Guide10 min read

Web components and shadow DOM: The invisible challenge of visual testing

Web Components' Shadow DOM encapsulates styles, breaking most visual tools. Real browser rendering handles Shadow DOM where others fail.

Contents
  1. Key points
  2. What the Shadow DOM changes for visual testing
  3. The three mechanisms that complicate everything
  4. Why classic approaches fail
  5. Comparing the real rendering: why this approach crosses the Shadow DOM
  6. Concrete cases where it makes a difference
  7. Web Components and design systems: the strategic stake
  8. Practical tips for visually testing your Web Components
  9. FAQ

Web Components are defined by MDN as "a set of technologies enabling the creation of reusable custom HTML elements, with their functionality encapsulated and isolated from the rest of the code" (MDN Web Docs, Web Components).

This definition masks a quiet revolution. Web Components are no longer an experimental curiosity. In 2026, every major browser supports them natively. Frameworks like Lit, Stencil and FAST use them as a foundation. Companies like Adobe (Spectrum Web Components), SAP (UI5 Web Components) and ING Bank (Lion Web Components) build their entire design systems on this technology.

And yet visual testing of Web Components remains a blind spot for most teams. The reason comes down to two words: Shadow DOM.

The essentials on one page: definition, no-code automation, how to choose a tool: Automated regression testing, no code.

Key points

  • The Shadow DOM encapsulates styles and DOM, making classic visual testing approaches partially blind
  • Tools that inspect the "normal" DOM don't see the elements inside the Shadow DOM without specific adaptation
  • A tool that renders the page in a real browser and compares it the way the human eye would works through the Shadow DOM, because it observes the final displayed rendering
  • Slots, CSS custom properties and style inheritance create complex interactions that only an analysis of the real rendering can verify

What the Shadow DOM changes for visual testing

To understand the problem, you need to understand what the Shadow DOM actually does. Normally, the whole DOM of your page is a single tree. CSS selectors apply to every element. Testing tools can walk the entire structure.

The Shadow DOM breaks that assumption. It creates an isolated DOM subtree, attached to a host element, with its own styles. External CSS selectors can't reach the internal elements. Scripts that walk the DOM with querySelector don't see what is in the shadow.

That is exactly the goal of the Shadow DOM: encapsulation. Your styles don't leak out, outside styles don't contaminate the inside. It is a feature, not a bug.

But for visual testing, this encapsulation is a wall. And most testing tools don't know how to get over it.

The three mechanisms that complicate everything

The Shadow DOM is only the visible part of the problem. Web Components rely on three mechanisms that, together, create a level of complexity that classic visual testing handles poorly.

Style encapsulation

Inside a Shadow DOM, styles are local. A .button selector in your Shadow DOM only targets the .button elements of that particular Shadow DOM. Not those of the main document, not those of other components.

The reverse is also true: your global styles (your CSS framework, your reset, your utility classes) don't apply inside the Shadow DOM. If your Web Component relies on styles that come "from the outside", they simply won't be there.

For visual testing, this means you can't reason about a component's style by looking only at the global stylesheets. Each component is a world of its own, with its own rules.

Slotting and content projection

Slots let a component's users inject content inside the Shadow DOM. The component defines placeholders (<slot>), and the content provided by the parent is "projected" into those placeholders.

Here is what that implies for visual testing: the content visible in a slot belongs to the main DOM (the "light DOM"), but it is displayed inside the Shadow DOM. It inherits some styles from the Shadow DOM but technically stays in the light DOM. This duality creates situations where a testing tool sees the element in the light DOM but doesn't understand its real visual context.

Slotted text can inherit the Shadow DOM's text color through CSS inheritance, yet keep its own font size defined in the light DOM. The visual result is a mix of the two contexts, and only the browser knows exactly what is displayed.

CSS Custom Properties (CSS variables)

CSS custom properties ("CSS variables") are the only standard CSS mechanism that crosses the Shadow DOM boundary. If you define --primary-color: blue on the host element, that variable is accessible inside the Shadow DOM.

