A lightweight, accessible JavaScript utility that enables keyboard-only navigation across headings, links, and landmarks on any webpage β even as content changes dynamically.
This utility simulates real-world keyboard navigation for users who rely on keyboard interaction (e.g., screen reader users, power users, and individuals with motor impairments). It ensures a seamless and accessible navigation experience without requiring any modifications to the existing HTML.
-
π Automatically scans the DOM for:
- Headings (
<h1>β<h6>) - Anchor links (
<a href="...">) - Landmarks (
<nav>,<main>,<form>,<section>, etc. and valid ARIA roles)
- Headings (
-
π― Keyboard shortcuts:
Hβ Jump to next/previous HeadingLβ Jump to next/previous LinkMβ Jump to next/previous Landmark
-
π Directional navigation:
ββ Set navigation backwardββ Set navigation forward
-
β»οΈ Dynamic DOM support:
- Updates in real time when elements are added or removed
-
ποΈ Accessibility highlighting:
- High-contrast focus style (yellow outline, black background)
-
β Works in latest versions of Chrome, Firefox, and Edge
-
π¦ No dependencies. Just one function:
initKeyboardNav();
- Keyboard Focus: Ensures all navigated elements receive programmatic focus.
- Visual Indicator: Provides high-contrast outline and background.
- ARIA Support: Detects valid landmark roles (e.g., role="main", role="nav").
- Skip Input Fields: Prevents hotkeys from interfering with typing.
- All elements to be navigated are visible and part of the DOM.
- Input fields (like , <textarea>) suppress shortcut behavior.
- Landmarks are defined using either semantic tags or role attributes.
- Include
navigationAZ.jsin your page. - Call the function once:
<script>
initKeyboardNav();
</script>keyboard-navigation-utility/
β
βββ navigationAZ.js # Main standalone JavaScript utility
βββ demo.html # Sample page with headings, links, landmarks
βββ README.md # Documentation