Skip to content

DLG-004 Never make the destructive button the default in a confirmation dialog

Level
Guideline, our choice
Verdict
Split (1 of 2)
Status
decided, version 1.0.2

Rule

In a dialog that asks the person to confirm a destructive action, put initial focus on the Cancel button, never on the destructive button, and never let Enter run the destructive action unless the person has moved focus to that button.

Examples

Live examples built with Justified's components. Try them with the mouse, the keyboard or a screen reader.

Do: Focus starts on Cancel

The dialog opens with focus on Cancel. Open it with the keyboard and press Enter at once: nothing is lost. To delete, move to Delete project with Tab first.

Don't: Focus starts on the destructive button

The dialog opens with focus on Delete project. The same habit, pressing Enter to get the dialog out of the way, now deletes the project. The person never chose it.

Why

The moment a dialog opens is the moment people are most likely to act without reading. Their hands are already on the keyboard, and Enter is the reflex that clears the way. If focus starts on the destructive button, or Enter fires it from anywhere in the dialog, that reflex deletes the project the person meant to keep. Starting on Cancel turns the dialog into a real pause: the person has to pick the destructive button on purpose, with Tab or a click, before anything is lost. WCAG 2.2, 2.4.3 Focus Order asks that focus moves in an order that keeps meaning and use intact. It does not say which element in a dialog gets focus first, so this rule is our choice. The pause it gives also supports 3.3.4 Error Prevention (Legal, Financial, Data) where that criterion applies.

Our reasons

The judges are split on this, so we chose. We start focus on Cancel in every destructive confirmation, also when the person asked for the action, for three reasons.

  • A stray key press must not destroy data. People press Enter out of habit, to clear whatever box is in the way, and sometimes by accident. A habit that saves a second must never cost a project, a customer list or a year of photos.
  • On the web, first focus decides what Enter does. A web page has no system default button that Enter presses from anywhere. Enter acts on the element that has focus. Choosing where focus lands is therefore the same as choosing what Enter will do, and we choose the answer that changes nothing.
  • The cost is one key press. A person who meant to delete presses Tab once and then Enter, or clicks the button. That small step is the price of the pause, and it falls only on people who have already decided.

Do

  • "Delete the project Autumn 2026?" opens with focus on Cancel. Enter now closes the dialog with nothing changed. To delete, the person moves to Delete project with Tab and presses Enter, or clicks it.
  • Set initial focus on Cancel in code, for example with autofocus, rather than leaving it to whichever element comes first.
  • Keep the buttons in the same order in every layout. If Cancel comes before Delete project in a row, it also comes first when the buttons stack on a small screen, in the code and on screen alike, as LAY-002 says.
  • Give the dialog its title as its name and its question as its description, for example with aria-labelledby and aria-describedby, so a screen reader can read them when focus lands on Cancel.
  • A dialog asks the person to type the project's name before Delete project works. Focus starts on Cancel as usual. Enter in the name field does nothing or moves focus on. It never runs the deletion, so the person still has to reach the button.
  • Once the person has moved focus to Delete project, Enter and Space press it, as with any button.

Don't

  • Open the dialog with focus on Delete project, even when the person has just chosen Delete in a menu.
  • Wrap the dialog in a form whose submit button is Delete project, so Enter in the name field deletes the project.
  • Listen for Enter anywhere in the dialog and run the deletion, whatever has focus.
  • Reverse the buttons when they stack, so Delete project comes first on a small screen. That breaks LAY-002, and focus left to the first button lands on the wrong one.
  • Mark Delete project as the button Enter will press, with a ring or a hint, before the person has moved to it.

Exceptions

  • Escape. Escape does what Cancel does wherever focus is, as DLG-001 says.
  • Actions that can be undone. When an action can be undone at once and no dialog is shown, this rule does not apply.
  • Labels and style. What the buttons say is covered by DLG-003, and how the destructive button looks by DLG-005.
  • Enter in a form. FRM-015 lets Enter send a form, but leaves destructive confirmations to this rule.

Verdict

Split (1 of 2). Only the judges decide; the expert witnesses are shown but do not vote. The judges do not settle this one, so it is a guideline: our own choice, with our reasons above. How verdicts work

Stances on DLG-004
SourceRoleStancePage
WCAG 2.2LawSupports2.4.3 Focus Order
WCAG 2.2LawSupports3.3.4 Error Prevention (Legal, Financial, Data)
Material DesignJudge No position
Apple Human Interface GuidelinesJudge OpposesAlerts
Carbon Design SystemJudge SupportsModal: accessibility
GOV.UK Design SystemExpert witness No position
Nielsen Norman GroupExpert witness SupportsConfirmation Dialogs Can Prevent User Errors, by Jakob Nielsen

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.2, : Points to FRM-015, which leaves Enter in a destructive confirmation to this rule.
  • 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