DEV Community

Cover image for data-nosnippet: decide what AI Overviews can quote
richi.codes
richi.codes

Posted on Originally published at richi.codes

data-nosnippet: decide what AI Overviews can quote

This note has an interactive demo. Try it in the original

There's no special markup that gets you into Google's AI Overviews, but there is markup that keeps parts of your page out of them. The same snippet controls that have shaped the grey text under a search result for years (nosnippet, max-snippet and the data-nosnippet attribute) now also decide how much of your page Google may use as direct input for AI Overviews and AI Mode. It's one of the few levers that is documented, works per page or per paragraph, and doesn't require blocking a crawler.

The demo above is a small page with a robots meta tag you can change. Tap a block to give it data-nosnippet, move the max-snippet slider, and watch the counter, the search result and the "AI input" box shrink. The fine-print block is a <p>, and that's on purpose: try excluding it and see what happens.

What Google actually says

Google's page on AI features is refreshingly blunt: "There are no additional requirements to appear in AI Overviews or AI Mode, nor other special optimizations necessary." It also says there's "no special schema.org structured data that you need to add". What it lists instead are SEO basics: allow crawling, keep important content in text, link it internally, and make sure your structured data matches the visible text.

The interesting part is the other direction. To limit what's shown from your pages, that same page points you to nosnippet, data-nosnippet, max-snippet and noindex. And the robots meta tag documentation spells out the AI part:

  • nosnippet applies to "all forms of search results", with AI Overviews and AI Mode named in the list, and it "will also prevent the content from being used as a direct input for AI Overviews and AI Mode".
  • max-snippet:[number] caps the text snippet at that many characters, and it "will also limit how much of the content may be used as a direct input for AI Overviews and AI Mode". 0 means no snippet (the same as nosnippet) and -1 lets Google choose.

So it's not an AI-only switch. It's your snippet, and AI features now read from the same budget.

How it works

Page-wide rules go in a meta tag (or in an X-Robots-Tag HTTP header). Partial rules go on the elements themselves:

<meta name="robots" content="max-snippet:120">

<p>Basil needs light. <span data-nosnippet>Call 555 0142.</span></p>

<section data-nosnippet>
  <p>The members-only trick: pinch the tips every week.</p>
</section>
Enter fullscreen mode Exit fullscreen mode

data-nosnippet is a boolean attribute: any value is ignored, so data-nosnippet="false" still excludes the text. And it only counts on span, div and section. Google's own example marks a custom element as "NOT VALID: not a span, div, or section", which is why the <p> in the demo turns yellow and doesn't change the count until you convert it to a <div>.

The demo models that with a tree walker that collects every text node and skips the ones inside an excluded block:

const SKIP = 'span[data-nosnippet], div[data-nosnippet], section[data-nosnippet]';

function quotableText(root) {
  const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT);
  let out = '';
  for (let n = walker.nextNode(); n; n = walker.nextNode()) {
    if (n.parentElement.closest(SKIP)) continue; // inside an excluded block
    out += n.data + ' ';
  }
  return out.replace(/\s+/g, ' ').trim();
}
Enter fullscreen mode Exit fullscreen mode

Then nosnippet or max-snippet:0 leave nothing, and max-snippet:N keeps the first N characters. I ran this function in Chromium against a page with a <span>, a <section>, a <p> and a <div data-nosnippet="false">, all excluded: it returned only the plain text plus the <p>, which is exactly the rule from the docs. I also ran the demo in Chromium, Firefox and WebKit, with no console errors.

Be clear about what this is: a model of the rules, not of Google. Google picks which sentences to show and how many; the demo only shows the upper limit of what you allow.

Gotchas

  • It's not only AI. nosnippet also removes the snippet from regular results, Images and Discover. If you just want shorter AI input, max-snippet or a targeted data-nosnippet is the gentler tool.
  • The HTML has to be valid. Google asks for valid HTML with every tag properly closed so the section can be read reliably.
  • Don't toggle it with JavaScript. Extraction may happen before and after rendering, so Google says not to add or remove data-nosnippet on existing nodes with JavaScript. Put it in the HTML your server sends. The demo toggles it with JavaScript only because it's a simulation.
  • Structured data inside an excluded block still counts. The docs say structured data declared within a data-nosnippet element remains usable for search results.
  • Blocking the crawler hides the rules. These settings are only read if crawlers are allowed to fetch the page. Disallow it in robots.txt and Google never sees your nosnippet.
  • Conflicts resolve to the stricter rule. With max-snippet:50 and nosnippet on the same page, nosnippet wins.
  • Google-Extended is a different control. It covers Gemini training and grounding in Gemini Apps and Vertex AI, and Google says it doesn't affect inclusion in Google Search. It isn't the switch for AI Overviews.
  • Separate permission overrides the cap. The docs note that the max-snippet limit doesn't apply where a publisher has separately granted permission to use the content.

What to keep an eye on

These are Google rules. Other engines and assistants have their own controls, or none, so check each one's documentation before assuming the same markup works there. And watch the robots meta tag page: the AI Overviews and AI Mode wording is what makes max-snippet matter here, and if Google changes how AI features use content, that's where it will show up first.

Sources


Originally published at richi.codes.

Top comments (0)