Course contentsShow
← Web Development
Lesson 306 of 2,9825. FlexboxFree lesson

Breadcrumb Navigation

Build breadcrumbs with separators using flexbox and pseudo-elements.

Breadcrumb Navigation

You'll learn how to build a breadcrumb navigation bar with separators using flexbox and pseudo-elements.

What Are Breadcrumbs?

Breadcrumbs are navigational aids that show users their current location within a website's hierarchy. Think of them like the trail Hansel and Gretel left in the fairy tale—they help you trace your path back home. A typical breadcrumb looks like: Home > Products > Laptops > Gaming.

Building Breadcrumbs with Flexbox

Breadcrumbs are perfect for flexbox because they're horizontal lists of links that need consistent spacing. Here's how to build them:

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.breadcrumb a {
  color: #0066cc;
  text-decoration: none;
}

.breadcrumb a:hover {
  text-decoration: underline;
}
<nav class="breadcrumb">
  <a href="/">Home</a>
  <span>/</span>
  <a href="/products">Products</a>
  <span>/</span>
  <span>Gaming Laptops</span>
</nav>

Adding Separators with Pseudo-Elements

Instead of manually adding separator elements, use the ::before pseudo-element to generate them automatically:

.breadcrumb a:not(:first-child)::before {
  content: "/";
  margin: 0 0.5rem;
  color: #999;
}

This adds a separator before every link except the first one. You can use any character: >, →, or even •.

Making It Semantic

The current page (last item) shouldn't be a link—it's where you already are!

Key Takeaway: Breadcrumbs use flexbox for horizontal layout with align-items: center, and pseudo-elements (::before) automatically generate separators between items, creating clean navigation without cluttering your HTML.