Bootstrap Breadcrumbs
Learn how to create breadcrumbs in Bootstrap to show the current location of a user within a website.
What are Breadcrumbs?
Breadcrumbs are a navigation component used to show the current location of a user on a website.
They display the path from the home page to the current page. This makes it easier for users to understand where they are and navigate back to previous pages.
Why Use Breadcrumbs?
Breadcrumbs are useful when a website contains multiple levels of pages or categories.
- They show the user's current location.
- They provide quick navigation to previous pages.
- They improve the overall user experience.
- They are useful for websites with many pages.
Basic Breadcrumb
Bootstrap provides the
.breadcrumb class to create a breadcrumb.
Each individual item is created using the
.breadcrumb-item class.
Example:
Code:
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item">
<a href="#">Home</a>
</li>
<li class="breadcrumb-item">
<a href="#">Courses</a>
</li>
<li class="breadcrumb-item active"
aria-current="page">
Bootstrap
</li>
</ol>
</nav>
Breadcrumb Classes
Bootstrap uses specific classes to create breadcrumb navigation.
| Class | Description |
|---|---|
.breadcrumb
|
Creates the breadcrumb container. |
.breadcrumb-item
|
Creates an individual breadcrumb item. |
.active
|
Indicates the current page. |
Active Breadcrumb Item
The current page in a breadcrumb should normally use
the .active class.
Example:
<li class="breadcrumb-item active"
aria-current="page">
Bootstrap Breadcrumbs
</li>
Multiple Breadcrumb Levels
You can add multiple breadcrumb items when your website has several navigation levels.
Example:
Breadcrumb with Links
Previous breadcrumb items can contain links so users can navigate back to those pages.
Example:
Breadcrumb Accessibility
Bootstrap breadcrumbs can be made more accessible by
using the aria-label and
aria-current attributes.
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item">
<a href="#">Home</a>
</li>
<li class="breadcrumb-item active"
aria-current="page">
Bootstrap
</li>
</ol>
</nav>
Real-World Example
Suppose a student is learning Bootstrap on a training website.
The website can show the following breadcrumb:
This tells the student that Bootstrap is currently open under the Web Development course.
Common Mistakes
-
Forgetting the
.breadcrumbclass. -
Forgetting the
.breadcrumb-itemclass. -
Not using
.activefor the current page. - Adding too many unnecessary breadcrumb levels.
-
Forgetting
aria-current="page"for the current page.
Summary
Bootstrap Breadcrumbs are used to show the navigation path of the current page.
-
.breadcrumbcreates the breadcrumb container. -
.breadcrumb-itemcreates each breadcrumb item. -
.activeidentifies the current page. -
aria-current="page"identifies the current page for accessibility. - Breadcrumbs make navigation easier for users.