弃用
This 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 兼容性表格 at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

HTML <shadow> element —an obsolete part of the Web 组件 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.

内容类别 Transparent 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 接口 HTMLShadowElement

属性

此元素包括 全局属性 .

范例

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

注意: 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
          <shadow></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.

shadow example

规范

This element is no longer defined by any specifications.

浏览器兼容性

The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
shadow 弃用 非标 Chrome 完整支持 35 Edge 完整支持 79 Firefox 不支持 33 — 59 Disabled
不支持 33 — 59 Disabled
Disabled ). To change preferences in Firefox, visit
IE 不支持 No Opera 完整支持 26 Safari 不支持 No WebView Android 完整支持 37 Chrome Android 完整支持 37 Firefox Android 不支持 33 — 58 Disabled
不支持 33 — 58 Disabled
Disabled ). To change preferences in Firefox, visit
Opera Android ? Safari iOS 不支持 No Samsung Internet Android 完整支持 3.0

图例

完整支持

完整支持

不支持

不支持

兼容性未知 ?

兼容性未知

非标。预期跨浏览器支持较差。

非标。预期跨浏览器支持较差。

弃用。不要用于新网站。

弃用。不要用于新网站。

用户必须明确启用此特征。

用户必须明确启用此特征。

另请参阅

元数据

  • 最后修改: