Skip to content
easeweb
Search topics

Confirmation dialogs that don't read out their question

A delete confirmation has no name and an unlinked message, so a screen reader announces only the Delete project button that focus lands on.

WCAG 2.2
SC 4.1.2ASC 2.4.3A
Required by
Section 508 · EN 301 549 (EU)
Broken <div class="confirm" role="dialog" aria-modal="true">
The accessibility problem illustrated: No vision:Delete what?
01

The problem

Screen reader users land on Delete project without hearing what it will delete, and once it is deleted, keyboard focus is lost on the page

02

Try it

Tab to a Delete button and press Enter, then press Enter again

Watch which button has focus when the dialog opens, and read what a screen reader would say. After deleting, see where focus is.

Broken Can you fix this?

BrokenA confirmation whose question is never read

Projects

  • Spring launch · 24 files
  • Annual report · 9 files
  • Team photos · 132 files

A recreated demo. The broken version is intentionally inaccessible.

03

The fix

Have the question read out, and start focus on Cancel

Before
BrokenA confirmation whose question is never read
<div id="page">  <h2>Projects</h2>  <ul>    <li data-name="Spring launch" data-files="24">      Spring launch · 24 files <button type="button" class="delete">Delete</button>    </li>    …  </ul></div> <div class="confirm" role="dialog" aria-modal="true" hidden>  <h2 class="confirm-title">Delete “Spring launch”?</h2>  <p class="confirm-message">This deletes the project and its 24 files. It can't be undone.</p>  <button type="button" class="cancel">Cancel</button>  <button type="button" class="ok">Delete project</button></div>
What is wrong4 points

On screen it matches the fixed versions word for word, and the page behind it is inert and Escape works, so it passes a look and a quick keyboard check. Neither check shows the rest.

  • A screen reader announces just "dialog", with nothing about what it asks. Nothing links the title to the dialog.
  • The message, which says what will be deleted and that it can't be undone, is not read when focus moves in. Nothing links it to the dialog either.
  • One stray Enter deletes the project. Focus starts on Delete project, so the very key press a confirmation is meant to catch goes through.
  • After deleting, focus is lost, and a keyboard user loses their place in the list. trigger.focus() aims at a button that has just been removed, so focus falls to the body.
After

A native dialog

<div id="page">  <h2 id="projects-heading" tabindex="-1">Projects</h2>  <ul>    <li data-name="Spring launch" data-files="24">      Spring launch · 24 files <button type="button" class="delete">Delete</button>    </li>    …  </ul></div> <dialog id="confirm-delete" role="alertdialog"  aria-labelledby="confirm-title" aria-describedby="confirm-message">  <form method="dialog">    <h2 id="confirm-title">Delete “Spring launch”?</h2>    <p id="confirm-message">This deletes the project and its 24 files. It can't be undone.</p>    <button value="cancel" autofocus>Cancel</button>    <button value="delete">Delete project</button>  </form></dialog>
How it is fixed6 steps
  1. Give the dialog role="alertdialog", which tells a screen reader this dialog needs an answer.
  2. Name it from its title with aria-labelledby, and link the message with aria-describedby, so the message is read with it.
  3. Put autofocus on Cancel, so a stray Enter keeps the project.
  4. Open it with showModal(). The page behind becomes inert, and Escape closes it.
  5. Put the buttons in a method="dialog" form. After Cancel or Escape, the browser returns focus to the Delete button.
  6. Clear returnValue before each opening. On close, when it is delete, remove the row and move focus to the list's heading, which has tabindex="-1", instead of letting it fall to the body.

This fixes the Before and passes 4.1.2 and 2.4.3. An animation, a styled ::backdrop and a click outside to close it (closedby="any", not yet in Safari in October 2026) work on the native dialog too, and focus still moves the moment showModal() runs.

Why this fix: Use native HTML first

Easily confused
04

Verify the fix

5 checks, no mouse.

Test with: Keyboard, Screen reader, Zoom, Forced colors

0 of 5 checked

Record the OS, browser and assistive-technology versions, the build, the date, and the actual result of each step. Repeat after the shared dialog component changes.

How screen readers handle aria-describedby and <dialog>

Limits

This is a starting pattern, not a guarantee for every application. The snippets delete only from the page and leave out the request to the server, its errors, and what happens if it fails. A payment or an order needs more than a dialog: see checkouts that take payment with no review or undo. A delete button that asks people to hold a key down, or press it again within a few seconds, instead of asking a question is covered in hold-to-confirm buttons and other timed key presses. Screen readers differ in how much of an alert dialog they read on their own, so test the complete journey with your target assistive technology.

This is a recreated teaching example, not a finding about a named client. The code is a starting pattern: test it in your own product. No completed assistive-technology test is claimed here.

EaseWeb service

Fixed it? Keep it from coming back.

I turn guides like this one into rules your coding agents follow and checks your CI runs. Then I retest by hand with a keyboard and screen readers, periodically.

See the service