Code has been added to clipboard!

A Source of Beginner-Friendly CSS Pagination Examples

Reading time 4 min
Published Dec 1, 2016
Updated Jan 23, 2020

TL;DR — CSS pagination refers to the procedure of organizing websites into separate pages and giving them numbers.

Getting Started With CSS Pagination

CSS pagination is for sites consisting of multiple pages. The pagination process begins by listing links to all the separate pages.

«
1
2
3
4
5
»

In the example, we create a simple pagination CSS style:

Example
.paginate {
    display: inline-block;
    padding: 2px;
    margin: 2px;
}

.paginate a {
    text-decoration: none;
    color: blue;
   float: left;
   padding: 10px 15px;
}

The first CSS pagination examples follow these steps:

  • Most of the CSS pagination examples present the links and wrap them in <div>.
  • Aligns links with float.
  • Sets text-decoration to none to remove underlines from links.
  • Adds padding and margin to make paginated links look neater.

Active and Hoverable

It is possible to highlight the page you are currently on by using the .active class and the :hover selector.

«
1
2
3
4
5
»

In the following pagination example, we assign :hover and .active to our list of links:

Example
.paginate a.active {
    background-color: lightblue;
    color: lightblue;
}

.paginate a:hover:not(.active) {
    background-color: lightgray;
}

Rounded Corners

We make the following CSS pagination examples to have rounded corners buttons by applying the border-radius property.

«
1
2
3
4
5
»

The border-radius accepts values as length (pt, px, cm, etc.) or percentage (%) indicators.

In the example, we add the border-radius to the pagination process:

Example
.paginate a {
    border-radius: 10px;
}

.paginate a.active {
    border-radius: 10px;
}

Transition Effect on Hover

The :hover selector allows us to change the styling of an element when a mouse cursor moves over it. However, changes happen at once.

The CSS transition property lets you indicate how quickly does the styling change.

«
1
2
3
4
5
»

We assign transition to our list in this CSS pagination example to make the transition of styles smoother:

Example
.paginate a {
    transition: background-color .5s; 
}

Adding Borders

In the following CSS pagination examples, we add borders to paginated links. Borders separate the link buttons from one another.


«
1
2
3
4
5
»

You can customize CSS borders by defining colors, styles, and width values inside the border shorthand.

In the example, we add borders to our pagination:

Example
.paginate a {
    border: 2px solid green;
}

The code below shows how to make rounded borders by using the border-radius property:

Example
.paginate a:first-child {
    border-top-left-radius: 10px;
    border-bottom-left-radius: 10px;
}

.paginate a:last-child {
    border-top-right-radius: 10px;
    border-bottom-right-radius: 10px;
}

If you want to add space around each page link, use margin.

«
1
2
3
4
5
»

In the example, we use margin property with two values defined:

Example
.paginate a {
    margin: 5px 10px;
}

Setting Text Size

You can easily manipulate the size of your page numbers with CSS. The font-size property changes the size of the text without changing the size of the HTML element.

We assign specific size (22px) to the numbers on this CSS pagination list example:

«
1
2
3
4
5
»
Example
.paginate a {
    font-size: 22px;
}

Alignment

You can position the pagination list on the left, right, or at the center of the page.

To align the pagination, you need to wrap it in a container such as <div>, <span>, <p>, or others.

Then, you should apply text-align property with one of the following values: left, right, or center.

In the following example, we center the CSS pagination:

Example
.center {
    text-align: center;
}

Breadcrumbs are essentially a variation of pagination. It is for displaying a file path in categories. To create breadcrumbs, you should follow these steps:

  • Perform HTML pagination by creating an unordered HTML list (<ul>).
  • Style the unordered list.
  • To remove the markers, we apply the list-style: none property.
  • Assign display: inline to have the links aligned side by side.

In the example, we create the breadcrumbs pagination:

Example
ul.bc {
    padding: 10px 15px;
    list-style: none;
    background-color: lightgreen;
}  	

ul.bc li {
    display: inline;
}

ul.bc li+li:before {
    padding: 10px;
    color: white;
    content: "/\00a0";
}

CSS Pagination Examples: Useful Tips

  • CSS pagination is important for SEO as it helps search engines index posts and rank them.
  • Bootstrap offers styled pagination links that you can use.
Tutorial
CSS3 Features
Syntax
Classes
ID Selectors
Attribute Selectors
Stylesheets
Inline
Internal
External
Box Model
Children Selectors
Pseudo Classes
Pseudo Elements
Variables
Counters
Text
Fonts
Web Fonts
Backgrounds
Background Images
Colors
Gradients
Opacity / Transparency
Shadow Effects
Transitions
Tooltip
Transform
Animations
Layout — Display
Layout — Position
Layout — Float
Layout — Clear
Layout — Horizontal & Vertical Align
Multiple Columns
Introduction
Responsive Web Design — Viewport
Responsive Web Design — Grid View
Responsive Web Design — Media Queries
Responsive Web Design — Flexbox Layout
Responsive Web Design — Images
Responsive Web Design — Videos
Borders
Margin
Padding
Width
Height
Outline
Links
Lists
Tables
Dropdown Menu
Navigation Bar
Images
Image Gallery
Border Images
Forms
Rounded Corners
Buttons
Box-Sizing
Selector Reference
Pagination Examples
Code Examples
CSS3 Browser Support Reference
Functions Reference
Speech Module Reference
Units
Web Safe Font Combinations
Cheat Sheet
:hover
@font-face
@keyframes
@media
align-content
align-items
align-self
all
animation
backface-visibility
background
background-clip
background-color
background-image
background-origin
background-position
background-size
border
border-image
border-radius
border-style
box-shadow
box-sizing
color
columns
filter
flex
flex-basis
flex-direction
flex-flow
flex-grow
flex-shrink
flex-wrap
font
font-family
font-size
font-size-adjust
font-stretch
font-style
font-weight
hanging-punctuation
justify-content
line-height
margin
offset
opacity
order
outline
overflow
padding
perspective
position
resize
tab-size
text-align
text-decoration
text-emphasis
text-transform
text-shadow
transform
transition-property
translate
vertical-align
word-break
word-wrap
z-index