Skip to
Keyboard shortcuts

Use the up and down arrow keys to move between items. Press Alt+Shift+K to open this list again.

Alpha version out now. The API may still change.

SkipLink

A link that is the first stop when you press Tab, so keyboard and screen reader users can jump past the header to the main content. Activating it moves focus to the main content, so people using a keyboard don’t have to tab through the header on every page. The default theme keeps it out of sight until it has focus, so the page looks the same to people who use a mouse.

Package
@kvirn-ui/react
Testing
Automated. Core 0 of 2, Release 0 of 3

When to use it#

  • Use one on every page that has a header or a menu before the main content. People who use a keyboard can then jump past it, instead of pressing Tab through it on every page.
  • Put it first in the page, before the header and any other link. Keep it in the page flow: don’t put it in a fixed bar that covers other content (2.4.11 Focus Not Obscured (Minimum), AA).
  • Give the main content an id, such as <main id="main">, and set the link’s href to #main. A # address points to an element on the same page.
  • Not for a link to another page: use a Link. Not for text that only screen readers (software that reads the screen aloud) should get: use VisuallyHidden.

Example#

Press Tab until the link appears here, then Enter to jump.

Skip to main content

Site header with a menu and a search field

Use cases#

A link to something other than the main content

A long page may have a block that people want to reach directly, such as the application form. Write the label yourself so it says where the link goes.

Press Tab until the link appears here, then Enter to jump.

Skip to the application form

Site header with a menu and a search field

Props in this example:

Warning: Don't forget

A label of your own is not translated for you. When it is in another language than the page, mark the language so screen readers pronounce it correctly (3.1.2 Language of Parts, level AA). See What you need to do.

Some pages have two things people look for first. Give each its own link, one after the other at the top: the main content first, then the search. Each link points to a target with its own id.

Press Tab to show the first link, and Tab again to show the second.

Skip to main contentSkip to search

Site header with a menu and a search field

Props in this example:

Your project already has a link component with its own class or markup. Pass it with as. SkipLink gives it the other props, the ref (a way to reach the underlying element) and the kv-skip-link class, so the link still hides until it has focus.

Press Tab until the link appears here, then Enter to jump.

Skip to main content

Site header with a menu and a search field

Props in this example:

  • as on SkipLink
  • href on SkipLink

Information: Did you know?

Your component must render an <a href> and pass on its ref. Don’t use Link.Root here: a same-page address is not a route.

Your own link element

You need markup the component doesn’t give you. Spread the props from the hook on your own link and use the label from the hook. If you only want your design system’s link, use as, as in the case above.

Press Tab until the link appears here, then Enter to jump.

Skip to main content

Site header with a menu and a search field

Props in this example:

Information: Did you know?

Put the whole of skipLinkProps on a native <a>. It carries the class, the address and the click handler that moves focus to the target (2.4.1 Bypass Blocks, A).

Accessibility#

What it does for you#

  • APG pattern: none. WCAG technique G1 (a link at the top to skip to the main content) with C7 (hide it until it has focus).
  • Deviations: none. Activating the link moves focus to the target. That is what the link is for.
  • Native elements used: <a href="#id">, never Link.Root: a hash on the same page is not a route.

SkipLink is a native link with a class. It is the first Tab stop in the body, hidden until it has focus, and it moves focus to the main content.

PartElement / roleARIANotes
SkipLink<a href> → linknoneclass="kv-skip-link". The name is the rendered text, the message skipLink.label or your children: text and not aria-label, so it is translated and found. href is required and is a same-page #id
Targetthe consumer's elementnoneNot focusable by itself: the link adds tabindex="-1" on activation and removes it when focus leaves. A target that is already focusable (tabindex 0 or -1, a control) is left alone
SkipLinkasthe component's ownA component that renders an <a href> and forwards its ref. It gets the other props, the ref and the part's class (className joins, handlers chain, refs merge)

It announces nothing.

What you need to do#

  • Put it first in the body, before the header and any other link, and give the main content the id (<main id="main">).
  • A missing target warns in development: the warning names the missing id.
  • Language. A custom label is your own text. When it is in another language than the page, mark it: put it in a nested KvirnProvider and spread useLocale().localeProps on your own element (3.1.2 Language of Parts, AA).
  • Do not hide the target's focus ring. The default theme draws the focus ring on the target, only when focus came from the keyboard (:focus-visible): don't set outline: none on [tabindex="-1"].
  • Do not put it in a sticky layer that covers other content (2.4.11 Focus Not Obscured (Minimum), AA): it stays in the flow.

