Examples
Mechanics
A bare-minimum modal
Open it, then try clicking outside it, pressing Escape, or pressing Tab — focus stays trapped inside the modal until you close it. Notice the body underneath does not scroll while it is open.
Confirm or cancel
The classic two-button pattern. The primary action is on the right and visually emphasized; the dismiss action is left of it. Either action ends the dialog.
Long content inside the modal
When the modal's content is longer than the viewport, the modal itself becomes the scroll container — the page underneath stays locked. The user gets a single, predictable scroll target.
Common use cases
Destructive confirmation
The canonical reason a modal exists. The action is irreversible, so the user is asked to slow down. The destructive button is styled differently — red here — to make the consequence visible at a glance.
A small focused form
A single-input edit form is exactly the kind of small task a modal handles well. The first input is auto-focused on open, the form submits on Enter, and the user is returned to the page they came from.
No backdrop dismiss, no escape
Sometimes the task must complete one way or another — clicking outside or pressing Escape would be a footgun. This trades user comfort for safety; reserve it for cases like 'accept these terms' or 'complete required setup' where a half-finished state is worse than friction.
Examples
Mechanics