It is the main theming mechanism of Web Components. Design systems based on Web Components expose dozens, sometimes hundreds of custom properties to allow customization.

The problem for visual testing: a custom property's effective value depends on the full CSS cascade: the values defined in the document, the inherited ones, the ones redefined locally. To verify that a component displays correctly, you have to resolve that cascade. And the only entity that does it correctly is the browser itself.

Why classic approaches fail

Let's look concretely at why common visual testing tools struggle with Web Components.

DOM-based tools

Many testing tools inspect the DOM to understand the page structure. They walk the elements, read the CSS classes, and deduce the expected appearance. Faced with a Shadow DOM, these tools hit a wall: internal elements aren't visible through the standard DOM APIs.

True, shadowRoot exists to access the content of an open Shadow DOM. But a testing tool has to actively traverse every Shadow DOM, handle nested Shadow DOMs (a Web Component inside another Web Component), and understand the interaction between the light DOM and the Shadow DOM.

Most tools weren't designed for that. They were built at a time when the DOM was a single, flat tree.

Pixel-by-pixel comparison

The screenshot approach works... on the surface. It captures what the browser displays, Shadow DOM or not. But it doesn't understand the structure. If a Web Component's rendering changes because of an inherited custom property change, pixel comparison detects a change but can't identify the cause.

More problematic: pixel comparison can't verify structural properties. Does the contrast of text inside a Shadow DOM meet WCAG? Is the spacing between slotted elements consistent? These questions require a structural understanding, not an image comparison.

CSS selectors in tests

If you write tests that verify styles through CSS selectors (for example, "the primary button must have a background-color of #0066FF"), you have a problem. Your CSS selectors don't cross the Shadow DOM. The button you're looking for is invisible to your selector.

You can work around the problem by chaining access to the shadowRoot, but that makes your tests fragile and dependent on the component's internal structure: exactly what Shadow DOM encapsulation is meant to prevent.

Comparing the real rendering: why this approach crosses the Shadow DOM

Comparing the visual result rendered by the browser elegantly sidesteps the Shadow DOM problem. Here is why: you don't read the DOM to guess what is displayed. You observe the final rendering: what the browser actually displays on screen, after all styles are applied.

When the browser renders an element, whether it is in the light DOM, the Shadow DOM, or projected through a slot, it resolves the full CSS cascade and produces concrete computed values. The background color is no longer "var(--surface-color)" but "rgb(30, 30, 30)". The font size is no longer "1.2em" but "19.2px".

By relying on this rendering, Delta-QA gets the browser's truth. It doesn't need to understand Shadow DOM encapsulation, custom property resolution, or slotting rules. The browser has already done all that work. The tool only has to compare the visual result as it is displayed.

It is a fundamental distinction. Instead of trying to reproduce the browser's logic (and failing against the Shadow DOM), Delta-QA trusts the browser and checks what it actually displays.

Concrete cases where it makes a difference

To illustrate the advantage of this approach, consider real situations that teams using Web Components run into.

Broken theming

Your design system exposes a --button-bg custom property to customize button color. A team updates the main theme and renames the variable to --btn-background. Every button in the Shadow DOM loses its custom color and falls back to the default value.

A structural test immediately detects that the button's computed color has changed. A pixel test detects it too, but flags a change without explaining the cause. A DOM test detects nothing because the component is structurally identical.

Badly styled slots

A card component uses a slot for the title. The title is provided by the parent as an <h3>. Someone changes the global <h3> styles without realizing these styles also apply to slotted titles inside cards: because slotted elements inherit light DOM styles for properties not defined in the Shadow DOM.

Delta-QA compares the visual result of the <h3> in its real display context (inside the slot) and detects the change in size or weight.

Nested components

A dialog component contains a form component, which contains input components. Three levels of nested Shadow DOM. A custom property change at the dialog level must propagate through all three levels.

