A modal (or dialog) is a box that pops open on top of the webpage, usually covering the whole page or a major portion of the page.
What makes an accessible modal?
In order to be accessible, modals:
-
should be hidden with
visibility: hidden, - should have an accessible name,
-
should have a
role="dialog"assigned, - should move focus inside the dialog,
- should not allow focus outside of the box,
- can be closed with Esc ,
- can be closed with a touch/click outside of box,
- can be closed with a close button (if present),
- when closed, should return user focus to the element that initiated the modal,
Why create a custom modal?
The
dialog
element is not supported across most browsers.
People who know this stuff
- Scott O'Hara: Accessible Modal Dialogs with Vanilla JS
- W3C: Modal Dialog Example
- Harvard University: Support Keyboard Interaction