From 7624ea2071261771fb45c919cf9a6240543bd9e1 Mon Sep 17 00:00:00 2001 From: wuyangfan <1102042793@qq.com> Date: Sun, 17 May 2026 16:07:25 +0800 Subject: [PATCH] fix(a11y): add skip link to main content Add a visually hidden "Skip to main content" link as the first focusable control. It targets the existing #mdbook-content landmark so keyboard users can bypass the sidebar and menu bar (WCAG 2.4.1). Fixes #2107 Co-authored-by: Cursor --- crates/mdbook-html/front-end/css/chrome.css | 16 ++++++++++++++++ crates/mdbook-html/front-end/templates/index.hbs | 7 ++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/crates/mdbook-html/front-end/css/chrome.css b/crates/mdbook-html/front-end/css/chrome.css index bab38894f4..bc50258db0 100644 --- a/crates/mdbook-html/front-end/css/chrome.css +++ b/crates/mdbook-html/front-end/css/chrome.css @@ -1,5 +1,21 @@ /* CSS for UI elements (a.k.a. chrome) */ +.skip-to-content { + position: absolute; + top: -100px; + left: 0; + padding: 0.5rem 1rem; + background-color: var(--bg); + color: var(--fg); + z-index: 1000; + text-decoration: none; + border: 2px solid var(--links); +} + +.skip-to-content:focus { + top: 0; +} + html { scrollbar-color: var(--scrollbar) transparent; } diff --git a/crates/mdbook-html/front-end/templates/index.hbs b/crates/mdbook-html/front-end/templates/index.hbs index b1834189f9..5526004a38 100644 --- a/crates/mdbook-html/front-end/templates/index.hbs +++ b/crates/mdbook-html/front-end/templates/index.hbs @@ -63,6 +63,7 @@ + Skip to main content

Keyboard shortcuts

@@ -143,9 +144,9 @@