Warning: Don't forget

Put the link first in the page and give the main content the id it points to. If the id is missing, the link goes nowhere and people using a keyboard still have to tab through the whole header (2.4.1 Bypass Blocks, level A). A development warning tells you when the id is missing.

Visual and modes#

Headless: no CSS. With the default theme the link is hidden visually, but not removed from the page, until it has focus. Nothing is hidden with display: none, which would also remove it from the Tab order. When it has focus it appears in the normal flow of the page, with:

  • link-coloured text that has enough contrast on the page background (1.4.3 Contrast (Minimum), AA), measured by an automated contrast check;
  • an underline, so colour is not the only cue (1.4.1 Use of Color, A);
  • a focus ring with at least 3:1 contrast (2.4.7 Focus Visible, AA);
  • space around it and a target of at least 24 by 24 CSS pixels (2.5.8 Target Size (Minimum), AA).

It reflows with the page (1.4.10 Reflow, AA): the reflow sweep checks every story at 320 CSS pixels for horizontal overflow. In forced colours (a Windows contrast mode) it uses the system's link and background colours and a highlight-coloured ring, with no reliance on a background fill. If you restyle it, keep the contrast, the underline, the ring and the target size.

Focus management#

  • Initial focus: not moved. The link is a Tab stop and nothing else.
  • On activation: focus moves to the target element. The click handler does not call preventDefault, so the browser still makes its own jump to the target. A test shows the browser's own jump is not cancelled.
  • A target made focusable has tabindex="-1" until it loses focus. A target already focusable is left alone, and so is one with its own tabindex="-1".
  • Trap: no. Restore to: not applicable.

Warning: Don't forget

Keep the focus ring on the target. When the target can’t take focus yet, the link adds tabindex="-1" to it so focus can move there. If your styles remove the outline from such elements, someone using a keyboard can’t see where the link took them (2.4.7 Focus Visible, level AA).

WCAG success criteria#

  • 2.4.1 Bypass Blocks (A): the link jumps to the main content.
  • 2.4.3 Focus Order (A): first stop; the next Tab continues in the target.
  • 2.4.7 Focus Visible (AA), 2.4.11 Focus Not Obscured (Minimum) (AA): visible and in the page flow while focused (a story with the default theme loaded).
  • 1.4.1 Use of Color (A): the link is underlined, so colour is not the only cue (a theme property, not a test).
  • 3.1.2 Language of Parts (AA): a custom label in another language is marked by the consumer (see Consumer responsibilities).
  • 2.5.8 Target Size (Minimum) (AA), 1.4.10 Reflow (AA), 1.4.3 Contrast (Minimum) (AA) and 1.4.11 Non-text Contrast (AA): the default theme; the contrast is measured by an automated check.
  • 4.1.2 Name, Role, Value (A): link named by its text, and axe finds no violation.

Keyboard#

Focus
native
Selection follows focus
n/a
Arrows wrap
n/a
Shortcuts
none

Native tab order. No key is intercepted.

KeyWhereWhat happens
Tabpage load or startFocuses the skip link. It becomes visible at the top of the page
Test: skip-link.test.tsx › SkipLink keyboard › the first Tab stop is the skip link
Tabon the skip linkMoves to the next focusable element, and the skip link hides again
Test: skip-link.test.tsx › SkipLink keyboard › Tab leaves the skip link for the next stop
Shift+Tabon the skip linkLeaves the page content backwards (browser UI)
Test: skip-link.test.tsx › SkipLink keyboard › Shift+Tab from the skip link leaves the document
Enteron the skip linkFocuses the target (tabindex="-1" added if it was not focusable); the next Tab continues in it
Test: skip-link.test.tsx › SkipLink keyboard › Enter moves focus to the target and the next Tab continues after it
Spaceon the skip linkNot handled (a link; the page scrolls natively)
Test: skip-link.test.tsx › SkipLink keyboard › Space is not handled

