Web/HTML/Element/shadow

From Get docs

DeprecatedThis feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.


The HTML <shadow> element—an obsolete part of the Web Components technology suite—was intended to be used as a shadow DOM insertion point. You might have used it if you have created multiple shadow roots under a shadow host. It is not useful in ordinary HTML.

Content categories Transparent content
Permitted content Flow content
Tag omission None, both the starting and ending tag are mandatory.
Permitted parents Any element that accepts flow content.
Permitted ARIA roles None
DOM interface HTMLShadowElement

Attributes

This element includes the global attributes.

Example

Here is a simple example of using the <shadow> element. It is an HTML file with everything needed in it.

Note: This is an experimental technology. For this code to work, the browser you display it in must support Web Components. See Enabling Web Components in Firefox.


<html>
  <head></head>
  <body>

  <!-- This <div> will hold the shadow roots. -->
  <div>
    <!-- This heading will not be displayed -->
    <h4>My Original Heading</h4>
  </div>

  <script>
    // Get the <div> above with its content
    var origContent = document.querySelector('div');
    // Create the first shadow root
    var shadowroot1 = origContent.createShadowRoot();
    // Create the second shadow root
    var shadowroot2 = origContent.createShadowRoot();

    // Insert something into the older shadow root
    shadowroot1.innerHTML =
      '<p>Older shadow root inserted by
          &lt;shadow&gt;</p>';
    // Insert into younger shadow root, including <shadow>.
    // The previous markup will not be displayed unless
    // <shadow> is used below.
    shadowroot2.innerHTML =
      '<shadow></shadow> <p>Younger shadow
       root, displayed because it is the youngest.</p>';
  </script>

  </body>
</html>

If you display this in a web browser it should look like the following.

[[File:../../../../../../media.prod.mdn.mozit.cloud/attachments/2015/02/04/10083/3f01843ca6e2e5df18a67595e32f8aff/shadow-example.png|shadow example]]

Specifications

This element is no longer defined by any specifications.

Browser compatibility

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet

shadow

Deprecated'Non-standard'

Chrome

Full support 35

Edge

Full support 79

Firefox No support 33 — 59

Disabled'

No support 33 — 59

Disabled'

Disabled' From version 33 until version 59 (exclusive): this feature is behind the dom.webcomponents.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.

IE

No support No

Opera

Full support 26

Safari

No support No

WebView Android

Full support 37

Chrome Android

Full support 37

Firefox Android No support 33 — 58

Disabled'

No support 33 — 58

Disabled'

Disabled' From version 33 until version 58 (exclusive): this feature is behind the dom.webcomponents.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.

Opera Android

?

Safari iOS

No support No

Samsung Internet Android

Full support 3.0

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Non-standard. Expect poor cross-browser support.'
Non-standard. Expect poor cross-browser support.
Deprecated. Not for use in new websites.'
Deprecated. Not for use in new websites.
User must explicitly enable this feature.'
User must explicitly enable this feature.


See also