CSS Pagination Examples

 

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

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="styles.css">
  <title>Pagination Example</title>
</head>
<body>

  <div class="pagination">
    <a href="#" class="active">1</a>
    <a href="#">2</a>
    <a href="#">3</a>
    <a href="#">4</a>
    <a href="#">5</a>
  </div>

</body>
</html>

 

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: #4CAF50;
  color: white;
}

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

Rounded Active and Hoverable Buttons

.pagination {
  display: flex;
  list-style: none;
  padding: 0;
}

.pagination a {
  text-decoration: none;
  padding: 8px 12px;
  margin: 0 4px;
  border: 1px solid #ccc;
  color: #333;
  border-radius: 4px;
  transition: background-color 0.3s;
}

.pagination a:hover {
  background-color: #eee;
}

.pagination a.active {
  background-color: #007bff;
  color: #fff;
}

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

Example

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

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

Hoverable Transition Effect

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <style>
    .hover-effect {
      width: 200px;
      height: 100px;
      background-color: #3498db;
      color: #fff;
      text-align: center;
      line-height: 100px;
      transition: background-color 0.3s ease;
    }

    .hover-effect:hover {
      background-color: #2980b9;
    }
  </style>
  <title>Hoverable Transition Effect</title>
</head>
<body>

  <div class="hover-effect">Hover Me</div>

</body>
</html>

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

Example

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


Bordered Pagination

  • Initial styles, such as background-color, color, and transition.
  • The transition property is used to specify the property to be transitioned (background-color), the duration of the transition (0.3s), and the timing function (ease).

Use the border property to add borders to the pagination:

Example

.pagination a {
  border: 1px solid #ddd; /* 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: 5px;
  border-bottom-left-radius: 5px;
}

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

Space Between Links

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

 

Example

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

Pagination Size

  • hange the size of the pagination with the font-size property:

Example

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

To center the pagination, wrap a container element (like

) around it with text-align:center

 

Example

.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: "/�0a0";
}

 
CSS Pagination

Login
ADS CODE