Shadow DOM and SEO: can Google and AI crawlers see web components?
Google flattens shadow DOM when rendering, but raw-HTML crawlers may see empty web components. How to check, and fix with slots or declarative shadow DOM.
By Crawlito · 6 min read
In short
Google says that when it renders a page it flattens the shadow DOM and light DOM content, and it can only see content that is visible in the rendered HTML.
A crawler that does not run JavaScript sees only the server HTML, so a custom element whose text is created by script appears as an empty tag.
Text placed between a custom element's tags is light DOM: it is in the raw HTML and can be shown inside the component with a slot element.
Declarative shadow DOM puts a shadow root in the HTML itself using a template element with a shadowrootmode attribute, and it is supported in all three major browser engines.
Check a component-heavy page by searching the raw HTML for its key sentences and comparing with the rendered DOM.
Google can index content inside shadow DOM, because its renderer runs JavaScript and flattens the shadow DOM and light DOM into one rendered page. Crawlers that read only the raw HTML are different: if a web component creates its text with JavaScript inside a shadow root, those crawlers see an empty custom element and nothing else. Many AI crawlers fetch HTML without rendering it, so the safe pattern is to put the important text in the HTML itself, either as light DOM shown through a <slot> or as declarative shadow DOM.
This post explains what each crawler type receives from a web component, how to test your own components, and the fixes in order of effort.
What shadow DOM is, briefly
A web component is a custom HTML element, such as <product-card> or <faq-item>, defined in JavaScript. Most components attach a shadow root: a separate, encapsulated DOM tree that holds the component's internal markup and styles. Content written between the element's tags in the page is the light DOM.
html
<product-card>
<!-- light DOM: written in the page HTML -->
<h3>Trail Runner 2</h3>
<p>Lightweight shoe for rocky ground.</p>
</product-card>
The component's shadow root decides how that light DOM is displayed. If the shadow root contains a <slot>, the light DOM is shown in that place. If it does not, the light DOM is not rendered at all, even though it is in the HTML.
What Google documents about shadow DOM
Google's JavaScript SEO basics has a short section on web components. It says that when Google renders a page, it flattens the shadow DOM and light DOM content, and that Google can only see content that is visible in the rendered HTML. It recommends the <slot> element as one way to make sure both light DOM and shadow DOM content appear in the rendered HTML.
Two consequences follow:
Shadow DOM is not a barrier to Google by itself. Googlebot renders pages with an evergreen Chromium, so text that a component renders into its shadow root ends up in the flattened page.
Light DOM that is not slotted is a problem even for Google. If your component reads its light DOM, copies it somewhere, and does not display it through a slot, the original text is not part of the rendered output. Google's guidance is about what is visible after rendering.
Rendering also happens later than crawling. Google says pages wait in a render queue, sometimes for a few seconds and sometimes longer. Content in the initial HTML does not depend on that step.
To see what Google's renderer produced for a specific URL, use the URL Inspection tool's rendered HTML view. The guide to URL Inspection and rendered HTML shows how to read it.
What non-rendering AI crawlers get
Crawlers that do not execute JavaScript work with the HTML your server sends. Our post on whether AI crawlers run JavaScript covers what each operator documents; the practical rule is to assume an AI crawler may read only the raw HTML.
Here is what a typical script-built component looks like to such a crawler:
The prices, plan names and feature list are created by pricing-table.js inside a shadow root after the script runs. The raw HTML contains an empty tag with an attribute. A crawler that does not run the script has no text to read.
Compare the three common patterns:
Pattern
Text in raw HTML?
Visible after rendering?
Script builds content inside the shadow root
No
Yes
Light DOM text, shown through a <slot>
Yes
Yes
Light DOM text, not slotted
Yes, but not displayed
No
Declarative shadow DOM in the server HTML
Yes, inside a <template>
Yes
The second row is the one that works for both kinds of crawler with the least change.
How to check your own components
You need two views of the page: the raw HTML and the rendered DOM. The general method is in raw vs rendered HTML; for components, add these steps.
Fetch the raw HTML and search for real sentences. Pick a sentence a visitor sees inside the component, such as a price or an FAQ answer:
Then look at what sits between each element's opening and closing tags. An empty pair means the content comes from script.
Inspect the rendered DOM. In Chrome DevTools, expand the element. A #shadow-root (open) node shows the shadow tree. Check whether light DOM children are assigned to a slot; DevTools shows slotted nodes under the <slot> with a "reveal" link.
Compare with Google's rendered HTML in URL Inspection for one representative URL, to confirm Google sees the flattened text.
The lowest-effort fix keeps your component and moves the content out of JavaScript into the page HTML. The component's shadow root provides layout and styles, and a slot displays the text.
html
<faq-item>
<span slot="question">Can I cancel any time?</span>
<p>Yes. Your plan stays active until the end of the billing period.</p>
</faq-item>
The question and answer are in the raw HTML, so every crawler can read them. After rendering, they are displayed inside the shadow tree through named and default slots, which is the pattern Google recommends. If the component is built with a library such as Lit or Stencil, the same idea applies: pass content as children, not only as attributes or fetched data.
Headings and links benefit the most. A link written in light DOM is a real <a href> in the HTML, which crawlers can follow. A link created inside a shadow root by script exists only after rendering.
Fix 2: declarative shadow DOM
If you render on the server, you can send the shadow root itself in the HTML. Declarative shadow DOM uses a <template> element with a shadowrootmode attribute:
According to web.dev's declarative shadow DOM article, the feature is available in all three major browser engines and became Baseline Newly available in August 2024. The browser attaches the shadow root while parsing the HTML, before any script runs, which also avoids layout shifts.
Points to know before you rely on it:
It is a parser feature. It only works in HTML parsed from the server response. Setting innerHTML with a shadowrootmode template does not create a shadow root; web.dev names setHTMLUnsafe() and parseHTMLUnsafe() as the APIs that do.
The text sits inside a <template> element. The content is in the raw HTML, but how each AI crawler's parser treats <template> content is not documented by the operators. Text in a template is not part of a normal parsed document tree. If the content matters for AI search, keep the key sentences in light DOM and slot them, and use declarative shadow DOM for structure and styling.
Your framework has to support it. Lit's server-side rendering and several other web component tool chains can output declarative shadow roots. Check your own stack's documentation.
Fix 3: render the page differently
If most of a page's text comes from components that fetch their data in the browser, the problem is client-side rendering, not shadow DOM. The options are the same as for any JavaScript-built page: server-side rendering, static generation or prerendering. The guide to client-side rendering and empty HTML compares them.
Frequently asked questions
Does Google index content in shadow DOM?
Google says it flattens shadow DOM and light DOM when it renders a page and can see content that is visible in the rendered HTML. Text that never becomes visible, such as light DOM that is not slotted, is not part of that output.
Can AI crawlers read web components?
A crawler that does not run JavaScript reads only the server HTML. It sees light DOM text and declarative shadow DOM markup, but not content that a script creates inside a shadow root.
Is declarative shadow DOM good for SEO?
It puts the component's markup in the server HTML, which removes the dependency on JavaScript for that content. For text you want every crawler to read reliably, light DOM with a slot is the more conservative choice.
Should I stop using web components?
No. The problem is where the text comes from, not the component model. Keep components for layout and behaviour, and keep important text and links in the HTML.
Test a component-heavy page
Pick the page where components carry the most important text, often pricing, product or FAQ pages, and run the free check on it. It shows whether that text is in the HTML an AI crawler receives, with no account needed.
Filed under Rendering and content. Topics: · rendering, javascript, raw-html, google, ai-crawlers
Do AI crawlers render JavaScript? Googlebot does. Most AI crawlers did not in Vercel's 2024 study. What that means for your pages and how to test them.
Raw HTML vs rendered HTML: what each one is, how to compare them with view-source, curl, DevTools and Search Console, and when the gap hides content from crawlers.