How to Create a Breadcrumb Navigation with CSS

Breadcrumb navigation is a secondary navigation method that helps users understand their current location within a website and provides a clear path back to the homepage or higher-level pages.

This type of navigation is particularly useful for websites with a deep hierarchy of pages, and it can improve the user experience and increase the likelihood of successful navigation.

In this tutorial, we’ll walk through the process of creating a breadcrumb navigation using CSS.


Step 1: HTML Markup

The first step in creating a breadcrumb navigation is to add the HTML markup.

The markup should include a list of links, each of which represents a page in the hierarchy.

The first link should be the homepage, and the rest of the links should represent the hierarchy of pages leading to the current page.

<ul class="breadcrumb">
  <li><a href="/">Home</a></li>
  <li><a href="/category/">Category</a></li>
  <li>Page Title</li>
</ul>

Step 2: Basic Style

Next, add some basic styles to the breadcrumb navigation to make it appear as a horizontal list.

You can use the CSS list-style-type property to remove the default bullet points and add padding and margin to the list items to provide some space between them.

.breadcrumb {
  list-style-type: none;
  padding: 10px 16px;
  background-color: #eee;
}

.breadcrumb li {
  display: inline-block;
  margin-right: 10px;
}

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

Step 3: Separator

To make the breadcrumb navigation more visually appealing, you can add a separator between the list items.

This can be done using the :before pseudo-element and the content property.

.breadcrumb li:not(:last-child)::before {
content: "›";
color: #555;
margin-right: 10px;
}

Step 4: Active Page

To indicate the current page in the breadcrumb navigation, you can style the list item for the current page differently from the rest of the items.

For example, you can change the text color to black and remove the link.

.breadcrumb li.active {
color: #000;
font-weight: bold;
}

.breadcrumb li.active a {
pointer-events: none;
cursor: default;
}

Conclusion

Breadcrumb navigation can greatly improve the user experience and make it easier for visitors to navigate your website.

By following the steps outlined in this article, you can create a breadcrumb navigation that is both functional and aesthetically pleasing.

With some creativity, you can customize the appearance of the breadcrumb navigation to match the design of your website.