Creating Pagination Links

To create pagination links in HTML, use a list (ul) within a nav element and style the links with CSS.

Pagination links are used to divide a large amount of content across multiple pages, allowing users to jump back and forth between them. It is a common pattern for search results, blogs, and product listings.

The HTML Structure

Each page number or arrow in your pagination should be a link within a list item:

Using aria-label="Page navigation" on the nav element helps screen readers identify this section as the page-to-page navigation area.

Styling the Links

To make the list horizontal, set the display property to flex on the ul element. You can then style the links to have a border, padding, and a hover effect to make them look like buttons:

Full Working Example

In the following example, we have styled the pagination links with rounded corners and a smooth hover transition:

View Output Full Screen Preview

The Active State

It's important to indicate to the user which page they are currently on. In the example above, we added an active class to the current page number and gave it a distinct background color. You can also use aria-current="page" on the active link to further assist screen reader users.