Skip Nav
A link, hidden until focused, that lets keyboard users jump past the navigation to the main content.
Navigation
This stands in for a navigation area that people may want to skip.
Usage
WebAIM.org on WCAG 2.4.1 (Bypass Blocks - Level A) strongly recommends a skip link past content that repeats on many pages.
Headings and the
mainregion let screen reader users skip content. That is not enough for sighted keyboard users.
import { SkipNavContent, SkipNavLink } from '@leverui/components';
<SkipNavLink>Skip to content</SkipNavLink>
<SkipNavContent />
Examples
Basic Usage
The SkipNavLink component ideally needs to be one of the first items a user encounters when they begin navigating a page after load. Therefore, it is recommended to place it as high as possible in the app.
It renders an a tag and automatically creates a link with an href attribute that will point to SkipNavContent.
The SkipNavContent component is used as a target for the link to place keyboard focus on the first piece of main content. It renders a div and can either be a self-closing component, or wrap the main content.
Navigation
This stands in for a navigation area that people may want to skip.
Custom ID
You can supply a custom id value using the id prop but you will have to use this prop and value in both components, or they will not match.
Header and navigation
Both parts in this example use the custom id "main-target" so that they match.
Main content (custom id)
SkipNavLink and SkipNavContent share the id "main-target". That is how the link finds its target and moves focus to it.
With Main Content
The SkipNavContent component can wrap your main content area to ensure proper focus management.
Site header
• Home
• About
• Services
• Contact
In Action
- Select Preview on the Basic Usage example.
- Press
Tabtwice. The link appears in the upper left of the window. - Press
Enterto move focus to the main content panel.
Guides
SkipNavContent marks where SkipNavLink jumps to. The link is hidden until
it has focus. Finish the stylesheet setup first.
Both parts use leverui-skip-nav as the target id by default. For another
target, give both parts the same id. On SkipNavLink, id sets the
fragment in the href. SkipNavContent has tabIndex={-1}: code can focus it,
Tab skips it. Keep the link near the start of the document. Give the target
the right meaning for the page, for example with as="main".
In your own layout, check that keyboard focus reaches the target after someone follows the link.
In a Solid Router app, set rel="external" on SkipNavLink. Otherwise the
router handles the hash link and the browser does not move focus.
Customize with CSS
.leverui-skip-nav styles the link and .leverui-skip-nav-content its target.
--leverui-colors-bg-panel sets the background of the focused link. unstyled
on the link turns off its default styles.
For one-off changes, use class or style. Neither part supports object CSS,
general style props, or custom recipes.