Native HTML

The <dialog> Element

Modern browsers provide a native modal element with built-in accessibility. Focus trap, Escape to close, and backdrop are all handled automatically!

Design System

Comprehensive component library with accessibility built-in.

🎭

Animation Library

Motion primitives respecting prefers-reduced-motion.

📊

Data Visualization

Interactive charts with keyboard navigation support.

Feature Comparison
Feature CSS :target Vanilla JS <dialog>
Focus Trap ✓ Manual ✓ Native
Escape to Close ✓ Manual ✓ Native
Backdrop ✓ Manual ✓ Manual ✓ Native
Top Layer (above z-index) ✓ Native
Return Focus ✓ Manual ⚠ Manual
No JavaScript
Browser Support All All Modern*
HTML Structure
<!-- Native dialog element --> < dialog id = "my-dialog" > < form method = "dialog" > < h2 >Dialog Title</ h2 > < p >Content here...</ p > <!-- form method="dialog" auto-closes --> < button value = "close" >Close</ button > </ form > </ dialog >
JavaScript Methods
const dialog = document. getElementById ( 'my-dialog' ); // Open as modal (with backdrop) dialog. showModal (); // Open non-modal (no backdrop) dialog. show (); // Close dialog. close (); // Listen for close dialog. addEventListener ( 'close' , () => { console. log ( 'Dialog closed' ); });
CSS Styling
/* Style the backdrop */ dialog::backdrop { background : rgba(0, 0, 0, 0.8) ; backdrop-filter : blur(4px) ; } /* Animate open state */ dialog[open] { animation : fadeIn 0.3s ease ; } @keyframes fadeIn { from { opacity : 0 ; } to { opacity : 1 ; } }