CSS Pagination is used to split large amounts of content into multiple pages, making it easier for users to navigate through data, articles, or search results.
Pagination usually consists of page numbers and navigation buttons like Previous and Next. CSS helps you style these elements with spacing, colors, hover effects, and disabled states so users can clearly see where they are and where they can go next.
<ul> holding page links.1, 2, Next) is an <li> with a link..active.Previous on the first page or Next on the last page using a class like .disabled.Pagination UI is usually built with:
<ul class="pagination"> container.<li> element with an <a> tag..active and .disabled added based on the current page.
/* Basic CSS for a horizontal pagination bar */
.pagination {
display: inline-flex;
list-style: none;
padding: 0;
margin: 0;
}
.pagination li a {
display: block;
padding: 10px 16px;
text-decoration: none;
color: #007bff;
border-right: 1px solid #ddd;
background-color: white;
cursor: pointer;
transition: background-color 0.3s ease, color 0.3s ease;
}
.pagination li a:hover {
background-color: #007bff;
color: white;
}
.pagination li a.active {
background-color: #007bff;
color: white;
cursor: default;
}
.pagination li a.disabled {
color: #ccc;
cursor: not-allowed;
background-color: #f9f9f9;
}
This is a typical markup structure for a pagination bar:
<!-- HTML structure for pagination -->
<ul class="pagination">
<li><a href="#" class="disabled">« Previous</a></li>
<li><a href="#" class="active">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
<li><a href="#">5</a></li>
<li><a href="#">Next »</a></li>
</ul>
In this example, the current page is highlighted using the .active class, while the Previous button is disabled using the .disabled class. Hover effects help users see which page they are about to select, and the layout stays compact and readable on both desktop and mobile screens.
<ul> and <li> for pagination lists.Previous on the first page and Next on the last page to avoid confusion.Next button to be disabled on the last page using the .disabled class.