Skip to content
TopClass UI

Breadcrumb

Where a page sits in the site, as real links with no JavaScript. The same trail is written as BreadcrumbList JSON-LD.

server - 0 KB

Breadcrumb

server - 0 KB

Where a page sits in the site, as real links with no JavaScript. The same trail is written as BreadcrumbList JSON-LD.

Install

The code

breadcrumb.tsx
import { Breadcrumb } from 'topclassui/breadcrumb'

/** The last item has no href: it is the page being read, and it stays out of the JSON-LD. */
export default function Demo() {
  return (
    <Breadcrumb
      items={[
        { href: '/', label: 'Home' },
        { href: '/docs', label: 'Docs' },
        { label: 'Breadcrumb' },
      ]}
    />
  )
}

Leave href off the last item: it becomes the current page, and the linked items also emit the BreadcrumbList JSON-LD.

Every state

3 states

Import from the package

topclassui/breadcrumb
import { Breadcrumb } from 'topclassui/breadcrumb'

Install once:npm i topclassui@beta zod

Examples

  • items is the trail as { href?, label }, root first. With an href on the last item too, it is one more link and no page is marked current.
  • In Next.js a plain link reloads the page. Pass link={<Link href="" />} and each crumb is a client navigation; its href is replaced with the item's.
  • Pass baseUrl="https://example.com" and the JSON-LD lists absolute URLs. The links stay as written.
  • A crumb with an empty label, or one that is not a string, is left out of the trail and of the JSON-LD.
  • A crumb without an href that is not the last one is plain text: no link, and no entry in the JSON-LD.
  • A long label ends in an ellipsis at the width of its box and is cut at 200 characters. The JSON-LD keeps the whole label.
basic
all-links
long-trail
long-label
mixed-label
deep-trail
In Arabic, right to left

Props

The props of Breadcrumb
PropTypeDefaultLimitsDescription
items*readonly BreadcrumbItem[]--The trail as { href?, label }, root first. An item with an href is a link and joins the JSON-LD; the last one without is the current page.
baseUrlstring--The address of the site, such as https://example.com: the JSON-LD then lists absolute URLs. The links stay as written.
labelsLabels--The built-in strings; the nav is named by labels.breadcrumb.label. Defaults to English.
linkReactElement--The element every crumb link is cloned from, such as link={<Link href="" />}; its href is replaced with the item's.
localestring--Accepted so {...getLabels(locale)} spreads cleanly. Nothing here formats a number, so it is not used and never reaches the element.

Keyboard and accessibility

The keyboard of Breadcrumb
KeysWhat it does
TabMoves to the next crumb link. The current page is text, not a tab stop.
EnterFollows the focused link.
  • The trail is an ordered list inside a nav named "Breadcrumb" from labels.breadcrumb.label. aria-label renames it; an empty one falls back to the built-in name.
  • The last crumb carries aria-current="page" and a heavier weight, so colour is not the only cue.
  • The carets between crumbs are decorative and hidden from a screen reader.

Right to left

Under dir="rtl" the trail runs from the right and each caret flips to point along it. labels={getLabels('ar').labels} names the nav in Arabic.

Server and client

Renders on the server and ships no JavaScript.

Files: index.tsx.

On the chip: server - 0 KB.