nav

Navigation sections containing links to other pages or parts of the page. Used for primary navigation, table of contents, breadcrumbs, and pagination.

Usage

Use the <nav> element for:

  • Primary site navigation in the header
  • Secondary navigation in sidebars or footers
  • Breadcrumb navigation
  • Table of contents
  • Pagination links
  • Hierarchical tree navigation for documentation or file browsers

Not all groups of links need to be in a nav element. Reserve nav for major navigation blocks. Use aria-label or aria-labelledby to distinguish multiple nav elements.

Examples

Default

Basic nav with styled list and links.

.horizontal

Horizontal layout for header navigation.

.vertical

Explicit vertical layout for sidebar navigation.

.pills

Pill-shaped links with rounded backgrounds.

.tabs

Tab-style navigation with bottom border indicators.

.breadcrumb

Breadcrumb navigation with separator characters. Use <ol> for proper semantics.

.breadcrumb separators

Use data-separator to change the separator character.

.breadcrumb collapsed

Use data-collapsed to hide middle items for deep hierarchies.

.bottom

Sticky bottom tab bar for mobile navigation. Stacks icon and label vertically in each link.

.minimal

Subtle, minimal link styling.

.pagination

Page navigation for multi-page content.

.pagination variants

Ellipsis, simple (prev/next only), and compact (connected buttons) variants.

.tree

Hierarchical tree navigation using <details> and <summary> for collapsible sections. Uses +/- indicators for expand/collapse state.

.tree nested

Tree navigation supports multiple nesting levels for deep hierarchies.

.tree compact

Use data-density="compact" for tighter spacing in dense navigation.

Variants

Layout Variants

Class Description
.horizontal Flexbox row layout with wrapping
.vertical Flexbox column layout (default behavior)

Style Variants

Class Description
.pills Fully rounded links with hover/active backgrounds
.tabs Bottom border indicators with underline on current page
.breadcrumb Horizontal list with separators; supports data-separator, data-collapsed, data-truncated
.minimal Subtle muted links with minimal padding
.pagination Page navigation with prev/next controls; supports data-variant, data-size
.tree Hierarchical tree navigation using <details>/<summary>; supports data-density
.bottom Sticky bottom tab bar for mobile; flex row with icon+label stacking and safe-area padding

Breadcrumb Attributes

Attribute Values Description
data-separator chevron, arrow, dot, pipe Changes the separator character (default is "/")
data-collapsed boolean Hides middle items, shows only first, "...", and last two
data-truncated on item Truncates long labels with ellipsis (max 10rem)

Pagination Attributes

Attribute Values Description
data-variant simple, compact Display variant: simple shows only prev/next, compact connects buttons
data-size sm, lg Size variant (default is medium)
data-prev on link Marks the "previous" link
data-next on link Marks the "next" link
data-ellipsis on span Marks ellipsis placeholder (non-interactive)
data-info on span Page info text (e.g., "Page 3 of 10")

Tree Attributes

Attribute Values Description
data-density compact Reduces spacing for dense navigation
open on <details> Expands section by default

Accessibility

  • Nav creates a navigation landmark for screen reader navigation
  • Use aria-label to distinguish multiple nav elements (e.g., "Main navigation", "Footer navigation")
  • Use aria-current="page" on the link to the current page
  • Breadcrumbs should use <ol> for ordered sequence semantics
  • Ensure sufficient color contrast for link text and focus states
  • Links should have visible focus indicators
  • Tree navigation uses native <details>/<summary> which are keyboard accessible and announce expand/collapse state

Related

  • <header> - Primary nav typically lives in site headers
  • <footer> - Secondary nav often appears in footers
  • <aside> - Sidebar nav can be placed in asides
  • <main> - Nav should be outside main content area