👀 Live Preview
Modern Shadow DOM via attachShadow() (the working approach):

The <shadow> tag was part of an experimental Shadow DOM feature. This guide explains its deprecated status, historical syntax, and the modern attachShadow() API beginners should use instead.
Early Shadow DOM.
Do not use.
Historical only.
Isolated styles.
Modern API.
Best practices.
<shadow> Tag?The <shadow> tag was introduced to help developers create encapsulated DOM trees (shadow DOMs) within a web component. The shadow DOM allows better modularity and style encapsulation in web development.
The <shadow> tag is deprecated and should not be used. It was part of an early Shadow DOM implementation replaced by the JavaScript Shadow DOM API.
The <shadow> tag is now deprecated and should not be used in modern web development. It was part of an early implementation of the Shadow DOM specification but has been replaced by more robust and standardized methods.
<shadow> in new projects. Modern browsers do not treat this element as a Shadow DOM insertion point. Use attachShadow() on custom elements instead.The historical syntax encapsulated content that was intended to be part of the shadow DOM:
<shadow>
<!-- Shadow DOM content here -->
</shadow>Since the tag is deprecated, this syntax should be avoided in favor of the Shadow DOM API shown in the Alternatives section.
<my-element>
<shadow>
<style>
p { color: red; }
</style>
<p>This is shadow DOM content.</p>
</shadow>
</my-element>| Topic | Details | Status |
|---|---|---|
<shadow> element | Declarative Shadow DOM (old) | Deprecated |
| Modern API | element.attachShadow() | Use this |
| Custom elements | customElements.define() | Web Components |
| Encapsulation | Styles scoped to shadow root | Supported via API |
| Tag attributes | None meaningful | N/A |
| Browser support | <shadow> element | 0% modern |
<shadow> vs attachShadow()| Approach | How it works | Use today? |
|---|---|---|
<shadow> tag | HTML element inside custom element markup | No — deprecated |
attachShadow() | JavaScript API on HTMLElement | Yes — standard |
| Declarative Shadow DOM | <template shadowroot> in HTML | Yes — modern declarative option |
The <shadow> tag had limited attribute support, focusing primarily on encapsulating content rather than adding functionality through attributes.
None DeprecatedNo tag-specific attributes were defined for meaningful behavior in modern HTML.
<shadow>...</shadow>Global attrs IgnoredEven global attributes like class or id have no practical effect on deprecated shadow insertion.
Not recommendedCompare the historical shadow syntax with the modern Shadow DOM API you should use in real projects.
Modern Shadow DOM via attachShadow() (the working approach):
When <shadow> was in use, it was employed within custom elements to encapsulate styles and scripts, preventing them from affecting the global DOM.
Intended use inside a custom element with scoped styles. This no longer works in modern browsers:
<my-element>
<shadow>
<style>
p { color: red; }
</style>
<p>This is shadow DOM content.</p>
</shadow>
</my-element>The current standard is the Shadow DOM API, part of the Web Components suite. Create a shadow root with JavaScript:
<my-element></my-element>
<script>
class MyElement extends HTMLElement {
constructor() {
super();
const shadow = this.attachShadow({ mode: 'open' });
shadow.innerHTML = \`
<style>
p { color: red; }
</style>
<p>This is shadow DOM content.</p>
\`;
}
}
customElements.define('my-element', MyElement);
</script>attachShadow(), ensure interactive elements inside shadow roots remain keyboard accessible.Create a class extending HTMLElement and register it.
Call attachShadow({ mode: 'open' }) in the constructor.
Set shadowRoot.innerHTML with scoped styles and markup.
Styles and DOM inside the shadow root do not leak to the rest of the page.
The <shadow> HTML element is deprecated with 0% modern support. The Shadow DOM JavaScript API (attachShadow) is widely supported in all modern browsers.
The <shadow> element was removed from the standard. Use attachShadow() instead.
<shadow> element<shadow> not supported<shadow> not supported<shadow> not supported<shadow> not supported<shadow> not supportedNote: attachShadow() API has ~97% global support. Only the deprecated <shadow> element is unsupported.
While the <shadow> tag played a role in early Shadow DOM experimentation, it is no longer relevant in modern web development. Developers should use the Shadow DOM API to achieve encapsulation and modularity in web components.
Understanding the history of such tags helps appreciate the evolution of web standards and encourages the adoption of best practices.
Given the deprecated status of the <shadow> tag, avoid using it altogether. Adopt the modern Shadow DOM API for encapsulated DOM structures.
attachShadow() in custom element constructorscustomElements.define()shadowroot) for SSR<shadow> HTML element<shadow>Bookmark these so you never use deprecated Shadow DOM markup.
Do not use.
StatusEarly experiment.
ContextModern API.
AlternativeScoped styles.
PurposeCustom elements.
EcosystemElement dead.
CompatibilityattachShadow() on custom elements instead of the shadow HTML element.this.attachShadow({ mode: 'open' }) in a custom element and set shadowRoot.innerHTML.<shadow> element has 0% modern support. The Shadow DOM JavaScript API is widely supported.Skip deprecated <shadow> markup. Practice attachShadow() in the Try It editor.
6 people found this page helpful