Skip to content
Journey to Code

Series

Journey to Web Components: From Fundamentals to Advanced UI Architecture

WEB COMPONENTS // ARCHITECTURE
Encapsulated & Modular

Build your own HTML tags with browser standards: custom elements, Shadow DOM, templates and slots, styling hooks and accessible behavior. HTML and CSS foundations come first and are optional if you already have them.

For readers who know a little HTML, CSS and JavaScript. Lessons 1 to 7 are foundations you can skip.

Try the component lab ↓Find your starting point ↓

COMPONENT / SCHEMATICSHADOW ROOT: OPEN
<app-card> / host element
Light DOM child
<h2 slot="header">Hello</h2>

↓ assigned to the named slot

#shadow-root (open)
<style> :host { ... } </style> <slot name="header">
→ renders "Hello"
<section part="body">

Slot assignment changes rendering, not parentage: the heading remains a light DOM child. This is an explanatory diagram, not a live DOM inspector.

LIVE LAB / A REAL CUSTOM ELEMENTEDIT. PROJECT. STYLE.

Don't just read the boundary. Test it.

Change a light DOM heading and watch it render through a named slot. Then style an exposed shadow part from the outside. No framework, editor setup, or installation.

The heading belongs to light DOM. The frame and body live in shadow DOM. The dashed boundary marks encapsulation, not a security barrier.

<mnix-component-lab> / live preview

Built on browser standards

This paragraph is projected through the default slot. It remains a child of the host element.

Progressive preview: content is readable before the custom element upgrades.

LIGHT DOM / ACTUAL HEADING
<h3 slot="header">Built on browser standards</h3>
EXTERNAL STYLING / CURRENT RULE
/* External part styling is off. */

Architecture explorer

The lab above shows one slot and one part. This one lets you pull every lever a component offers: attributes, slots, CSS custom properties, page CSS and shadow parts. Watch the light DOM, the shadow tree and the slot assignments change together.

The explorer needs JavaScript. The lessons on custom elements, the Shadow DOM, templates and slots, and component styling cover the same ideas.

QUICK PATH

Where to start

If you can read HTML and CSS and have used querySelector and an event listener, skip the foundations and start with your first component. If you need HTML, CSS or JavaScript first, begin with semantic HTML. If you only need one thing, pick it from the list.

Small boundaries. Composable interfaces.

  • <custom-element>Name your own element and define its behavior with native lifecycle callbacks.
  • #shadow-rootScope internal selectors. Inherited properties and CSS custom properties can still cross the boundary.
  • <template> / <slot>Reuse inert markup and compose it with content supplied by the host's light DOM.
  • ::part() / ::slotted()Expose deliberate styling hooks and target elements assigned directly to slots.
DEFINITION / MINIMAL EXAMPLENO ADDED LIBRARIES
JavaScript example
class AppCard extends HTMLElement {
  constructor() {
    super();
    const root = this.attachShadow({ mode: 'open' });
    root.innerHTML = `
      <style>:host { display: block; }</style>
      <slot name="header"></slot>
      <section part="body"><slot></slot></section>
    `;
  }
}
customElements.define('app-card', AppCard);

Illustrative source, not executed here. The shadow tree is attached once in the constructor; its markup is a fixed string, not untrusted input.

All lessons, in reading order

Lessons 1 to 7 are the optional foundations. The component lessons follow, starting with the introduction to web components.

  1. Establishing a Foundation of Semantic HTMLReplace a page of divs with header, nav, main and footer so visitors can jump straight to navigation, content or footer. · 7 min read
  2. Implementing Accessibility Best Practices in HTML & ARIA EssentialsLabel every control and image, add ARIA only where plain HTML cannot say it, and manage keyboard focus for screen reader users. · 8 min read
  3. Crafting Incredible HTML: Best Practices & Real-World ExamplesKeep HTML readable with consistent formatting, check it with a tool, and review it the way a stranger would. · 4 min read
  4. CSS Fundamentals for Accessible DesignWrite CSS that works for low-vision, keyboard and screen reader users: selectors, specificity, color, focus styles and units. · 8 min read
  5. Responsive Layouts & Advanced CSS TechniquesRearrange one page for phone and desktop with Flexbox, Grid and media queries, with legible type and spacing. · 6 min read
  6. Advanced CSS: Optimization & Best PracticesKeep CSS files small and rules understandable, and expose a few named CSS variables so a component can be re-themed. · 7 min read
  7. Exploring JavaScript Essentials for Enhancing HTMLMake a page react with JavaScript: hide a paragraph on a button press, update a list as you type, and load data from a server. · 4 min read
  8. Introduction to Web ComponentsBuild a custom tag like info-card that carries its own look and behavior, and see how Shadow DOM keeps its styles from leaking. · 8 min read
  9. Getting Started with Custom ElementsDefine a custom element, change an attribute and watch its text update, and see how it learns when it is added or removed. · 6 min read
  10. Lifecycle Callbacks & Component CommunicationReact when a custom element is added, removed or changed with lifecycle callbacks, then pass messages between components. · 7 min read
  11. Exploring the Shadow DOMAttach a private shadow tree to an element, choose open or closed mode, and learn which page styles can reach inside. · 6 min read
  12. How Templates and Slots WorkUse template for a fixed layout and slot for the blanks a page fills in, then combine them in a web component. · 5 min read
  13. Mastering the Art of Web Component StylingStyle a web component from outside through four doors in its wall: :host, ::slotted, CSS custom properties and ::part. · 10 min read
  14. Accessibility in Web ComponentsBuild custom elements that say what they are, work from the keyboard, and announce changes to screen reader users. · 12 min read
  15. Advanced Patterns & Integration with FrameworksPass objects from React to a custom element without getting [object Object], and handle events across the framework boundary. · 4 min read
  16. Real-World Examples & Patterns in Web ComponentsSee who publishes web components (Google, Microsoft, Adobe and others) and four patterns that make them easy to use, with runnable examples. · 11 min read
  17. The Future of Web ComponentsWhich Web Component features you can use today, which work in only some browsers, and which are still proposals, with a dated status table. · 8 min read