CSS Adding and Styling Paginations

Learn how to create a responsive pagination using CSS.

Simple Pagination

If you have a website with lots of pages, you may wish to add some sort of pagination to each page:

Example

.pagination {
display: inline-block;
}

.pagination a {
color: black;
float: left;
padding: 8px 16px;
text-decoration: none;
}

Active and Hoverable Pagination

  • «
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • »

Highlight the current page with an .active class, and use the :hover selector to change the color of each page link when moving the mouse over them:

Example

.pagination a.active {
background-color: #0054ff;
color: white;
}

.pagination a:hover:not(.active) {background-color: #f2f2f2;}

Rounded Active and Hoverable Buttons

Add the border-radius property if you want a rounded "active" and "hover" button:

Example

.pagination a {
border-radius: 20px;
}

.pagination a.active {
border-radius: 20px;
}

Hoverable Transition Effect

Add the transition property to the page links to create a transition effect on hover:

Example

.pagination a {
transition: background-color .3s;
}

Bordered Pagination

Use the border property to add borders to the pagination:

Example

.pagination a {
border: 1px solid #e6e6e6; /* Gray */
}

Rounded Borders

Tip: Add rounded borders to your first and last link in the pagination:

Example

.pagination a:first-child {
border-top-left-radius: 20px;
border-bottom-left-radius: 20px;
}

.pagination a:last-child {
border-top-right-radius: 20px;
border-bottom-right-radius: 20px;
}

Space Between Links

Tip: Add the margin property if you do not want to group the page links:

Example

.pagination a {
margin: 0 5px; /* 0 is for top and bottom. Feel free to change it */
}

Pagination Size

Change the size of the pagination with the font-size property:

Example

.pagination a {
font-size: 25px;
}

Centered Pagination

To center the pagination, wrap a container element (like <div>) around it with text-align:center. and add display: inline-block; to pagination <div>.

.center {
text-align: center;
}

Breadcrumbs

Another variation of pagination is so-called "breadcrumbs":

Example

ul.breadcrumb {
padding: 8px 16px;
list-style: none;
background-color: #eee;
}

ul.breadcrumb li {display: inline;}

ul.breadcrumb li+li:before {
padding: 8px;
color: black;
content: "/\00a0";
}

Comments