Master Bootstrap From Scratch

Clear, interactive, and structured Bootstrap lessons designed for beginners and developers.

Bootstrap Pagination

Learn how to create pagination in Bootstrap to divide large amounts of content into multiple pages.

What is Pagination?

Pagination is a navigation component used to divide large amounts of content into separate pages.

Instead of displaying all records on one page, pagination allows users to move between different pages.

Example: 1 2 3 4 5 Next

Why Use Pagination?

Pagination is useful when a website contains a large number of records or content items.

  • It keeps the page clean and easy to read.
  • It improves website navigation.
  • It avoids displaying too much content at once.
  • It is commonly used in tables, product lists, search results, and blog pages.

Basic Pagination

Bootstrap provides the .pagination class to create pagination.

Each page number is created using the .page-item and .page-link classes.

Example:
Code:
<ul class="pagination">

    <li class="page-item">
        <a class="page-link" href="#">
            1
        </a>
    </li>

    <li class="page-item">
        <a class="page-link" href="#">
            2
        </a>
    </li>

    <li class="page-item">
        <a class="page-link" href="#">
            3
        </a>
    </li>

</ul>
Simple Explanation: .pagination creates the pagination container, while .page-item and .page-link create individual page numbers.

Previous and Next Buttons

Pagination can contain Previous and Next buttons to make navigation easier.

Example:
Simple Explanation: Previous moves to the previous page and Next moves to the next page.

Active Page

The .active class is used to highlight the current page.

Example:
<li class="page-item active"
    aria-current="page">

    <a class="page-link" href="#">
        2
    </a>

</li>
Note: Here, page number 2 is the current page.

Disabled Page

The .disabled class is used when a pagination link should not be clickable.

Example:
Example: On the first page, the Previous button can be disabled because there is no previous page.

Pagination Sizes

Bootstrap provides different pagination sizes using .pagination-sm and .pagination-lg.

Small Pagination:
<ul class="pagination pagination-sm">

    ...

</ul>
Large Pagination:
<ul class="pagination pagination-lg">

    ...

</ul>

Centered Pagination

Use justify-content-center to place pagination in the center.

<ul class="pagination justify-content-center">

    ...

</ul>

Right Aligned Pagination

Use justify-content-end to align pagination to the right side.

<ul class="pagination justify-content-end">

    ...

</ul>

Real-World Example

Suppose an online training website contains 100 courses. Showing all courses on one page would make the page very long.

Instead, we can display 10 courses per page and use pagination to navigate between the pages.

Simple Explanation: The user can move from one course page to another without loading all courses at the same time.

Important Pagination Classes

Class Purpose
.pagination Creates the pagination container.
.page-item Creates an individual pagination item.
.page-link Creates the clickable page link.
.active Highlights the current page.
.disabled Disables a pagination item.
.pagination-sm Creates small pagination.
.pagination-lg Creates large pagination.

Common Mistakes

  • Forgetting the .pagination class.
  • Forgetting .page-item around each item.
  • Forgetting the .page-link class.
  • Not highlighting the current page using .active.
  • Not disabling Previous on the first page or Next on the last page.

Summary

Bootstrap Pagination is used to divide large amounts of content into multiple pages.

  • .pagination creates the pagination container.
  • .page-item creates each pagination item.
  • .page-link creates the clickable link.
  • .active highlights the current page.
  • .disabled disables a pagination item.
  • .pagination-sm creates small pagination.
  • .pagination-lg creates large pagination.