DOM Interfaces
ShadowRoot
A document-fragment-like root of an encapsulated DOM subtree. Styles and selectors have scoping rules, but slots and inherited CSS can cross boundaries. Shadow DOM is not a security isolation mechanism. Example result: Inside.
Formal Syntax & Structure
html syntaxhtml
host.attachShadow({ mode: "open" })Return Value
ShadowRoot
Root of the shadow tree.
Working Example
Example Snippethtml
<p> Result: <output id="result"></output></p><script> const result = document.getElementById("result"); (async () => { const host = document.createElement("div"); document.body.append(host); const root = host.attachShadow({mode: "open"}); root.textContent = "Inside"; result.textContent = root.textContent; })().catch(error => { result.textContent = "Error: " + error.name; });</script>