Skip to the content

Controls and surfaces

skip-link

A link at the very start of the page, hidden until it has keyboard focus, that jumps past the header and navigation to the main content (WCAG 2.4.1).

Surfaces and navigation

When to use it

Every page with a header or navigation before its content: put it first inside <body>, and give the main content the id it points to. Several can go in a row (to the content, to the search).

See it working

The demonstration the browser checks drive, with the keyboard as well as the pointer. More of it is on the Surfaces and navigation page.

Alert dialog

kept

Hover card and collapsible

Drawn by the maps team.

Menubar

grid on

Navigation menu

Toolbar and button group

bold

100%

Resizable

Folders
Messages

30 / 70

Sidebar

The page beside the sidebar.

Skip link, hidden words and shortcuts

Skip to the heading

Press Shift+J anywhere on the page: 0

Add it

npx shadcn@latest add @rivier-ui/skip-link

The registry is named once in components.json: see Installation.

Example

Import it from @/components/ui/skip-link.

<SkipLink href="#main">Skip to content</SkipLink>
…
<main id="main" tabIndex={-1}>…</main>

What it needs

Plain markup: it can stay a server component. No packages beyond React.

It imports

Source

The whole file. Once copied it is yours: the registry item holds the same text.

src/components/ui/skip-link.tsx
/**
 * @name skip-link
 * @category ui
 * @description A link at the very start of the page, hidden until it has keyboard focus, that jumps past the header and navigation to the main content (WCAG 2.4.1).
 * @when Every page with a header or navigation before its content: put it first inside `<body>`, and give the main content the id it points to. Several can go in a row (to the content, to the search).
 * @example
 * <SkipLink href="#main">Skip to content</SkipLink>
 * …
 * <main id="main" tabIndex={-1}>…</main>
 */
import type { ComponentProps } from "react";
import { cn } from "@/lib/cn";
 
export function SkipLink({ className, ...props }: ComponentProps<"a">) {
  return (
    <a
      data-slot="skip-link"
      className={cn(
        "fixed start-2 top-2 z-[100] -translate-y-[200%] rounded-control border bg-background px-4 py-2 text-sm font-medium text-foreground transition-transform duration-instant ease-out focus:translate-y-0 motion-reduce:transition-none",
        className,
      )}
      {...props}
    />
  );
}