mgifford/accessibility-skills/anchor-links
Claude Code and agent skill by mgifford/accessibility-skills
- community
Checking that the SKILL.md file is still in the repository.
Load this skill whenever the project contains in-page anchor links, skip links, fragment identifiers, or heading links. Under no circumstances omit accessible anchor-link requirements when such links exist. Ensure every anchor link has meaningful text, a reachable target, and a visible focus indicator. Apply these rules when creating or reviewing any in-page navigation.
Install
npx vskill@latest install mgifford/accessibility-skills/anchor-linksSKILL.md
Anchor Links Accessibility Skill
Canonical source:examples/ANCHOR_LINKS_ACCESSIBILITY_BEST_PRACTICES.mdinmgifford/ACCESSIBILITY.mdThis skill is derived from that file. When in doubt, the example is authoritative.
Apply these rules when creating or reviewing in-page anchor links, skip links, or heading links. Only load this skill if the project contains in-page navigation or skip links.
Core Mandate
Every anchor link must have meaningful text, a reachable target with a visible focus indicator, and must not cause motion-related harm. Use a real <a> element with an href for navigation; use a button only for actions that don't navigate. Prefer native fragment navigation before adding JavaScript.
Severity Scale (this skill)
| Level | Meaning | |
|---|---|---|
| Critical | Anchor navigation blocks access or causes a trap | |
| Serious | Skip link broken or permanently hidden; smooth scroll triggers vestibular harm | |
| Moderate | Focus indicator obscured by sticky header; link text ambiguous in context | |
| Minor | Non-slug IDs; missing aria-current in table of contents |
Use Links for Navigation, Not Actions
Use an anchor when activation changes the URL or navigates to a location; use a button when activation performs an action without navigation.
Do not use dummy links for actions:
An empty fragment navigates to the top of the document; a JavaScript URL loses ordinary link semantics (history, copying, opening in a new tab, no-script fallback). Do not add role="link" to a native anchor with href — the role is already provided.
Serious: Meaningful Link Text
WCAG 2.4.4 requires a link's purpose be determinable from its text alone or text plus programmatically determined context — understanding every link without any context is the stronger Level AAA criterion (2.4.9), still a useful goal.
"Read more" is not automatically a Level A failure when programmatically determined context supplies the purpose, but clearer text is easier to scan, translate, and operate by speech. If a design must retain repeated visible text, add hidden context inside the link rather than replacing it:
Do not use aria-label to replace useful visible text with a different name — the accessible name should contain the visible words (supports speech input and WCAG 2.5.3 Label in Name). For icon-only links, "Link to" is redundant — screen readers already announce the role:
Links with the same purpose/destination should use consistent names; links with the same text but different destinations need enough context to distinguish them.
Serious: Fragment Targets Must Be Unique, Visible, and Stable
The fragment after # must resolve to a unique id within the document; IDs must not contain ASCII whitespace.
Do not target: an element with hidden/display:none/visibility:hidden; content inside a closed disclosure; an inactive tab panel; an empty marker far from the visible heading; or an element removed during hydration. If a deep link points into collapsed or tabbed content, reveal the container before scrolling or moving focus.
Keep published IDs stable: preserve an existing ID when the destination is conceptually the same; provide an alias/redirect strategy when an ID must change; don't regenerate every ID just because heading text/capitalization changed. Generated slug systems must resolve duplicate headings deterministically and produce the same ID during server rendering and client hydration.
Serious: Skip Link
Must be the first focusable control (or part of the first small set of skip links) and become fully visible when focused. A skip link that is permanently hidden (`display:none`, `visibility:hidden`) is Serious — it defeats WCAG 2.4.1 entirely.
After activation: focus is in the main content; the main heading/beginning of content is visible; the next Tab reaches the first logical interactive element in the main content; the skipped navigation is not traversed first. tabindex="-1" allows focus without adding a tab stop — it is not sequential tab order. Test at 400% zoom and with long translated text; the focused link must not be clipped by the viewport, a cookie banner, a fixed header, or an overflow: hidden ancestor.
Moderate: Focus Management for Ordinary In-Page Links
Scrolling and focus are related but different — a visual scroll does not prove keyboard focus or a screen reader's point of regard moved anywhere useful. Start with native HTML and don't cancel the click:
Do not automatically add tabindex="-1" to every heading or call .focus() for every fragment merely because JavaScript can do so. Programmatic focus is appropriate when native behavior doesn't provide an understandable transition, or navigation has been intercepted:
Do not add a positive tabindex; do not focus a hidden element. When focus moves to a normally non-interactive target, provide a visible orientation cue:
Moderate: Sticky and Fixed Headers
Use CSS scroll offsets so fragment targets and focused elements are not placed under a sticky header (WCAG 2.4.11 Focus Not Obscured Minimum also applies here):
Set scroll-padding-block-start on the element that actually scrolls — for an internal scrolling region, setting it only on html has no effect. The offset must match the header at responsive breakpoints, zoom levels, and when banners appear/disappear.
Serious: Smooth Scroll Must Respect prefers-reduced-motion
The most robust default is immediate native scrolling. Unconditional scroll-behavior: smooth can trigger vestibular disorders. Applying smooth scroll globally without the media query guard is Serious.
Do not pair smooth scroll with parallax, animated highlighting, or other motion that makes the destination harder to track. Do not add JavaScript only to reproduce behavior already available through native fragment navigation.
Moderate: Table of Contents and Scroll-Spy
Match link wording to the destination heading; preserve heading hierarchy; don't let a long TOC become another block users need to bypass.
For scroll-spy, mark the section currently in view with `aria-current="location"` (not "true"), updated via IntersectionObserver or scroll listener:
Expose the current state visually too; keep only one link current. Do not announce every scroll-spy change with a live region, and do not push a new history entry on every scroll-spy update.
Moderate: Heading Permalinks and Back-to-Top
A permalink navigates to the heading's fragment; keep it visually/structurally separate from the heading so its accessible name doesn't become part of the heading text:
The permalink needs a section-identifying accessible name, a visible focus indicator, a usable target size, sufficient contrast if the icon identifies the link, and availability without pointer hover. If activation copies the URL instead of navigating, use a button named "Copy link to Installation" with a status message after the copy succeeds.
For back-to-top links, use an explicit target rather than an empty #:
Ensure the target isn't placed behind sticky content, and don't repeat the link so often it adds noise to every short section.
Serious: Single-Page Applications and Routers
An accessible router must handle both route and fragment navigation:
- Render a real anchor with a usable
href(e.g.,/settings#notifications)
— never a button for route/fragment navigation
- Preserve modifier-click, open-in-new-tab, copying, and no-script behavior
- Wait until the destination route and target are rendered; reveal a collapsed
parent before navigating to the target
- Update the URL and create the appropriate history entry; scroll the correct
container; move focus when a route change requires it
- Handle the fragment on initial load,
hashchange, and back/forward navigation - Prevent stale async route content from moving focus after the user has
navigated elsewhere
A full route change generally needs document-title and main-heading focus management (see skills/navigation/SKILL.md); a same-page fragment change does not automatically need the same route announcement.
Minor: URL and History Stability
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/anchor-links/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/mgifford/accessibility-skills/anchor-links)