How to Inspect and Edit Shadow DOM Trees in Google Chrome DevTools

Modern frontend web development heavily relies on reusable web components and encapsulation frameworks to build modular interfaces. Native HTML elements like video players (<video>) and file upload pickers (<input type="file">), alongside modern component libraries (such as Lit, Shoelace, and Polymer), prevent global CSS cascades from accidentally distorting internal component styling by encapsulating their markup inside the Shadow DOM.

However, when debugging third-party web components, styling encapsulated slots, or testing accessibility tree nodes, standard DOM inspection tools often conceal internal element hierarchies behind a collapsed host tag. Google Chrome DevTools includes dedicated Shadow DOM inspection and authoring capabilities, allowing developers to expand shadow roots, reveal native browser user-agent shadow DOM trees, and modify encapsulated styles in real time.

Understanding Shadow DOM Architecture

The Shadow DOM allows hidden DOM trees to be attached to regular elements in the main document DOM:

  • Shadow Host: The standard regular DOM node that the shadow DOM is attached to.
  • Shadow Root: The root node of the scoped shadow tree, separating internal nodes from the outer document.
  • Shadow Tree: The encapsulated DOM hierarchy residing underneath the shadow root.
  • Shadow Boundary: The barrier across which CSS selectors and JavaScript queries (like document.querySelector) cannot penetrate unless explicitly configured in open encapsulation mode.

Expanding and Inspecting Custom Web Components

To inspect elements encapsulated inside open shadow roots in Chrome DevTools:

  1. Open Google Chrome and navigate to a web page utilizing web components.
  2. Open DevTools by pressing F12 or Ctrl + Shift + I (on Windows/Linux) or Cmd + Option + I (on macOS).
  3. Select the Elements panel.
  4. Locate the custom component tag (for example, <user-card>).
  5. Immediately beneath the host element, locate the distinctive grey badge labeled #shadow-root (open).
  6. Click the disclosure triangle next to #shadow-root (open) to expand the encapsulated child hierarchy.

You can now click, inspect, and select any inner elements (such as paragraphs, containers, or buttons) just like standard DOM nodes.

Revealing User-Agent Shadow DOM

Native browser elements—such as media player play buttons, volume sliders inside <video> controls, and password visibility toggles—are constructed using Chrome’s internal User-Agent Shadow DOM. By default, DevTools conceals these internal elements to prevent inspector clutter.

To reveal internal browser component markup:

  1. Click the Settings (gear) icon in the top-right corner of DevTools (or press F1).
  2. Under the Preferences tab, scroll down to the Elements section.
  3. Tick the checkbox labeled Show user agent shadow DOM.
  4. Close the Settings pane.

Now, inspecting an element like <input type="range"> reveals its underlying #shadow-root (user-agent) tree, displaying the slider track and thumb container divs.

Modifying Encapsulated CSS in the Styles Pane

When an element inside a shadow tree is selected, the Styles pane updates contextually:

  • Scoped Rules: Styles declared inside the component’s internal <style> block are displayed with local scoping indicators.
  • CSS Custom Properties (Variables): Inherited CSS variables defined on parent documents (e.g., --button-background: #007acc;) pass through the shadow boundary seamlessly. You can edit variable values in the Styles pane to test thematic changes across all encapsulated instances simultaneously.
  • Live Editing: You can double-click property values to change colours, margins, or flexbox layouts immediately on screen.

Inspecting Shadow DOM Slots

When web components use slotting (<slot>) to distribute markup supplied by light DOM consumers into designated template positions, DevTools displays an interactive reveal badge next to slotted nodes. Clicking the badge instantly jumps the inspector between the light DOM source node and its rendered position in the shadow tree.

Mastering Shadow DOM inspection in Chrome DevTools gives web developers complete transparency when authoring, customising, and debugging modern modular web components.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.