Latest web development tutorials
 

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:

To create a pagination, style a HTML list:

Example

ul.pagination {
    display: inline-block;
    padding: 0;
    margin: 0;
}

ul.pagination li {display: inline;}

ul.pagination li a {
    color: black;
    float: left;
    padding: 8px 16px;
    text-decoration: none;
}
Try it Yourself »

Active and Hoverable Pagination

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

ul.pagination li a.active {
    background-color: #4CAF50;
    color: white;
}

ul.pagination li a:hover:not(.active) {background-color: #ddd;}
Try it Yourself »

Rounded Active and Hoverable Buttons

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

Example

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

ul.pagination li a.active {
    border-radius: 5px;
}
Try it Yourself »

Hoverable Transition Effect

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

Example

ul.pagination li a {
    transition: background-color .3s;
}
Try it Yourself »

Bordered Pagination

Use the border property to add borders to the pagination:

Example

ul.pagination li a {
    border: 1px solid #ddd; /* Gray */
}
Try it Yourself »

Rounded Borders

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

Example

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

.pagination li:last-child a {
    border-top-right-radius: 5px;
    border-bottom-right-radius: 5px;
}
Try it Yourself »

Space Between Links

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

Example

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

Pagination Size

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

Example

ul.pagination li a {
    font-size: 22px;
}
Try it Yourself »

Centered Pagination

To center the pagination, wrap a container element around it (like <div>), and add text-align:center

Example

div.center {
    text-align: center;
}
Try it Yourself »

More Examples


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";
}
Try it Yourself »