Mid-level Track Roadmap

Accessible modals

This course covers building modal dialogs with the HTML dialog element instead of div overlays. It explains what showModal() provides natively: the top layer, the backdrop, focus trapping, Escape handling, inertness and focus restore. Lessons cover styling ::backdrop with Tailwind, initial focus and autofocus choices, Tab order, backdrop clicks and scroll locking. It also covers ARIA names, sr-only labels and aria-hidden icons, a reusable ui--dialog Stimulus controller with lazy turbo-frame loading, and a checklist for testing the full dialog lifecycle.

What you'll learn

  • ✓What showModal() does natively compared with a div overlay
  • ✓Styling the ::backdrop pseudo-element with Tailwind's backdrop: variant
  • ✓Focus trapping, initial focus, autofocus choices and focus restore
  • ✓Escape, Tab order, backdrop clicks and preventing scroll behind the dialog
  • ✓Naming dialogs and labeling icon buttons for screen readers with ARIA
  • ✓A reusable ui--dialog Stimulus controller with lazy turbo-frame loading
Free preview · Lesson 1 4 min read

The `<dialog>` element replaces div overlays

Before HTML added <dialog>, every modal on the web was a <div> with position: fixed, a backdrop built from another <div>, and a pile of JavaScript to manage focus, keyboard events and screen reader announcements. That approach works, but it reimplements browser behavior that the <dialog> element…

Read the full lesson free →

Curriculum

7 lessons
Type to start searching...