Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Bootstrap Breadcrumbs: Markup, CSS & Accessibility

· 6 min read · Home Tech

In this article
  1. What Are Breadcrumbs and Why Use Them?
  2. Bootstrap Breadcrumb Markup: The Correct Structure
  3. CSS: How Bootstrap Styles Breadcrumbs
  4. Accessibility Facts and Best Practices
  5. Common Problems and How to Fix Them
  6. Alternatives and When Not to Use Breadcrumbs
  7. Frequently Asked Questions

Bootstrap breadcrumbs are a navigation component that shows the user’s location within a site hierarchy. The correct markup uses a <nav> element with aria-label="breadcrumb", an ordered list with class="breadcrumb", and list items with class="breadcrumb-item"; the current page is marked with aria-current="page". This setup, combined with Bootstrap’s built-in CSS, provides a functional and accessible breadcrumb trail that helps users understand and navigate the site structure.

What Are Breadcrumbs and Why Use Them?

Breadcrumbs are a secondary navigation aid that reveals the user’s position in a website’s hierarchy. They typically appear horizontally at the top of a page, showing a trail like Home > Products > Laptops. They help users understand where they are, how the site is organized, and provide one-click access to higher-level pages. Breadcrumbs are especially useful on large e-commerce sites, documentation portals, and any site with multiple levels of content. They reduce the number of clicks needed to go back to a section and improve overall usability.

Bootstrap Breadcrumb Markup: The Correct Structure

Bootstrap 5 provides a specific markup pattern for breadcrumbs. The component is built with a <nav> element that has the aria-label="breadcrumb" attribute to identify it as a navigation landmark for assistive technologies. Inside, an ordered list (<ol>) with the class breadcrumb contains list items (<li>) with the class breadcrumb-item. The current page is represented by a list item with the class active and the attribute aria-current="page".

Here is the exact markup from Bootstrap’s documentation:

<nav aria-label="breadcrumb">
  <ol class="breadcrumb">
    <li class="breadcrumb-item"><a href="#">Home</a></li>
    <li class="breadcrumb-item"><a href="#">Library</a></li>
    <li class="breadcrumb-item active" aria-current="page">Data</li>
  </ol>
</nav>

Notice that the current page is not a link. It is plain text with the active class. This visually distinguishes it and prevents users from trying to click the page they are already on.

CSS: How Bootstrap Styles Breadcrumbs

Bootstrap’s CSS for breadcrumbs is straightforward. The .breadcrumb class uses flexbox with flex-wrap: wrap and padding: .75rem 1rem, along with a light background color (#e9ecef) and border-radius. The .breadcrumb-item + .breadcrumb-item selector adds a separator (by default a forward slash /) using the CSS content property on the ::before pseudo-element. The .active class sets the color to the muted gray #6c757d.

You can customize the separator by overriding the ::before content. For example, to use a chevron (›), you would add:

.breadcrumb-item + .breadcrumb-item::before {
  content: "›";
}

To change the background or padding, you can override the .breadcrumb class in your own CSS. If you are using Sass, you can modify the variables like $breadcrumb-divider and $breadcrumb-bg before compiling.

Accessibility Facts and Best Practices

Accessibility is a key reason for the specific markup. Here are the essential facts:

  • Use <nav> with aria-label="breadcrumb": This exposes the breadcrumb as a navigation landmark, allowing screen reader users to jump to it directly.
  • Use an ordered list (<ol>): The order of items matters, so a list conveys the hierarchy correctly.
  • Mark the current page with aria-current="page": This tells assistive technologies that this item represents the current page, so screen readers can announce it as such.
  • Do not link the current page: The current page should be plain text, not an anchor. This prevents confusion and redundant navigation.
  • Consider hiding the breadcrumb on small screens: Some sites hide breadcrumbs on mobile to save space, but this can harm orientation. If you do hide them, provide an alternative way to navigate.

One common misconception is that you need role="navigation" on the <nav> element. In HTML5, <nav> already implies the navigation role, so adding it is redundant. However, using aria-label is necessary to distinguish the breadcrumb from other navigation elements on the page.

Common Problems and How to Fix Them

Here are typical issues developers face and how to resolve them:

  • Separator not showing: Ensure you are using Bootstrap’s CSS correctly. If you are using a custom build, you may have excluded the breadcrumb component. Also check that the list items are siblings – the separator is added to .breadcrumb-item + .breadcrumb-item, so if you nest items, it won’t work.
  • Breadcrumb wraps awkwardly: By default, flex-wrap: wrap allows wrapping. If you want to prevent wrapping, add flex-wrap: nowrap to the .breadcrumb class, but be aware this may cause overflow on small screens.
  • Current page is a link: This is a common error. Remove the <a> tag from the active item and just use plain text with the active class.
  • Screen reader reads “breadcrumb” too many times: If you have multiple <nav> elements, each with aria-label="breadcrumb", screen readers will announce each one. Use unique labels if you have more than one breadcrumb on a page, or use aria-label="Breadcrumb" only on the primary one.

Alternatives and When Not to Use Breadcrumbs

Breadcrumbs are not always the right choice. For flat sites with only one or two levels, they can be redundant. Alternatives include:

  • Simple back button: If the site has a linear flow, a back button may be sufficient.
  • Tab navigation: For sections that are peers rather than hierarchical, tabs work better.
  • Sidebar navigation: When there are many subpages, a sidebar can show the full hierarchy at once.

Breadcrumbs are most effective when the site has a clear hierarchy of three or more levels. They should not replace primary navigation; they are a supplement. Also, avoid using breadcrumbs on single-page applications where the “location” is not a URL but a state – in such cases, a different orientation aid may be more appropriate.

Frequently Asked Questions

Do I need JavaScript for Bootstrap breadcrumbs?

No. Breadcrumbs are purely CSS and HTML. They do not require any JavaScript to function. The only interactive elements are the links themselves.

Can I use a <div> instead of <ol>?

Technically you can, but it is not recommended. The ordered list conveys the sequence of the hierarchy to assistive technologies and is part of Bootstrap’s documented markup. Using a <div> would require additional ARIA roles to replicate the same semantics, which is more work and more error-prone.

How do I change the breadcrumb separator?

Override the content property of the .breadcrumb-item + .breadcrumb-item::before pseudo-element. For example, to use a right-pointing angle bracket, add .breadcrumb-item + .breadcrumb-item::before { content: "›"; }. You can also use an image or icon font by setting content to an empty string and using a background image.

Should breadcrumbs be visible on mobile?

It depends on your design. Breadcrumbs can take up valuable space on small screens, but they also help orientation. If you hide them, ensure users have another way to know where they are. Some sites show a truncated breadcrumb on mobile, like “Home / … / Current Page”.

What is the difference between aria-current="page" and class="active"?

class="active" is a visual styling hook used by Bootstrap to gray out the text. aria-current="page" is an accessibility attribute that tells screen readers the item represents the current page. Both are needed: the class for visual users, the ARIA attribute for assistive technology users.

Can I use breadcrumbs for a product category path that is not a true hierarchy?

Yes, but be cautious. If your categories are not strictly hierarchical (e.g., a product appears in multiple categories), breadcrumbs can confuse users. In such cases, consider using a “tag” or “related” style navigation instead. Always reflect the actual URL structure or a logical parent-child relationship.