A story with the default theme loaded proves the visible state: hidden before Tab, shown in the page flow while focused, hidden after Tab.

API reference#

import { SkipLink, useSkipLink } from '@kvirn-ui/react'

Renders <a href> with the role link. It takes every attribute of an <a> and passes ref to it. The default theme is described on Theming.

PropTypeDefaultDescription
hrefstringRequiredA same-page address, "#main": the id of the main content. A development warning says so when no element has the id.
childrenReactNodethe message skipLink.labelYour own label. It replaces the message, so you set its language: mark it if it differs from the page.
messagesPartial<KvirnMessages['skipLink']>–Overrides the message for this link: { label: "Jump to the content" }.
asElementType'a'Changes the element to a component of your own, such as your design system’s link. It must render an <a href> and forward its ref, and it gets the other props, the ref and the part’s class. Don’t use Link.Root: a same-page address is not a route.
Class or attributeValuesMeaning
kv-skip-linkalwaysThe part class. The default theme hides the link until it has focus.

Options

PropTypeDefaultDescription
hrefstringRequiredA same-page address, "#main": the id of the element the link jumps to.
messagesPartial<KvirnMessages['skipLink']>–Overrides the message skipLink.label for this link.

Result

PropTypeDefaultDescription
skipLinkPropsSkipLinkPartProps–Spread on an <a>: class, href and a click handler that moves focus to the target.
labelstring–The message skipLink.label: the default text of the link.

Strings

These are the default texts in @kvirn-ui/i18n.

For your whole app, pass messages to KvirnProvider. For one SkipLink, pass its messages prop.

skipLink.label

The link’s visible text, when you give no children. It says where the link goes.

LanguageDefault text
SvenskaHoppa till huvudinnehållet
SuomiSiirry pääsisältöön
Norsk bokmålGå til hovedinnhold
Norsk nynorskGå til hovudinnhald
EnglishSkip to main content

Known issues#

  • If you override the label, have a native speaker check it.
  • Safari (WebKit): whether the focus ring shows on the target after someone presses Enter on the link is not covered by an automated test, so check it in your own service. In Safari, Tab only reaches links when "Press Tab to highlight each item" is on (or with Option+Tab), so test with that setting on. Don't hide the ring on [tabindex="-1"].

Testing#

The automated tests prove the keyboard behaviour, the names and states, that axe finds no violations in every story and theme, and, for the components they cover, that the stories hold up in forced colours, reduced motion, text spacing and a 320 pixel width. An Automated row passes on these tests alone. A Core or Release row passes only when an automated agent check and a person on the real assistive technology have both checked it. "agent-verified" means automated tests in the repository (with a virtual screen reader for the screen reader rows), not the real assistive technology.

AT + browser + OSAgent checkHuman checkResultNotes
Automated (re-runnable tests)
axe, WCAG 2.2 A and AA, every story, 4 themespassn/apassskip-link.stories.tsx, every story, 4 themes
Markup and ARIA (roles, names, ids, states)passn/apassskip-link.test.tsx › the name is the default label, rendered as text with no ARIA added; expectNoA11yViolations
Keyboard contract rows (Vitest browser)passn/apass5 rows, each names a test (skip-link.test.tsx › SkipLink keyboard › the first Tab stop is the skip link)
Focus order and managementpassn/apassskip-link.test.tsx asserts focus (document.activeElement); first rule: SkipLink keyboard › the first Tab stop is the skip link
Display modes (forced colours, 320px reflow, text spacing, reduced motion)passn/apassthe four sweep projects (storybook-forced-colors, -reduced-motion, -reflow, -text-spacing), run in CI
Core (required for beta)
NVDA + Chrome + Windowspendingpendingpending
VoiceOver + Safari + iOSpendingpendingpending
Release (before 1.0 and each minor)
JAWS + Chrome + Windowspendingpendingpending
TalkBack + Chrome + Androidpendingpendingpending
VoiceOver + Safari + macOSpendingpendingpending

What to check#

  • Tab once on a fresh page: the link appears and its name is read.
  • Press Enter: focus lands in the main content, and the next Tab continues after the link, not in the header.
  • Tab without Enter: the link hides.
  • At 400% zoom the focused link is visible and uncovered.
  • In Safari, turn on "Press Tab to highlight each item" first, then repeat the first two steps.