DOM Properties
ShadowRoot.mode
Read-only creation mode, open or closed. It cannot be changed after attachment. Open mode exposes the root on host.shadowRoot; closed mode returns null through that host property. Both modes permit use of the root object by code that already holds it. Neither mode is a security boundary. Example result: open.
Formal Syntax & Structure
html syntaxhtml
root.modeReturn Value
string
The string "open" or "closed".
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.mode; })().catch(error => { result.textContent = "Error: " + error.name; });</script>