DLG-001 Let Escape do what Cancel does in a dialog
- Level
- Rule
- Verdict
- Unanimous (3 of 3)
- Area
- Dialogs
- Status
- decided, version 1.0.3
Rule
In a dialog that has a dismissive action, which is Cancel, Close, a close icon or, where none of those exists, the button that leaves everything as it is, pressing Escape does exactly what that action does, including any check before unsaved input is thrown away, and never confirms, submits or runs the destructive or default action.
Examples
Live examples built with Justified's components. Try them with the mouse, the keyboard or a screen reader.
Do: Escape keeps the old name, as Cancel does
Folder: Invoices 2026
Do: Escape asks the same question as Cancel
Customers
- Ines Park
Don't: Escape closes when Cancel would ask
Customers
- Ines Park
Why
Escape is the key people press to back out. If it does something other than the visible way out, they lose control: a form is sent, a file is deleted, or a long text is gone without a word. When Escape and Cancel lead to the same place, a keyboard user can leave a dialog without hunting for the button, and anyone can trust that pressing it changes nothing they did not choose. WCAG does not ask for Escape. It does ask that a dialog can be used and left by keyboard, under WCAG 2.2, 2.1.1 Keyboard and 2.1.2 No Keyboard Trap, and this rule supports both.
Do
- In a dialog called "Rename folder" with Cancel and Save, pressing Escape closes the dialog and the folder keeps its old name, just as Cancel would.
- In a dialog called "New customer" where the person has typed a name and an address, Cancel first asks "Discard the changes?", as the guideline FRM-004b describes. Escape asks the same question, with Cancel and Discard changes. If the person picks Cancel, the dialog and every typed value stay as they were.
- In a dialog with only I understand and a close icon, Escape does what the close icon does. It does not count as pressing I understand.
- When a popup is open inside the dialog, such as the list under Country or a date picker, the first Escape closes only that popup. The next one closes the dialog.
- When Cancel and the close icon do different things, Escape follows the one that loses less of the person's work. FRM-004a has such a case: the close icon keeps a draft and Cancel discards, so Escape keeps the draft.
- A warning that the person will soon be signed out has Stay signed in and Sign out, and no Cancel. Stay signed in leaves everything as it is, so Escape does that, as STA-004 says.
- If a press on the backdrop closes the dialog, it takes the same path as Escape and Cancel, with the same check. This is our own point.
- Send Escape and the dismissive action through the same code, so they cannot drift apart. If you use the native HTML
dialogelement, handle itscancelevent so Escape runs the same check as Cancel. - Where focus goes when the dialog closes is decided by DLG-006: back to the control that opened it, or to a logical place nearby when that control is gone.
Don't
- Let Escape press the default button. In "Save changes?" with Save highlighted, Escape must not save.
- Let Escape press the focused button. In "Delete the project?", Escape never deletes, even when focus is on Delete.
- Close a dialog with unsaved input straight away on Escape, when Cancel would have asked first.
- Let Escape do nothing in a dialog that has Cancel or a close icon.
- Close the whole dialog on the first Escape while a menu or list inside it is still open.
Exceptions
- No way out. A dialog with no dismissive action at all, where every button commits something, is outside this rule. A dialog that destroys data always has Cancel, as DLG-003 says, so it is always inside this rule. Do not remove a way out only to avoid this rule.
- While sending. After the person has confirmed and the dialog shows that it is working, such as "Saving …", this rule does not decide what Escape does. STA-005a covers that moment. Its own choice is that Escape, Cancel and the close icon behave alike, and either stop the request or are unavailable until the reply.
- Non-modal panels. A side panel or a non-modal dialog that people can work beside is outside this rule.
Verdict
Unanimous (3 of 3). Only the judges decide; the expert witnesses are shown but do not vote. How verdicts work
| Source | Role | Stance | Page |
|---|---|---|---|
| WCAG 2.2 | Law | Supports | 2.1.1 Keyboard |
| WCAG 2.2 | Law | Supports | 2.1.2 No Keyboard Trap |
| Material Design | Judge | Supports | Dialogs: accessibility Dialogs: guidelines |
| Apple Human Interface Guidelines | Judge | Supports | Alerts Modality |
| Carbon Design System | Judge | Supports | Modal: usage Modal: accessibility |
| GOV.UK Design System | Expert witness | No position | |
| Nielsen Norman Group | Expert witness | No position |
Each stance links to the page it rests on, read on the date in the source register. This page never repeats what a source says; read the source itself.
History
- Version 1.0.3, : Focus after closing is now DLG-006, and the time while sending STA-005a. The discard example refers to FRM-004b.
- Version 1.0.2, : Escape follows the dialog's dismissive action, also when that is the one button that changes nothing; says what Escape does when Cancel and the close icon differ and that a backdrop press takes the same path.
- Version 1.0.1, : Examples in English.
- Version 1.0.0, : First version.
Last checked against the other rules for conflicts on .
More in Dialogs: 5 rules and 2 guidelines · All rules
Justified is an independent project. It is not affiliated with, sponsored or endorsed by the organisations whose guidance it cites. Read the full statement.
Apple is a trademark of Apple Inc., registered in the U.S. and other countries and regions.