Outline updated November 2026
Introduction to Web Components
Class Duration
14 hours of live training delivered over 2 days.
Student Prerequisites
- Experience with modern JavaScript or TypeScript
- Experience with web browser programming
Target Audience
Web developers who want to build encapsulated, reusable UI with the platform's own standards. Teams continuing on can move to Professional Web Components with Lit.
Description
This course teaches developers to build reusable UI components with nothing but the web platform. The same components work in plain HTML pages and inside React, Angular, Vue, or Svelte apps. After a review of HTML, CSS, and JavaScript, students define Custom Elements and encapsulate them with Shadow DOM. They expose styling hooks, render shadow roots on the server with Declarative Shadow DOM, and compose content with slots. The course closes with form-associated elements built on ElementInternals and unit testing in a real browser.
Learning Outcomes
- Explain how Custom Elements, Shadow DOM, and HTML templates fit together.
- Set up a Web Components project with Vite and TypeScript.
- Define Custom Elements and use lifecycle callbacks correctly.
- Reflect attributes and properties.
- Encapsulate markup and styles with Shadow DOM.
- Expose styling hooks with custom properties,
::part, and:state(). - Compose components with templates, named slots, and
slotchangeevents. - Render components on the server with Declarative Shadow DOM.
- Build form-associated custom elements with
ElementInternals. - Unit test components in a real browser.
Training Materials
Comprehensive courseware is distributed online at the start of class.
Software Requirements
Students will need a free, personal GitHub account to access the courseware. Students will need permission to install Node.js and Visual Studio Code on their computers. Also, students will need permission to install NPM Packages and Visual Studio Code extensions. If students are unable to configure a local environment, a cloud-based environment can be provided.
Software versions: a current release of Chrome, Edge, Firefox, or Safari, with Vite 8, TypeScript, and Node.js 22.12 or later.
Training Topics
What are Web Components?
- What problem do Web Components solve?
- Custom Elements, Shadow DOM, and templates
- Web Components alongside React, Angular, Vue, and Svelte
- Browser support and Baseline features
Language Review
- HTML
- Elements and custom elements
- Attributes vs. properties
- Semantic meaning and accessibility
- Template and slot elements
- CSS
- Selectors
- Id, class, element, and attribute selectors
- Pseudo-classes and pseudo-elements
- Combinators
- Specificity
- Custom properties
- Scoping strategies
- Layout with Flexbox and Grid
- Selectors
- JavaScript
- Classes and inheritance
- ES modules
- Promises and async/await
- TypeScript
- Typing DOM APIs
- Declaring custom elements in
HTMLElementTagNameMap
- Browser API review
- Selecting elements
- Creating, appending, removing, and cloning elements
- HTTP requests
- The Fetch API
- Cancelling requests with
AbortController
- Events
- Bubbling and capturing
- Registering event handlers
- Custom events and event data
- Prevent default and stop propagation
Project Setup with Vite
- Creating a Vite project with TypeScript
- Native ES modules in the browser
- Dev server and hot module replacement
- Production builds and library mode
Web Components: Custom Elements
- Define a new Custom Element class
- Register a Custom Element and naming rules
- Lifecycle callbacks
- Connected callback
- Disconnected callback
- Adopted callback
- Attribute changed callback and observed attributes
- Reflecting attributes and properties
- Element upgrades and
whenDefined() - The
:definedpseudo-class - Scoped custom element registries
- Native classes without transpilers
Web Components: Shadow DOM
- Shadow host, shadow tree, shadow boundary, and shadow root
- Attach a shadow root
- Open vs. closed shadow roots
- Delegating focus
- Applying styles with
:hostand::slotted() - Constructable stylesheets and
adoptedStyleSheets - Theming with CSS custom properties
- Styling hooks with
::partandexportparts - Custom states with
CustomStateSet - The
:state()pseudo-class - Events across the shadow boundary
composedevents and retargeting
Web Components: Declarative Shadow DOM
- Server-rendered shadow roots with
<template shadowrootmode> - Declarative styles and slots
- Hydrating a declarative shadow root on the client
- Progressive enhancement and server-side rendering use cases
Web Components: Templates and Slots
- Template element
- Usage with Web Components
- Slot element
- Named slots and fallback content
- Project content with slots
- Reacting to
slotchange - Reading assigned elements
Web Components: Forms and Accessibility
ElementInternalsandattachInternals()- Form-associated custom elements with
static formAssociated - Setting form values with
setFormValue() - Validation with
setValidity() - The constraint validation API
- Form reset and disabled callbacks
- Restoring form state
- Default roles and ARIA properties through
ElementInternals - Keyboard interaction and focus management
Web Components: Unit Testing
- Testing in a real browser
- Vitest browser mode or Web Test Runner
- Unit test scaffolding
- Test suite
- Test
- Setup and teardown
- Assertions
- Spies
- Mocks
- Querying inside shadow roots
- Testing attributes, events, and form behavior