Open mode is a Shadow DOM attachment setting that exposes a component’s shadow root through its shadowRoot property. The shadow root remains a separate DOM tree, but code with access to the host can cross the boundary deliberately. section 8.2
Attach an open shadow root
Inside connectedCallback(), call this.attachShadow({mode: 'open'}), then use this.shadowRoot to populate the component. For example, setting this.shadowRoot.innerHTML creates an internal div. Outside code cannot find that div with a document-level query, but it can reach it through the host: document.querySelector('sample-component').shadowRoot.querySelector('.inside-component'). section 8.2
Use open mode when controlled inspection or access is more useful than a strict boundary:
- It blocks ordinary document-level selectors from reaching component internals, reducing accidental intrusions. section 8.2
- It preserves an escape route through the host’s shadowRoot property when debugging, integrating, or making a deliberate change. section 8.4 section 8.2
- The mode must be supplied explicitly; browser vendors did not choose a default between open and closed. section 8.2
