Skip to the page

Observers, workers and the platform · senior

Web components and Shadow DOM

Custom elements (customElements.define) plus Shadow DOM give framework-free components with encapsulated styles; they are used for design systems shared across frameworks.

The notes

What you must know

  • class MyEl extends HTMLElement with connectedCallback, disconnectedCallback, attributeChangedCallback and observedAttributes.
  • attachShadow({ mode: 'open' }) scopes CSS; slots project light-DOM children; ::part exposes styling hooks.
  • Events crossing the shadow boundary are retargeted; set composed: true to let custom events escape.
  • React 19 supports custom elements properly (properties and custom events).

The red pen

Common traps: mistake → fix

  • Mistake: "Shadow DOM is a security boundary"

    Fix: it is style and DOM encapsulation, not isolation from scripts.

Easy to hard

Questions interviewers ask, easy to hard

  1. What problems do web components solve?
  2. How do styles work with Shadow DOM?

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview