Course contentsShow
← Web Development
Lesson 1162 of 2,98221. Accessible ComponentsFree lesson

Confirmation Dialogs and Destructive Actions

Building accessible confirmation modals with clear messaging and appropriate button focus order.

Confirmation Dialogs and Destructive Actions

What you'll learn: How to build accessible confirmation modals that protect users from accidental destructive actions through clear messaging and proper focus management.

Destructive actions—like deleting an account, permanently removing data, or canceling a subscription—can't be easily undone. A confirmation dialog acts as a safety net, giving users a moment to reconsider before committing. For accessibility, these dialogs must communicate clearly what will happen and guide keyboard users to the safest option first.

Clear, Specific Messaging

Avoid vague prompts like "Are you sure?" Instead, explicitly state the consequence: "Delete 'Project Alpha'? This action cannot be undone." Users—especially those relying on screen readers—need to understand the stakes immediately without hunting for context elsewhere on the page.

Button Focus Order Matters

When your confirmation modal opens, initial focus should typically land on the safer action (usually "Cancel" or "Keep"). This prevents accidental confirmation if a user habitually presses Enter or Space. Think of it like a car with the brake pedal positioned before the accelerator—safer by default.

For highly destructive actions, place focus on the Cancel button first. For less critical confirmations, you might focus the confirmation button, but err on the side of caution. The tab order should flow logically: Cancel → Confirm → Close (if present).

Implementation Pattern

Your confirmation dialog should trap focus (preventing users from tabbing to background content), announce its purpose to screen readers, and restore focus to the triggering element upon close—all patterns you've already learned. The unique aspect here is the semantic labeling and focus priority that emphasizes safety.

<dialog aria-labelledby="confirm-title" aria-describedby="confirm-desc">
  <h2 id="confirm-title">Delete Account?</h2>
  <p id="confirm-desc">This will permanently remove all your data.</p>
  <button>Cancel</button><!-- Focus lands here first -->
  <button>Delete Account</button>
</dialog>

Key Takeaway: Accessible confirmation dialogs for destructive actions prioritize safety through explicit messaging and strategic initial focus placement—typically on the Cancel button—to prevent accidental data loss.