HTML shadowrootmode Attribute
The shadowrootmode attribute turns a <template> into a declarative shadow root on its parent element, in open or closed mode, without JavaScript.
Description
The shadowrootmode attribute of the <template> element creates a declarative shadow root on the template's parent element. Its value sets whether the shadow root is open (accessible from JavaScript through element.shadowRoot) or closed.
Declarative Shadow DOM lets a web component's shadow root be written directly in HTML: a <template> element with the shadowrootmode attribute, placed inside the host element, is turned into a shadow root by the HTML parser. This makes it possible to render components on the server, with their encapsulated styles, without waiting for JavaScript.
Syntax
<template shadowrootmode="open | closed">
Values
- openCreates an open shadow root, exposed through the host's shadowRoot property.
- closedCreates a closed shadow root, hidden from JavaScript outside the component.
Applies To
Example
Browser Support
The following information will show you the current browser support for the HTML shadowrootmode attribute. Hover over a browser icon to see the version that first introduced support for this HTML attribute.
Desktop





Tablets & Mobile





