Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Short answer: custom HTML can supply metadata that search engines and social platforms read, but CSS normally cannot change those metadata values. Put a descriptive <title>, <meta name="description">, and any Open Graph fields in the document head. Use CSS to improve the visible page that a crawler or sharing service may inspect—not to write hidden preview text.

What actually controls a metadata preview?

A preview is assembled by the system displaying it. Google Search, a social network, a messaging app, and a link unfurling service can read different fields and apply different rewriting rules. Your HTML provides inputs; the consuming system decides whether and how to display them.

Preview context Typical input Can your CSS set the text? Important qualification
Google Search result <title>, meta description, page text, robots controls No Google may select page text instead of your description for a particular query.
Open Graph consumer og:url, og:title, og:description, image fields No The platform decides which Open Graph fields it supports and how it renders them.
Visible page HTML elements and CSS presentation Yes, for appearance Visible content can be read as page text, but CSS-generated text is not a reliable metadata source.

Google describes metadata as information for search engines and other clients. Its examples include a page title and meta description in the document head. If you use a CMS, its SEO or page-settings panel usually writes these elements for you; you do not need to edit the template directly. See Google’s supported meta tags documentation.

Build the HTML metadata first

Use a valid head structure

Place the page’s title and description inside <head>. Google lists title, meta, link, script, and style among valid head elements. Broken or invalid markup can cause later metadata to be read incorrectly, so validate the document and inspect the rendered source. The rules are documented in Valid Page Metadata for Google Search.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Custom HTML and CSS for Metadata Previews</title>
    <meta
      name="description"
      content="Learn which HTML metadata controls search and social previews, what CSS can change, and how to validate the result."
    >
    <link rel="canonical" href="https://example.com/metadata-previews">
  </head>
  <body>
    <main>
      <h1>Custom HTML and CSS for Metadata Previews</h1>
      <p>Write useful, visible content that matches the page's metadata.</p>
    </main>
  </body>
</html>

Write the description as an accurate summary rather than a list of keywords. A description is an input, not a promise that the same sentence will appear in every result.

Add Open Graph fields for social sharing

Open Graph is a separate vocabulary for web-page objects. Add the fields appropriate to your page, then let the sharing platform interpret them. The protocol is specified at ogp.me.

<meta property="og:url" content="https://example.com/metadata-previews">
<meta property="og:type" content="article">
<meta property="og:title" content="Using Custom HTML and CSS for Metadata Previews">
<meta property="og:description" content="A practical guide to HTML metadata, CSS limitations, and preview validation.">
<meta property="og:image" content="https://example.com/images/metadata-previews.jpg">

Do not assume that an Open Graph description becomes a Google meta description, or that changing one field changes every platform’s card. Each client processes only the tags it supports; unsupported tags are ignored.

Why CSS cannot write dependable preview text

CSS changes presentation, not metadata values

Rules such as font-size, color, display, and layout properties can change what a human sees on the page. They do not rewrite the title, meta, or Open Graph values in the head.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

CSS-generated text is not page content for Google

The content property can draw text beside a pseudo-element, but that text is not part of the DOM. Google states: “For example, content that is added via the CSS content property is not part of the DOM and Google Search ignores it at the moment.” Put important wording in a real HTML element or the appropriate metadata field. The statement appears in Google’s SEO Guide for Web Developers.

/* This may appear visually, but it is not dependable preview metadata. */
.card::before {
  content: "Limited-time guide";
}

/* Put the meaningful text in HTML instead. */
<p class="eyebrow">Limited-time guide</p>

CSS can still make that real paragraph look like a label. The distinction is semantic: the words exist in the HTML DOM, while pseudo-element text is only a rendering instruction.

How Google chooses a search snippet

Google says it may use your meta description when it considers it more accurate than the page’s text. Snippets are designed for the particular query, so the same URL can show different wording for different searches. A carefully written description improves the available input, but it cannot force one exact snippet. Read How to Write Meta Descriptions for Google’s guidance.

Make the page text support the description

  • Give the page one clear, descriptive <h1>.
  • State the page’s subject and outcome in visible introductory text.
  • Keep the title, description, headings, and body factually consistent.
  • Avoid placing the only important explanation in an image, canvas, or CSS pseudo-element.

Expect title-link adjustments

Google can truncate title links and may choose alternate title text when the title does not match the language or writing system of the page’s main content. Its recommendations are collected in Influencing Title Links in Google Search. Treat your title as a strong suggestion, not a fixed-width label.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Limit or permit snippets deliberately

Google supports robots metadata and the data-nosnippet attribute to control eligibility for portions of a result. These controls matter only when Google can crawl the page. A blocked crawler cannot read your instruction.

Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
<!-- Keep the page crawlable, but do not use this paragraph in a snippet. -->
<p data-nosnippet>Internal navigation note</p>

<!-- Example robots control in the head. Choose deliberately. -->
<meta name="robots" content="max-snippet:160">

Use these controls when you have a specific reason to limit preview text, not as a substitute for writing useful metadata. Google’s specifications are at Robots Meta Tags Specifications.

A practical implementation and validation workflow

  1. Choose the canonical URL and page language. Use the final public URL in the canonical and Open Graph fields, and set the correct lang attribute.
  2. Write the visible page first. Add a useful heading and introductory paragraph in HTML so users and crawlers have substantive page text.
  3. Write the head metadata. Add one title, one description, canonical link, and the Open Graph fields your sharing targets support.
  4. Keep CSS visual. Style real HTML content. Do not put essential wording only in ::before, ::after, or another generated-content rule.
  5. Validate the markup. Check that head elements are correctly nested and closed, attributes are quoted, and there is no accidental text before or inside the head.
  6. Inspect the rendered source. View the final HTML delivered to a crawler, not only the template file. Confirm that server-side rendering or a CMS has emitted the values you authored.
  7. Check crawl access. Ensure authentication, robots rules, and network restrictions do not prevent the relevant client from fetching the page.
  8. Allow for recrawling and rewriting. A platform may cache an earlier card or choose different text for a query. Changes are not guaranteed to appear immediately.

Common mistakes and fixes

Symptom Likely cause Fix
The old description still appears The client has cached an earlier fetch, or Google selected page text. Confirm the live head output, keep the page crawlable, and allow the client to recrawl. Do not expect a fixed snippet.
CSS text is missing from a result The words exist only in a pseudo-element’s content. Move the wording into a real HTML element and style that element.
Open Graph changes do not affect Google Open Graph and Google metadata are separate inputs. Update the standard title/description as well as the Open Graph fields.
Some tags appear ignored The consuming client does not support those tags, or the markup is invalid. Use documented fields for that client and validate the complete head.
data-nosnippet has no effect Google cannot crawl the URL or has not fetched the new version. Restore crawl access, verify the attribute in delivered HTML, and wait for a new crawl.
Title language looks wrong The title does not match the page’s primary language or writing system. Use a title consistent with the main content and language declaration; Google may still adjust it.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If your goal is to inspect the rendered page after changing its HTML and CSS, ScreenshotNeo can capture that page through one API call. It is a capture and verification service, not a way to override metadata rules: the consuming search or social system still decides its preview.

ScreenshotNeo removes cookie-consent banners, newsletter popups, and chat widgets before capture, with each cleanup step switchable. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing; response headers identify the page verdict and whether the shot was billed. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. Every feature is on every plan: 1,000 shots per month free with no card, then Starter is $5 for 3,000, Growth $15 for 15,000, Pro $39 for 60,000, Scale $99 for 250,000, and Business $249 for 1,000,000; yearly billing gives two months free.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use the API documented at https://screenshotneo.com/docs/ after publishing your page:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com/metadata-previews -o preview.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://example.com/metadata-previews"}, timeout=90)
open("preview.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://example.com/metadata-previews' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

Capture the final page at desktop and mobile viewports, then inspect the delivered HTML separately for metadata. You can also use custom CSS, JavaScript, waits, headers, cookies, device presets, full-page capture, and PDF output when a page needs a controlled rendering check.

Create a free ScreenshotNeo account for 1,000 screenshots a month with no card.

What custom HTML and CSS can—and cannot—do

  • HTML metadata can: provide titles, descriptions, canonical URLs, Open Graph values, and crawler directives in the formats a client supports.
  • Visible HTML can: supply substantive text that Google may use when generating a query-specific snippet.
  • CSS can: control the appearance and layout of that visible content.
  • CSS cannot reliably: populate metadata fields or make generated pseudo-element text part of Google’s DOM.
  • No author can guarantee: the exact wording or visual layout a third-party preview will display.

Frequently Asked Questions

Can a CMS manage these fields without editing HTML?

Yes. Google notes that a CMS may provide a settings interface for metadata; verify that the saved values appear in the delivered document head.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Will every social network render the same Open Graph card?

No. Open Graph supplies a shared vocabulary, but each consuming platform determines which fields it reads, how it caches them, and how it renders the result.

Does a metadata change appear immediately in search?

Not necessarily. Google must recrawl the page and may still select different text for a query, so treat metadata as input rather than an exact-output guarantee.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.