coderef

Shadow DOMBaseline · Widely available

Shadow DOM allows you to attach encapsulated "shadow" DOM trees to elements. A shadow DOM tree is a separate component, isolated from the scripts and styles in other parts of the document. This is a part of Web Components.

Supported in all major browsers for at least 30 months — safe to use without fallbacks. Baseline since Jan 15, 2020. Widely available since Jul 15, 2022.

Browser support

DesktopChrome
1–52Not supported
53+Supportedsince Aug 31, 2016
Current: 155
Edge
12–18Not supported
79+Supportedsince Jan 15, 2020
Current: 154
Firefox
1–62Not supported
63+Supportedsince Oct 23, 2018
Current: 157
Safari
1–9.1Not supported
10+Supportedsince Sep 20, 2016
Current: 27
MobileChrome Android
18–52Not supported
53+Supportedsince Sep 7, 2016
Current: 155
Firefox Android
4–62Not supported
63+Supportedsince Oct 23, 2018
Current: 157
Safari iOS
1–9.3Not supported
10+Supportedsince Sep 13, 2016
Current: 27

How to use

This feature is Baseline widely available — use it freely, no fallback needed.

Example

Full syntax and examples are on MDN: attachShadow.

Feature detection

JS · check before using
if ("ShadowRoot" in globalThis) {
  // ShadowRoot is available
} else {
  // load a polyfill or use a fallback
}

Sub-features

Support for each part of the feature (15). The overall table above shows when the whole feature works.

Sub-featureChromeEdgeFirefoxSafariChrome AndroidFirefox AndroidSafari iOS
Element.attachShadow53796310536310
Element.attachShadow.options_clonable_parameter12412412317.412412317.4
Element.attachShadow.options_delegatesFocus_parameter53799413.1539413.4
Element.attachShadow.options_serializable_parameter1251251281812512818
Element.shadowRoot35796310356310
Event.composed53795210535210
Event.composedPath53795910535910
Node.getRootNode54795310.1545310.3
Node.isConnected51794910514910
ShadowRoot53796310536310
ShadowRoot.clonable12412412317.412412317.4
ShadowRoot.delegatesFocus53799415539415
ShadowRoot.host53796310536310
ShadowRoot.mode53796310.1536310.3
ShadowRoot.serializable1251251281812512818