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.
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>
.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:
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>
Disabled Page
The .disabled class is used when a
pagination link should not be clickable.
Example:
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.
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
.paginationclass. -
Forgetting
.page-itemaround each item. -
Forgetting the
.page-linkclass. -
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.
-
.paginationcreates the pagination container. -
.page-itemcreates each pagination item. -
.page-linkcreates the clickable link. -
.activehighlights the current page. -
.disableddisables a pagination item. -
.pagination-smcreates small pagination. -
.pagination-lgcreates large pagination.