Development: Light DOM vs. Shadow DOM

Bobby Bailey

Bobby Bailey

Jump to Article

Vibe Check – Light DOM vs. Shadow DOM: What developers need to know about accessibility

The way web components are structured can make or break an accessible experience. One of the most important concepts developers need to understand is the difference between the Light DOM and Shadow DOM—and how these choices impact assistive technology, styling, and usability.

Too often, developers use Shadow DOM without realizing the accessibility pitfalls it can create. Let’s break down what these concepts mean, why they matter, and how they affect accessibility.

A personal story – When the Shadow DOM hid important content

I once tested a custom-built web component that looked perfect visually. It was a date picker, neatly styled and integrated into the page. But when I navigated it using a screen reader, nothing happened. No labels, no focus indication, no feedback—just silence.

After inspecting the code, I found the culprit: everything was inside a Shadow DOM, and the necessary accessibility hooks weren’t exposed. The developers had unknowingly trapped critical information in an isolated part of the DOM, making it invisible to assistive technology.

This experience reinforced a crucial lesson: If assistive technology can’t reach content, it might as well not exist. Understanding how the Shadow DOM works—and how to make it accessible—is key to creating inclusive web experiences.

Elevate the vibe – Understanding the Light DOM and Shadow DOM

What is the Light DOM?

The Light DOM is the standard document structure of a webpage. Elements in the Light DOM are part of the main HTML document, meaning:

Assistive technologies (screen readers, voice commands) can interact with them naturally.

CSS styles can be applied without restriction.

JavaScript can access and modify them easily.

What is the Shadow DOM?

The Shadow DOM is a way to encapsulate web component internals so they don’t interfere with the rest of the document. It creates a hidden subtree inside an element, meaning:

Styles and scripts inside a Shadow DOM are isolated from the main document.

Elements within the Shadow DOM aren’t directly accessible to external JavaScript or CSS.

By default, many assistive technologies can’t access content inside a closed Shadow DOM unless explicitly exposed.

Shadow DOM is useful for creating modular, reusable components, but it introduces serious accessibility risks when misused.

Vibe up – How the Shadow DOM impacts accessibility

1) Screen readers may not detect Shadow DOM content

The problem:

If a Shadow DOM is closed, screen readers may not announce its contents at all.

Even in an open Shadow DOM, accessibility attributes need to be explicitly connected to the Light DOM.

Fix it:

Prefer open Shadow DOM unless security requires a closed one.

Ensure ARIA attributes and labels connect to elements inside the Shadow DOM.

Use slot elements to expose relevant content to assistive technology.

2) CSS isolation can break focus indicators

The problem:

Shadow DOM creates a separate styling environment, meaning global styles don’t apply.

If a developer forgets to include :focus states inside the Shadow DOM, keyboard users lose navigation cues.

Fix it:

Always include focus states and keyboard navigation styles inside the Shadow DOM.

Use ::part() and ::slotted() to allow Light DOM styles to modify Shadow DOM elements when necessary.

3) JavaScript events may not bubble up

The problem:

Some JavaScript events (like click, focus, keydown) don’t naturally bubble from the Shadow DOM to the Light DOM.

This can break assistive technology interactions if developers aren’t careful.

Fix it:

Use composed: true when dispatching custom events so they reach the Light DOM.

Ensure event handlers work both inside and outside the Shadow DOM.

4) Form elements inside Shadow DOM may not integrate correctly

The problem:

Browsers don’t always associate Shadow DOM form inputs with their containing forms in the Light DOM.

This can cause issues with form validation and submission.

Fix it:

Use the ElementInternals API to properly associate form controls inside Shadow DOM.

Manually forward form data from Shadow DOM elements to Light DOM forms.

Vibe boost – How to build accessible web components with Shadow DOM

1) Expose important content using <slot>

<slot> allows parts of the Shadow DOM to be visible in the Light DOM.

This ensures assistive technology can interact with critical content.

2) Use aria-labelledby and aria-describedby to link labels

If an element inside the Shadow DOM needs an external label, use ARIA attributes to connect them.

Example:

<custom-button aria-labelledby="button-label"></custom-button>
<span id="button-label">Click Me</span>

3) Ensure keyboard and focus visibility

Define :focus styles inside the Shadow DOM.

Use tabindex="0" on key interactive elements.

4) Make sure JavaScript events reach the Light DOM

Dispatch events using { composed: true, bubbles: true } to ensure they are detected outside the Shadow DOM.

Example:

this.dispatchEvent(new CustomEvent('custom-action', { bubbles: true, composed: true }));

5) Test with assistive technology

Use screen readers (NVDA, JAWS, VoiceOver) to verify content is announced correctly.

Check keyboard navigation to ensure tab order makes sense.

Inspect form behavior to confirm submissions work properly.

Self-reflection – Evaluating your use of Shadow DOM

Ask yourself:

Is any critical content hidden inside a closed Shadow DOM?

Can screen readers navigate and interact with Shadow DOM elements?

Are focus states clearly visible for keyboard users?

Have I tested my web components with real assistive technologies?

If any of these raise concerns, it’s time to rethink your approach!

Vibe in action – Making Shadow DOM work for accessibility

1) Apply what you’ve learned

Audit your web components to check for accessibility gaps.

Refactor components to use <slot> for important content exposure.

2) Share the knowledge

Educate your team on the risks of hiding content inside Shadow DOM.

Advocate for building accessible web components from the start.

3) Keep learning

Follow best practices for ARIA integration in Shadow DOM.

Stay updated on browser support and accessibility improvements.

Test, iterate, and improve based on real-world feedback.

Vibing out

Web components and Shadow DOM are powerful tools, but they must be used responsibly. Developers need to think beyond encapsulation and consider how their choices impact accessibility.

By exposing content properly, maintaining focus states, and ensuring compatibility with assistive technology, we can create web components that are both modern and inclusive.

Because when accessibility is built into the foundation, everyone benefits.

Support my work in accessibility

Creating accessible content takes time, care, and deep testing — and I love every minute of it. From writing blog posts to doing live audits and building checklists, everything I create is designed to make the digital world more inclusive.If something here helped you — whether it saved you time, taught you something new, or gave you insight into accessibility — consider supporting my work.

You can buy me a coffee to help keep this platform going strong:

Buy Me a Coffee

Every coffee goes toward:

  • Creating new articles with accessibility tips, tools, and testing methods
  • Covering hosting, software, and assistive tech costs
  • Supporting free education for designers, developers, and testers
  • Making a meaningful difference for people living with disabilities

Thanks for being part of this mission to build a more accessible web — one page at a time.