Overview

Shadow DOM allows a component to have its own 'shadow' DOM tree that cannot be accidentally accessed from the main document. This ensures that the component's internal structure and styles remain isolated.

Key Concepts

  • Shadow Host: The regular DOM node that the shadow DOM is attached to.
  • Shadow Tree: The internal DOM tree inside the shadow DOM.
  • Shadow Boundary: The line where the shadow DOM ends and the regular DOM begins.
  • Shadow Root: The root node of the shadow tree.

Benefits

  • Scoped CSS: Styles defined inside the shadow DOM do not affect the rest of the page.
  • DOM Isolation: Prevents external scripts from accidentally breaking the component's internals.

Related Terms