Dev.to WebDev 🛠 Dev 👁 2 📖 2 min read

Breadcrumbs Component Leveraging Aria

First, a brief timeline leading up to WAI-ARIA (Web Accessibility Initiative - Accessible Rich Internet Applications), often shortened to simply ARIA: Early HTML was mostly static. You went to a webpage, it displayed i

First, a brief timeline leading up to WAI-ARIA (Web Accessibility Initiative - Accessible Rich Internet Applications), often shortened to simply ARIA:

  1. Early HTML was mostly static. You went to a webpage, it displayed information, and there was very little interaction.
  2. Developers started using the <table> element to layout their websites and custom widgets like tabs and menus using <div> elements wasn't uncommon.
  3. It became painfully obvious that screen readers and keyboard-only users couldn't practically use websites.

In 2006, the W3C started building out ARIA standard and then after W3C picked up the HTML5 effort, ARIA and HTML5 were built on side of each other.

All of this matters because serious effort has been made to make the internet accessible to everyone, regardless of if you need assistive technology or not.

I previously wrote an article on my rewrite of PicoCSS and one of the philosophical principles that I kept was that aria attributes/roles can and should be used to style components.

Think about breadcrumbs for a moment. A breadcrumb widget is typically a menu that shows where a page sits in a site's hierarchy. With that approach, we can use very lean markup by leveraging a <nav> (menu), <ol> (hierarchical list), <a> (links), and the aria-current attribute:

<nav>
  <ol>
    <li>
      <a href="/sports">Sports</a>
    </li>
    <li>
      <a href="/football">Football</a>
    </li>
    <li>
      <a href="/football/2026" aria-current="page">2026 Season</a>
    </li>
  </ol>
</nav>

This structure has several benefits for users:

  1. The markup is lean
  2. Assistive technology can easily announce the menu
  3. Keyboard only users can easily navigate the menu
  4. Assistive technology can easily indicate which link represents the current page

What's nice for developers is that this specific structure of nav > ol can be used to style it to look like breadcrumbs.

In T'Pico, this is done via:

:where(nav:has(> ol)) {
  justify-content: flex-start;
}

:where(nav > ol) {
  flex-wrap: nowrap;
  margin-inline: 0;
  overflow-x: auto;
}

:where(nav > ol > li) {
  flex-shrink: 0;
  white-space: nowrap;
}

:where(nav > ol > li + li)::before {
  color: var(--t-pico-muted-color);
  content: var(--t-pico-nav-breadcrumb-divider);
  display: inline-block;
  margin-inline-end: var(--t-pico-nav-link-spacing-horizontal);
}

:where(
  nav > ol [aria-current]:not([aria-current=""], [aria-current="false" i]))
) {
  color: var(--t-pico-muted-color);
  font-weight: inherit;
  pointer-events: none;
  text-decoration: none;
}

:where(nav:dir(rtl)) {
  --t-pico-nav-breadcrumb-divider: "<";
}

:where(a:not([role="button"]), [role="link"]):is([aria-current]:not([aria-current="false" i]):not([aria-current=""]),
:hover,
:active,
:focus
) {
  --t-pico-color: var(--t-pico-primary-hover);
  --t-pico-text-decoration: underline;
  --t-pico-underline: var(--t-pico-primary-hover-underline);
}

Demo: https://jsbin.com/qatifaqase/edit?output

Notice how the aria-current drives the behavior of the active page.

Thank you for taking the time to read this article. I hope what you take away from this is the philosophy that I've picked up on of keeping an aria first approach to web development.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.