DOM Properties

ShadowRoot.host

Read-only reference to the element that owns the shadow root. It lets component code locate the host without searching the document. Given an existing root, host returns the actual element object, not an ID string or its tag name. It works even when the root is closed if the caller already has its reference. Example result: true.

Formal Syntax & Structure

html syntaxhtml
root.host

Return Value

Element

The element owning this 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.host === host;  })().catch(error => { result.textContent = "Error: " + error.name; });</script>
HTML Reference