Delta-QA compares the visual result at every level without worrying about nesting depth. The browser has resolved the cascade. The tool compares what is displayed.

Web Components and design systems: the strategic stake

Web Components aren't used in isolation. They are the technology of choice for modern design systems, and for a good reason: a Web Component works with React, Angular, Vue, or no framework at all. It is the ultimate interoperability.

But this interoperability creates a major visual testing stake. Your Web Components design system is used by several teams, in several applications, with different CSS contexts. A visual bug in a base component spreads everywhere.

Visual testing of a design system based on Web Components is not optional. It is quality assurance for every team that depends on it. And that assurance has to work across the Shadow DOM, with slots, with custom properties.

The structural approach is, to date, the only one that ticks all these boxes without requiring technical contortions.

How Delta-QA handles Web Components

Delta-QA renders the page in a real browser, compares it the way the human eye would and names the elements that changed, whether they are in the light DOM, the Shadow DOM, or projected through a slot. No special configuration is needed for Web Components: the tool treats them like any other element of the rendering.

Concretely, Delta-QA checks text contrast inside Shadow DOMs, detects spacing inconsistencies between components, and identifies theming regressions when a custom property changes value. All of it without writing a test, without a specific CSS selector, without explicit access to the shadowRoot.

It is no-code visual testing applied to Web Components. You point the tool at your page, and it analyzes the rendering as the browser produces it.

Practical tips for visually testing your Web Components

If you use Web Components, or are considering adopting them, here is how to approach visual testing pragmatically.

Test components in isolation first

Before testing your full pages, test each component in an isolated environment (Storybook or a demo page). Check the states (default, hover, focus, disabled, error) and the variants (sizes, colors, light/dark modes).

Check the integration points

The nastiest visual bugs show up at integration points: where the light DOM meets the Shadow DOM, where one component is nested inside another, where custom properties cross boundaries.

Watch your custom properties

Keep an inventory of your theming custom properties. Delta-QA automatically detects any visible rendering change whatever its cause.

Build visual testing into your release pipeline

Every new version of a Web Component should go through an automated visual test before being released. A regression in a base component has a devastating multiplier effect.


FAQ

Does the Shadow DOM prevent automated visual testing?

No, but it prevents certain visual testing approaches. Tools that inspect the DOM directly don't see the elements inside the Shadow DOM without specific adaptation. On the other hand, tools that compare the visual result rendered by the browser cross the Shadow DOM without difficulty, because they observe what is actually displayed on screen.

How do slots affect visual testing of Web Components?

Slots create a duality: slotted content belongs to the light DOM but is displayed in the visual context of the Shadow DOM. Inherited styles come from both sides. An effective visual testing tool has to verify the element's real appearance in its final display context, not its position in the DOM tree. The structural approach handles this case naturally.

Do you need specific visual tests for Web Components?

Not if your tool uses the structural approach. Visual quality rules (contrast, spacing, alignment, consistency) apply the same way to all elements, whether they are in the light DOM or the Shadow DOM. You don't need "special Web Components" tests: you need a tool that works everywhere.

Does Delta-QA need special configuration for Web Components?

No. Delta-QA renders the page in a real browser and compares the visual result of all displayed elements, regardless of their position in the DOM. Elements inside the Shadow DOM are treated exactly like the others. No special selector, no shadowRoot configuration, no access script.

Do Web Components create more visual regressions than classic components?

Not intrinsically, but the regressions are harder to detect with classic tools. Shadow DOM encapsulation hides changes from tools that aren't prepared for it. Moreover, the interactions between custom properties, CSS inheritance and slotting create subtle dependency chains that an automated visual test is better placed to watch than a human.

Which Web Components frameworks are compatible with structural visual testing?

The approach is framework-agnostic. Whether you use Lit, Stencil, FAST, or vanilla Web Components, the browser produces the same final rendering on screen. Delta-QA works with all Web Components frameworks without distinction, because it compares the visual result of the rendering, not the component's source code.


Try Delta-QA