Modal
The modal component inform users about a specific task and may contain critical information which users then have to make a decision. E.g Accepting the T&Cs during signup
Example
Anatomy
- Icon (situational): Serves to give more context to what the modal is about.
- Title: Serves to tell users what the modal is about.
- Close icon (situational): Allows users to close the modal manually without the use of CTA buttons.
- Content: Serves to explain what the model is about. For e.g error messaging or confirmation messaging.
- CTA buttons: Serves to let users take an action or cancel.
Spacing
Within the modal
Ensure that there is at least 24px of spacing within the modal and
between content elements.
Usage guidelines
Modals should be used when:
- You want to interrupt a user's current task to direct the user's attention to something important. For example, confirming when a user wants to submit a form, user sign up and login, or highlighting an important event with an infographic upon entering your website.
- You want to highlight something.
Modals should not be used when:
- You need to present simple notifications to the user. It should always accompany something actionable by the user such as confirming or filling in a form. If you need to notifiy the user, use something less intrusive such as the notification component instead.
Usability guidelines
User triggered
Modals should always appear as a result of a action that a user has taken like when submitting a application. Modals should not be automatically displayed to the user. Some exceptions to the rule would be if you need to inform users that their session is about to time out or if they have to accept cookies before proceeding.
Clear heading labels and CTAs
Ensure that the heading and CTAs are clear to the user. This avoids confusion and indicates what action needs to be taken.
Try to avoid long content with scrolling
Long content with scrolling limits a user's ability to view the entire message due to the limited space.
Behaviour
Allow users to close the modal by clicking the backdrop (the area outside the modal) and by pressing the Esc key.
Accessibility guidelines
Aria attributes
-
The element that serves as the dialog container has a
role="dialog"
. -
All elements required to operate the dialog are descendants of the element that has
role="dialog"
. -
The dialog container element has
aria-modal="true"
.
Keyboard accessibility
- Tab or Shift-Tab to move the focus between elements within the modal.
- Enter or Space to select action buttons or interactive elements.
- Esc to close the modal.
Focus indicator
- When the modal opens, move focus to the first interactive element within the modal. When the modal closes, return focus to the element that triggered the modal.
- Ensure all interactive elements within the modal are keyboard navigable. Trap focus within the modal so that tabbing does not navigate to elements outside the modal.
-
Include a close button and ensure it is keyboard accessible and properly labeled using
aria-label
.
Modal design tokens
Last updated 02 October 2024