Overview
Modals get the user's attention by appearing as an overlay above the main webpage content. They interrupt the user's workflow by design.
When a modal is active, the user is unable to interact with the main page content. They can't return to their previous workflow until the modal task is completed or the user dismisses the modal.
While modals can be effective when used correctly, they should be used sparingly.
When to use a modal
If you need an immediate response from the user
Use a dialog to request information that is preventing the system from continuing a user-initiated process.
To notify the user of urgent information
Use a modal dialog to notify the user of urgent information concerning their current work. Modal dialogs are commonly used to report system errors or convey a consequence of a user’s action.
To confirm a user decision
Use a modal dialog to confirm user decisions. Clearly describe the action being confirmed and explain any potential consequences that it may cause. Both the title and the button should reflect the action that will occur. If the action is destructive or irreversible then use a transactional danger modal.
When to use another component
Only use modals to provide notifications to the user if the information is critical to their task. For other notifications, consider using an in-page alert or a toast. These are less disruptive to the user.
Formatting
Anatomy
- Container
- Icon (optional)
- Close icon button – selecting the button closes the modal window without submitting any data
- Heading
- Body copy
- Primary call to action with an optional icon Icon optional
- Secondary call to action
- Overlay – obscures the on-page content
Behaviors
Triggers
Modals are triggered as a result of a user’s action. Buttons, links, or icons are common components that trigger a modal. On a keyboard, typing Enter or space bar should launch the modal.
A modal can be closed by clicking on the close icon or typing Esc.
Focus
When a modal window opens, focus moves to the close button inside the window. Focus should remain trapped in the modal until it is closed. When navigating by keyboard, Tab and Shift-Tab do not move the focus outside of the modal.
Tab:
- Moves focus to the next focusable element inside the window.
- If focus is on the last focusable element inside the window, Tab moves focus to the first focusable element inside the window.
Shift + Tab:
- Moves focus to the previous focusable element inside the window.
- If focus is on the first focusable element inside the window, Tab moves focus to the last focusable element inside the window.
Esc:
- Closes the window. Keyboard focus returns to the component that opened the modal.