On this page
What this issue is
A modal is a popup layer such as a lead form, a booking window, a cookie panel or an offer. Focus is the element that currently receives keyboard input. You can see it as the outline around a link or field when you press Tab.
This issue has two halves. On open, focus stays on the trigger button, or on the page underneath, instead of moving into the modal. On close, focus is not sent back to the trigger, so it resets to the top of the document or disappears. Both relate to WCAG 2.2 success criteria such as 2.4.3 Focus Order and 4.1.2 Name, Role, Value.
Why it costs you leads or sales
People who use a keyboard, a switch device or a screen reader cannot reach your form if focus stays behind the popup. They may press Tab many times through hidden page content before reaching the modal, or never reach it. A screen reader may not announce that a dialog opened, so the user does not know it exists.
On close, losing focus sends them back to the top of the page. They must tab through the header and menu again to find where they were. In a checkout or booking flow, many will give up.
- Land on pageTabs to the Get a quote button
- Press EnterModal opens visually
- Focus stays behindNext Tab goes to page links, not the form
- Fill in formCannot reach the fields
- Lead submittedNever happens
Focus stays behind the modal, so the form is never reached.
Example: illustrative numbers only, not measured data. Completion among keyboard-only visitors before and after fixing focus handling.
How to check if your site has it
You can test this in two minutes with only your keyboard. Do it on every modal that matters: lead forms, booking popups, quick-view windows, cart drawers and consent panels.
Tab to the trigger
Press Tab until the button that opens the modal has a visible outline. Note which button it is.
Open it with Enter or Space
Do not use the mouse. The modal should appear.
Check where focus went
Focus should now be on the modal itself, its heading, or its first field or close button. If the outline is still on the trigger or has vanished, focus did not move in.
Press Tab a few times
Focus should cycle through elements inside the modal only. If it goes to page links behind it, the modal does not manage focus.
Close with Escape
Press Escape, or activate the close button. Focus should return to the original trigger button.
Repeat with a screen reader
Use NVDA or VoiceOver. On open it should announce the dialog and its name, for example the heading text.
For a faster check, open the browser console and run document.activeElement after the modal opens. It should return an element inside the modal.
console.log(document.activeElement);
console.log(document.activeElement.closest('[role="dialog"], dialog'));How to fix it
The most reliable fix is the native HTML <dialog> element opened with showModal(). The browser moves focus into the dialog, keeps Tab inside it, closes it on Escape and returns focus to the element that was focused before. If you need a custom modal, do those jobs yourself.
<button id="open-quote">Get a quote</button>
<dialog id="quote-dialog" aria-labelledby="quote-title">
<h2 id="quote-title">Get a quote</h2>
<form method="dialog">
<label for="q-email">Email</label>
<input id="q-email" type="email" autocomplete="email">
<button type="submit">Send</button>
<button type="button" id="close-quote">Close</button>
</form>
</dialog>
<script>
const dlg = document.getElementById('quote-dialog');
document.getElementById('open-quote').addEventListener('click', () => dlg.showModal());
document.getElementById('close-quote').addEventListener('click', () => dlg.close());
</script>let lastTrigger = null;
const modal = document.getElementById('my-modal'); // has role="dialog" aria-modal="true" aria-labelledby="..." tabindex="-1"
function openModal(trigger) {
lastTrigger = trigger;
modal.hidden = false;
const first = modal.querySelector('input, select, textarea, button, a[href]');
(first || modal).focus();
}
function closeModal() {
modal.hidden = true;
if (lastTrigger) lastTrigger.focus();
}
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape' && !modal.hidden) closeModal();
});Identify the popup source
Check whether the modal comes from your theme, a page builder (Elementor, Divi) or a popup plugin. Open the plugin's popup settings and look for accessibility or focus options.
Update and test
Update the plugin and theme, then repeat the keyboard test. If focus still does not move, switch to a plugin that supports focus management or replace the popup with a
<dialog>in a Custom HTML block.
Check the theme
Current Online Store 2.0 themes usually manage focus in cart drawers and quick-view modals. Update the theme to the latest version first.
Check app popups
If the failing modal comes from an app, test it with the app's settings and report the issue to the app developer. As a fallback, edit your theme's JavaScript (in Edit code) so the opening function focuses the first field and the close function focuses the trigger.
Find injected popups
If a Custom HTML tag injects the popup, add the focus code to that tag's script: focus the first field after inserting it, and focus the trigger or previously active element on close.
Save the active element first
Store
document.activeElementbefore opening, so you can call.focus()on it when closing.
Use custom code for focus
Modals built with interactions do not manage focus by themselves. Add a custom code embed with a script that focuses the first field on open and the trigger on close.
Set roles and labels
In the element settings, add custom attributes
role=dialog,aria-modal=trueandaria-labelledbypointing to the heading id.
Test the popup
Funnel and website popups are generated by the builder. Run the keyboard test on the published page.
Add a custom script if needed
If focus is not handled, add a script in the page's custom code section that focuses the popup's first field when it appears and returns focus to the trigger when it closes. Contact support if the popup does not expose a trigger you can target.
Use Wix lightboxes
Wix lightboxes provide built-in keyboard handling in most cases. Prefer them to custom HTML popups.
Test in a published page
Publish and run the keyboard test. If a Velo-built modal fails, add
focus()calls in your open and close handlers.
Check built-in popups
Test the Promotional Pop-up and lightbox blocks with the keyboard test on the live site.
Use Code Injection for fixes
If focus is not handled, add a script in Settings, Advanced, Code Injection that focuses the first field on open and returns focus to the trigger on close.
Switch to
<dialog>Replace div-based modals with
<dialog>andshowModal(). Browsers then handle focus, Escape and the background for you.Or follow the dialog pattern
For custom markup, use
role=dialog,aria-modal=trueand a label, move focus on open, return it on close, and make the backgroundinert.
Before
- Focus stays on the trigger button when the modal opens
- Tab moves through the page behind the popup
- Screen reader does not announce a dialog
- After closing, focus resets to the top of the page
After
- Focus moves to the first field or the modal heading
- Tab cycles only through modal controls
- Screen reader announces the dialog name
- After closing, focus returns to the trigger button
How to confirm it's fixed
- Open the modal with Enter or Space: focus lands inside it
- Tab and Shift+Tab stay within the modal
- Escape closes the modal
- Focus returns to the exact button that opened it
- A screen reader announces the dialog and its name on open
- The test passes on mobile with an external keyboard or screen reader
- Every modal on the site has been tested, not just one
How to prevent it happening again
Modals get broken by theme updates, new popup plugins and marketing tools that add their own overlays. Build a short habit around it.
- Use native
<dialog>for new modals - Add the keyboard test to your release checklist for any page with a popup
- Retest after theme, plugin or popup tool updates
- Run an automated accessibility scanner plus a manual keyboard pass before launching campaigns
- Ask popup vendors whether their widget manages focus before buying
How FunnelGuard handles this
This issue is outside what FunnelGuard checks. FunnelGuard runs your customer journeys with a robot visitor and checks steps, tracking hits and test lead delivery. It does not judge keyboard focus behaviour or screen reader output. The kind of tool that fits is an accessibility testing tool: a browser-based accessibility checker for quick scans, combined with manual testing using only a keyboard and a screen reader such as NVDA or VoiceOver.
What FunnelGuard can help with is the neighbouring risk: whether your lead form, checkout or booking journey still completes on a schedule, and whether the lead reaches your inbox. You can start with the Free plan (1 site, 2 journeys, daily checks, no card) or a free read-only website audit.
Questions people ask
Why is focus not moving into my modal when it opens?
Most often the modal is shown by toggling a CSS class and nothing calls focus(). Focus therefore stays on the trigger button. Call focus() on the first field, the heading (with tabindex="-1") or the modal container after it appears, or use <dialog> with showModal().
How do I return focus to the button after closing a modal?
Save the trigger before opening, for example lastTrigger = document.activeElement. In your close function, hide the modal and call lastTrigger.focus(). A native <dialog> opened with showModal() does this automatically.
Where should focus go when a modal opens?
Move it to the first interactive element, usually the first form field, or to the modal heading or container if there is introductory text a user should hear first. For a destructive confirmation, focus the least risky button. Avoid leaving it on the page behind.
Does the HTML dialog element handle focus automatically?
Yes, when opened with showModal(). The browser moves focus into the dialog, keeps it there, makes the rest of the page inert, closes on Escape and restores focus to the previously focused element. Dialogs opened with show() do not make the page inert.
Is aria-modal enough to fix modal focus?
No. aria-modal="true" tells assistive technology the content behind is inactive, but it does not move focus or stop keyboard users tabbing out in every browser. You still need to manage focus with script or use <dialog>.
What is the difference between a focus trap and missing focus management?
A keyboard trap means users cannot leave the modal. Missing focus management means focus never enters the modal or does not return after it closes. A good modal keeps Tab inside while open but always allows Escape or a close button.
Can I test modal focus without a screen reader?
Yes. Use only your keyboard: Tab to the trigger, press Enter, check the focus outline is inside the modal, Tab around, press Escape, and check focus returns to the trigger. Adding a screen reader then confirms the dialog is announced.
Can FunnelGuard detect modal focus problems?
No. This is outside what FunnelGuard checks. Use an accessibility testing tool plus manual keyboard and screen reader testing. FunnelGuard instead monitors whether your funnels, tracking and test leads still work.
Related issues
- PRF-312Keyboard trap in modal or widgetFix guide
- PRF-311Focus outline removed (outline:none)Fix guide
- PRF-313Form cannot be completed with keyboard onlyFix guide
- PRF-314Illogical focus orderFix guide
- PRF-316Focused element hidden behind sticky header (WCAG 2.4.11)Fix guide
- PRF-324Icon-only buttons without accessible namesFix guide