Custom JavaScript modal overlays
Possible replacement: <dialog>
Why this was flagged: The page uses script-managed modal surfaces without native
<dialog> behavior.
Why it may help
- Deletes custom focus-trap logic and open-state tracking.
- Lets the browser handle top-layer rendering and Escape key dismissal.
- Provides modal semantics and focus management with less custom JavaScript.
- Found in
-
-
Newsletter signup and mobile navigation overlays
.newsletter-modal#mobile-menu
-
Newsletter signup and mobile navigation overlays
See the example on CodePen for native dialog (opens in a new tab)
Current HTML + JavaScript
<div class="modal" role="dialog"
aria-modal="true" hidden>
<button class="modal__close">Close</button>
<!-- modal content -->
</div>
const modal = document.querySelector('.modal');
trigger.addEventListener('click', () => {
modal.hidden = false;
trapFocus(modal);
});
Modern alternative
<button type="button"
commandfor="site-modal"
command="show-modal">Open dialog</button>
<dialog id="site-modal" aria-label="Example dialog">
<button type="button"
commandfor="site-modal"
command="close">Close</button>
…
</dialog>