Keyboard Focus Trap & Tab Order Simulator
Visualize keyboard tab order, inspect focusable elements, and test modal focus-trap behavior from pasted HTML.
Simulator
Results
Simulated focus
Tab order
Introduction
Keyboard accessibility depends on a predictable focus order. Menus, dialogs, forms,
and custom widgets can easily break tab order when they misuse
tabindex or fail to trap focus correctly.
This tool helps you inspect the focusable elements in a block of HTML and simulate the approximate tab sequence before testing in a live environment.
How it works
The tool parses pasted HTML inside an inert template element. It then
finds focusable elements, filters out disabled and hidden controls, and sorts the
approximate tab order based on tabindex and DOM order.
- Scripts in pasted HTML are not executed.
- Dangerous elements such as
scriptandiframeare removed. - Positive
tabindexvalues are sorted before natural order. - Negative
tabindexvalues are excluded from tab order.
How to use
- Paste HTML.
- Optionally enter a container selector for a modal or dialog.
- Click Audit HTML.
- Review messages and the generated tab order.
- Use Next Tab and Previous Tab to simulate keyboard focus.
- Copy the report or focus-trap snippet.
Practical example
A dialog should usually contain at least one tabbable element, trap Tab and Shift+Tab, and return focus to the trigger when closed. This tool can help you check whether the dialog markup contains focusable controls and whether the tab order looks reasonable.
Use cases
- Reviewing modal markup before implementing JavaScript.
- Finding accidental positive
tabindexvalues. - Checking whether custom controls are keyboard reachable.
- Debugging focus order in forms and navigation menus.
- Preparing accessibility test notes.
Best practices
- Prefer native interactive elements over focusable divs.
- Avoid positive
tabindexvalues. - Use
tabindex="-1"only for programmatic focus. - Trap focus inside modal dialogs while they are open.
- Return focus to the opening element when a dialog closes.
Common mistakes
- Adding
tabindex="0"to static text without keyboard behavior. - Using positive
tabindexto reorder focus. - Leaving background content tabbable while a modal is open.
- Making an element focusable without an accessible role or label.
- Forgetting to test Shift+Tab.
Limitations
- The simulator uses static HTML and cannot fully evaluate rendered CSS visibility.
- JavaScript-driven focus changes are not simulated.
- Shadow DOM content is not analyzed.
- Real focus behavior should always be verified with a keyboard.
Browser compatibility
The tool itself works in current versions of major browsers. The keyboard patterns it checks are based on widely supported HTML and ARIA behavior.
FAQ
Is my HTML uploaded?
No. The HTML is parsed and analyzed locally in your browser.
Does it execute scripts from pasted HTML?
No. Pasted HTML is placed into an inert template and dangerous elements are removed.
Is positive tabindex always wrong?
It can be valid in rare cases, but it often creates unpredictable keyboard order.
Most interfaces should rely on natural DOM order and tabindex="0".
Does this prove my modal is accessible?
No. It helps identify common issues, but modal accessibility also requires live focus management, Escape handling, labeling, and focus restoration.