In this lesson, you followed focus through the step ladder’s cancel dialog on My Reservations, the way Mei Lin Chen does with the keyboard:
- Focus moves in. When Cancel step ladder opens the dialog as a modal, the dialog goes into the top layer, the backdrop dims the page, and focus lands on Keep it, the first element in the dialog that can take focus. That’s a safe start: an accidental Enter keeps the reservation. To start focus on another element, give that element the
autofocusattribute. - Focus stays off the page. Tab moves between Keep it and Yes, cancel, and past the last button out to the browser’s own controls, then back to Keep it. Those controls belong to the browser, so that’s expected. While the modal is open, the rest of the page is inert: Cancel hedge trimmer never gets focus, and nothing behind the backdrop takes clicks.
- A click on the backdrop doesn’t close it. A native modal stays open, so always give it a visible way to close, like Keep it.
closedby="any"adds closing on an outside click, but it isn’t Baseline yet. Some popovers, which come later in this section, close on an outside click. - Focus comes back. The browser remembers which button opened the dialog. Esc or Keep it closes the dialog and returns focus to Cancel step ladder.
- What a screen reader gets. With the dialog open, turn on Show accessibility tree at the top of the Accessibility pane of DevTools’ Elements panel. Chromium’s accessibility tree (November 29, 2026) holds one dialog, marked modal, named “Cancel the step ladder?” from its heading, with its text and its two buttons. The reservations behind it aren’t in the tree.
- So on opening, a screen reader should announce a dialog with that name, then the Keep it button, and on closing, the Cancel step ladder button. Check it with your own screen reader.
- The
openattribute does none of this. Showing a dialog withopendoesn’t move focus in: its buttons are part of the page, so Tab goes through them and on to Cancel hedge trimmer, and Esc does nothing. Nothing behind it is inert either, so the page’s buttons still take clicks. - When Keep it closes the dialog, no button opened it, so focus goes to the page itself. No focus ring shows and there’s no button for a screen reader to announce, so Mei Lin can’t tell where she is. The browser keeps her place where the dialog was, so the next Tab reaches Cancel hedge trimmer, but the modal had put her back on her own button.
Here’s the ladder’s button and dialog, unchanged from the last lesson (with its popover fallback attributes left out):
<button type="button" commandfor="cancel-ladder"
command="show-modal">Cancel step ladder</button>
<dialog id="cancel-ladder" class="cancel-dialog"
aria-labelledby="cancel-ladder-title">
<h2 id="cancel-ladder-title">Cancel the step ladder?</h2>
<p>Another member can then reserve it for December 4.</p>
<form action="reservation-cancelled.html">
<input type="hidden" name="tool" value="step-ladder">
<button type="button" commandfor="cancel-ladder"
command="close">Keep it</button>
<button>Yes, cancel</button>
</form>
</dialog>
A modal dialog moves focus in, keeps it away from the inert page behind, and gives it back to the button that opened it.