StealThis .dev

Breadcrumb Nav

Accessible breadcrumb navigation with structured data, truncation for deep paths, and home icon. Pure CSS + minimal JS.

Open in Lab
css vanilla-js
Targets: JS HTML

Code

An accessible breadcrumb navigation component with home icon, chevron separators, active state, and JSON-LD structured data injection for SEO.

Features

  • <nav aria-label="Breadcrumb"> with <ol> list structure
  • Home icon for the root crumb
  • SVG chevron separators via CSS ::after
  • Current page uses aria-current="page" and distinct style
  • Truncates deeply nested paths with ellipsis crumb on narrow screens
  • JS utility injects application/ld+json BreadcrumbList structured data

How it works

  1. Breadcrumb items are <li> elements inside an <ol> — separators provided by CSS ::after pseudo
  2. The JS generateSchema() function reads [data-href] attributes and injects a BreadcrumbList <script> tag
  3. On mobile, a ResizeObserver collapses middle crumbs into to keep the trail readable