Production-ready modal implementations with pure CSS and modern HTML5
Pure CSS modal using the checkbox hack - no JavaScript required!
:checked pseudo-class. Clicking the backdrop or close button unchecks the checkbox.
Different entry/exit animations for visual variety
Styled confirmation modals for important actions
Modal containing a form for user input
Using the native HTML5 <dialog> element with enhanced styling
<dialog> element is well-supported in modern browsers (Chrome 37+, Firefox 98+, Safari 15.4+). Use a polyfill for older browsers.
Click any placeholder to open in a lightbox modal
Pure CSS Limitation: The checkbox hack method doesn't prevent body scrolling when a modal is open.
JavaScript Solution:
// Add when modal opens
document.body.style.overflow = 'hidden';
// Remove when modal closes
document.body.style.overflow = '';
Or use the native <dialog> element which handles this automatically!
<dialog>)role="dialog", aria-modal="true", aria-labelledby<dialog> element or a JavaScript-enhanced solution with proper focus management.
Use the <dialog> element styled with CSS for the best of both worlds:
showModal() and close())