The popup close button accessibility label and focus order is the least glamorous part of a lead-capture build, and the part visitors reach for most. A dismiss control that screen readers announce as a bare "button", that Tab skips, or that jumps under the pointer after your embed script loads will cost you the interaction you were trying to win. This guide sets one target outcome: a close control that is clearly named, reached first by keyboard users, closes every path cleanly, and stays put on screen while the widget boots.
The scope is deliberately narrow. We assume a WidgetJar popup is already configured and installed for the registered website domain via the embed script, and that a visitor can see and dismiss it with a mouse. What follows is the announcement-ready rebuild of the one control everyone uses and almost nobody tests.
Why the close button deserves its own test pass
Popups are interruptions. A visitor who did not ask for the dialog has one job: get rid of it. If that job is hard for a keyboard user, a screen reader user, or someone with a motor impairment, they leave and remember the interruption, not the offer.
The WAI-ARIA Authoring Practices dialog pattern is explicit here: it is "strongly recommended that the tab sequence of all dialogs include a visible element with role button that closes the dialog, such as a close icon or cancel button" (WAI-ARIA dialog pattern). That single sentence drives this whole article: visible, focusable, named, and inside the tab sequence.
If your popup is a custom <div> rather than a native <dialog>, everything the browser gives you for free has to be rebuilt and re-tested. Our comparison of a dialog element vs custom modal div for popups covers which behaviors you inherit and which you owe; this article assumes you own them and need to prove they work.
Name the control: visible text or a labeled icon, never a bare SVG
An icon-only dismiss button is the most common defect in lead-capture popups. If the button contains only an inline SVG and no text, assistive technology falls back to the element name and often announces simply "button". A visitor cannot know what it does.
Use one of these, in order of preference:
- Visible text:
<button type="button">Close</button>. Best for announcements where the dialog is prominent and space allows. - Icon plus an accessible name: a button wrapping the SVG, with
aria-label="Close"on the button, andaria-hidden="true"plusfocusable="false"on the SVG so its paths are not announced. - Visually hidden text inside the button when you want the name to live in the DOM as real text.
<button type="button" class="popup-close" aria-label="Close announcement">
<svg viewBox="0 0 24 24" width="20" height="20" aria-hidden="true" focusable="false">
<path d="M6 6l12 12M18 6L6 18" />
</svg>
</button>
Two traps to avoid. First, do not put the aria-label on the SVG instead of the button; the name must sit on the focusable control. Second, do not use title as the only name; it is unreliable and does not appear for touch or keyboard focus. Our accessible popup checklist walks through naming alongside the rest of the dialog, and if you are auditing icon-only controls across a page, the inline SVG accessible labels guide applies the same rule to another embed type.
Focus order: decide first or last, then keep it honest
The WAI-ARIA pattern says that when a dialog opens, focus moves to an element inside the dialog, and that "generally, focus is initially set on the first focusable element" (WAI-ARIA dialog pattern). For a lead-capture popup, the close control is a defensible first stop: a visitor who wants out should not have to traverse a headline, a form and a privacy note to escape.
The native <dialog> element follows this model. MDN notes that showModal() sets focus on the first nested focusable element, and recommends autofocus on the close button "if no other element involves more immediate interaction" (MDN dialog element).
Practical rules for the build:
- Put the close button first in DOM order inside the dialog, or use
autofocuson it. Do not usetabindexvalues greater than zero to force the order; that creates a parallel tab sequence that breaks containment. - Confirm the visual position matches the DOM order. A close icon pinned to the top-right with CSS is fine only if it is also the first focusable element or is reachable without surprise.
- If your layout puts the close button last visually, keep it last in the DOM too and put the opening focus on a static heading with
tabindex="-1"instead, following the pattern's advice for content-heavy dialogs. - Tab and Shift+Tab must cycle within the popup and never land on the page behind it.
If you have not written the containment test yet, the step-by-step script in modal focus management covers entry, containment and return in enough detail to reuse.
Every close path returns focus to the opener
Closing is not finished until focus lands somewhere sensible. The pattern is direct: "When a dialog closes, focus returns to the element that invoked the dialog" unless that element no longer exists, in which case focus moves to another element that provides a logical work flow (WAI-ARIA dialog pattern).
Implement three close paths and give each the same return behavior:
| Path | Trigger | Focus after close |
|---|---|---|
| Close button | Click, Enter or Space on the labeled control | The opener (link or button that launched the popup) |
| Escape | Key press while focus is inside | The opener |
| Outside click, if enabled | Pointer on the backdrop | The opener, since keyboard users were never in the backdrop |
Store a reference to the opener when the popup opens, then call focus() on it in the close handler. On a native dialog, Escape dismissal is built in, but the focus return is not automatic for a custom trigger, so add it. If your popup is a stored embed that opens on a timer with no user trigger, return focus to the nearest stable control, such as the first link in the announcement region or the site header, and document that choice.
The failure mode to hunt down is the one described in this fix guide on a popup form that leaves focus behind the page after close: the dialog vanishes and focus silently resets to the top of the document, so a screen reader user has no idea where they are.
Escape deserves a note for multi-dialog pages. Per MDN, if multiple modal dialogs are open, Escape should close only the last shown one, and the native element provides that behavior (MDN dialog element). If you have more than one WidgetJar popup eligible on a page, resolve the conflict before shipping rather than after a complaint.
Reserve the popup's space so the close button never moves
The accessibility work above can be undone by a layout shift at exactly the wrong moment: the visitor moves the pointer toward the close icon, the embed finishes loading, the popup grows by 40px, and the click lands on the privacy link.
Two measurements matter. Cumulative Layout Shift is the one that catches this movement. Largest Contentful Paint is the one that tells you whether the embed has delayed your main content; Google's guidance targets LCP of 2.5 seconds or less for at least 75% of visits, and warns that text or images managed by JavaScript rather than present in the initial HTML can widen the gap between first paint and LCP (web.dev: Optimize LCP).
Reserve dimensions on the placeholder or wrapper before the script executes:
.popup-slot {
min-height: 320px; /* match your configured popup height */
width: 100%;
max-width: 480px;
}
For a modal that overlays content, the shift risk is lower but the close button can still reflow within the panel. Fix the header row height so the icon's hit area does not move when the headline wraps to a second line. The full method, including how to capture a baseline, is in reserve space for popup embed to prevent layout shift.
A pre-launch test script you can run in fifteen minutes
Run this against a staging copy of the registered domain, not a local file, so the embed script loads as visitors will see it.
Keyboard-only pass
- Navigate with Tab only to the element that opens the popup. Activate it with Enter or Space.
- Confirm focus lands on the close button (or your chosen entry point) and that a visible focus ring is present.
- Press Tab repeatedly through the popup, then Shift+Tab backwards. Focus must loop inside the dialog and never reach the page behind it.
- Press Escape. The popup closes and focus returns to the opener.
- Reopen, activate the close button with Enter, then again with Space. Both close the popup and return focus.
- Click outside, if enabled, and confirm the same return.
Screen reader pass
- Read the dialog on open. Confirm a dialog role and title, then the close control announced with your chosen name, not "button".
- Confirm nothing behind the dialog is reachable while it is open.
- Confirm the icon's internal paths are not announced.
Zoom and reflow
- Zoom the browser to 200%. Confirm the close button is still visible without horizontal scrolling and its hit area does not overlap the headline or the form.
Performance check
- In DevTools, open the Performance panel and record before and after installing the embed on the page.
- Note LCP and CLS in the live metrics view. Ideally compare against field data, which web.dev recommends over lab-only numbers for judging real user experience (web.dev: Optimize LCP).
- Throttle to a slow connection and reload. Watch whether the popup grows after paint and whether the close button moves.
Record pass or fail per step. A checklist with evidence beats a memory of "it worked when I tried it".
What to fix first when a step fails
- Announced as "button": add
aria-labelto the button element, hide the SVG. - Tab skips the close button: it is likely outside the dialog container, or has
tabindex="-1"applied by mistake, or the popup is not trapping focus at all. - Focus lost after close: no opener reference is stored, or the close handler removes the trigger from the DOM. Capture and restore deliberately.
- Close button moves after load: the wrapper has no reserved height, or the header row is content-sized.
- Escape does nothing: a keydown handler is calling
preventDefault()on the document without a close path, or the popup is a non-modal panel that does not dismiss on Escape by default.
Ship the close control before you ship the campaign
A lead-capture popup can carry a good offer and still lose the visitor at the one control they need. Name the button, put it first in focus order, make Escape and outside-click return focus to the opener, and reserve the space so a slow embed never slides the icon away from the pointer. Run the script above once on staging and keep the results with the campaign notes.
When you are ready to configure the popup itself, set it up in WidgetJar's popup widget, confirm the trigger and layout, then install the embed script on your registered domain and re-run the keyboard, screen reader and CLS checks against the live page.