Use a modal for a contained task that temporarily suspends the surrounding page. Keep the task short, provide a clear exit, and define where focus goes when the layer opens and closes.
Does this short task need to pause the page behind it?
A teammate chooses Edit display name from an account page. The layer contains one field, Save name, Cancel, and a close control. The person can finish this small edit without losing the account-page context.
The modal contract includes entry, containment, and return
State
Expected behavior
Failure to investigate
Open
Move focus to an appropriate element inside the titled dialog.
Focus stays on a control behind the layer.
Tab forward and backward
Cycle through the modal's available controls.
Focus escapes to the account page or reaches hidden controls.
Cancel or press Escape
Close the edit without applying it and restore the invoking context.
The name changes on cancellation or focus drops to the document body.
Save name
Apply the edit, communicate its outcome, and return to a logical place.
The layer disappears while the person remains uncertain whether the edit succeeded.
Why this choice
The dimmed background is only a visual cue. Modality also requires behavior that keeps the surrounding page unavailable. Focus placement and the exit path should be designed with the task, rather than patched after the animation is built.
Where the decision changes
Use a full page for a long, shareable workflow. Use an inline region or non-modal surface when the person must keep operating the background. If the opener has been removed, return focus to the next logical workflow target.
Try these checks
Open the Good UX example using the keyboard and locate the focused element.
Traverse every available control in both directions and check the wrap points.
Press Escape, reopen, then cancel; compare both exit paths and their return target.
Complete the edit and check the displayed name and outcome message.
What the sources support
APG specifies an inert background, contained tab sequence, Escape dismissal, and logical focus placement and return. W3C APG: Modal dialog ↗
The HTML dialog technique supplies implementation and testing guidance. Passing the lab checks alone does not establish full accessibility conformance. W3C: HTML dialog technique H102 ↗
These source claims were checked on . The scenario and decision analysis are illustrative; the checks are a test plan, not reported results from a user study.
Decision first
Choose this pattern when the problem matches
Use when
A short task must interrupt normal page interaction but should return users to the same context afterward.
The background page should remain visible for orientation but unavailable for interaction.
The task has clear complete and cancel outcomes.
Avoid when
The workflow is long, multi-step, shareable, or needs browser navigation.
Users must inspect or manipulate background content while the layer is open.
The only purpose is to confirm a destructive action, which needs confirmation-dialog guidance.
Problem it prevents
The user is working in a larger page but must complete a compact task before continuing.
Test the behavior
Try strong and weak versions of the interaction
Open the working example, try its controls, and compare the behavior against the decision guidance.
In the lab you can
switch between strong UI, weak UI, strong UX, and weak UX;
trigger required, empty, loading, error, and recovery states;
inspect keyboard and accessibility expectations beside the demo.
The user is working in a larger page but must complete a compact task before continuing.
Pattern promise
Open a titled dialog above the current page, make background content unavailable, place focus inside the dialog, keep focus contained until close, then return focus to the invoking control or next logical workflow point.
Required state
Closed page state with an obvious invoking control.
Failure to inspect
Background remains interactive while the modal is visible.
Access contract
Use dialog semantics with an accessible name from the visible title.
Quality bar
The difference between expert and weak execution
Strong implementation
Specific, visible, recoverable
Account settings opens in a titled dialog with one display-name field, Save, Cancel, close control, and dimmed inactive page context.
The dialog panel has a clear accessible name, stable width, readable body copy, and actions that remain visible.
Opening moves focus to the display-name field, Tab remains inside the layer, Escape cancels, and closing returns focus to Open dialog.
Save applies the compact task and returns the user to the same page context with a clear status message.
Weak implementation
Vague, hidden, hard to recover from
A vague popup titled Popup floats over active page controls and offers only OK.
A long settings workflow is squeezed into a small modal where the primary action scrolls out of reach.
Users can click background Delete or Navigate controls while the modal is still open.
Closing the dialog drops focus at the top of the document or loses the user's previous context.
UI guidance
Render a titled layer above a dimmed or otherwise unavailable page, with clear task content, named actions, visible close or cancel affordance, and stable scroll boundaries.
Keep background controls visually present for orientation but unavailable to pointer and keyboard interaction while the modal is open.
UX guidance
Use the modal interruption only for compact tasks that genuinely need temporary focus before the user returns to the page.
Make entry, completion, cancellation, Escape dismissal, and focus return predictable so users understand they are in a temporary mode.
Implementation contract
What the implementation must handle
States
Closed page state with an obvious invoking control.
Opening transition that moves focus into the dialog and marks background content unavailable.
Open task state with accessible title, concise body, primary action, secondary cancellation, and visible close behavior.
Keyboard cycling state where Tab and Shift+Tab remain inside the dialog.
Interaction
Tab and Shift+Tab cycle through focusable elements in the dialog until the user closes it.
Escape closes dismissible modal tasks and follows the same cleanup path as cancel.
Closing through save, cancel, Escape, or close button restores focus to the opener unless the workflow clearly moves elsewhere.
The dialog has an accessible name from its visible title and a useful description when body copy explains the task.
Accessibility
Use dialog semantics with an accessible name from the visible title.
Indicate modality so assistive technologies know the background is unavailable.
Move focus into the dialog on open.
Keep keyboard focus inside the dialog while it is modal.
Review
What page interaction must be blocked while this task is open?
Where exactly does focus go on open, on Tab wrap, on Escape, on cancel, and on completion?
Would a drawer, inline panel, or full page preserve the user's context better than a modal?
Does the title name the task rather than merely saying dialog or popup?