Facebook Tracking Pixel

Article

Accessible Components: Pagination Controls

Published By:

TABLE OF CONTENTS

WEBINAR

How Charities Can Reach More People Online

Sign Up

Pagination Controls

This guide provides helpful HTML and CSS fixes – including semantic landmarks, compliant target sizing, and clear visual styling – to make pagination controls fully accessible and inclusive.

The primary goal of pagination controls is simple – help users navigate different pages within a listing to find exactly what they are looking for. However, our web audits show that many websites fail to provide this simplicity for everyone. Common issues include layouts that lose context when read by screen readers, small target sizes that lead to accidental clicks for users with poor motor skills, and interactive controls that lack accessible visual distinction. Non-accessible pagination controls simply cannot be used by some users with disabilities.

Identifying the problems

When auditing website, we see a few common issues with pagination components:

  • Visually intuitive layouts losing this implied meaning when being read by a screen reader. This visual structure is lost when a screen reader simply reads the visible text in a pagination component. A screen reader might read “1”, “2”, “dots”, “9”, “10”, “right arrow” which is difficult to intuit without more context.
  • Pagination links are common candidates for small target sizes. Being seen as secondary to the content around them, if pagination controls are too small, or positioned too close to one another, users with low vision or poor motor skills may inadvertently click the wrong link.
  • Pagination controls are interactive controls, so they need to be visually distinguishable for all sighted users. Sites often fail to do this correctly for everyone.

Building accessible pagination controls

Now that we understand the problems we see for pagination controls, let’s look at some solutions.

Signposting the component for screen reader users

First of all, let’s make the whole component easily identifiable for screen reader users; the purpose of pagination controls is to allow users to navigate through a listing, so just wrap the entire component in a <nav> landmark to identify its purpose. We then give this landmark a unique name to clearly establish the purpose of this navigation landmark. Doing so will look something like this:

<nav aria-label="Article pagination"> ... </nav>

Immediately, we’re communicating key details about the component with the markup; this is a navigation component and specifically it is pagination for our article listing.

Structuring the component

Next, let’s add more structure within the component. Pagination controls are presented as a list, albeit usually a horizontal list. Therefore, our markup should reflect this:

<nav aria-label="Article pagination">
    <ul>
        <li>...</li>
        <li>...</li>
        <li>...</li>
        <li>...</li>
    </ul>
</nav>

The order of the list isn’t particularly important, so <ul> is fine here. Each list item will contain a different link, but the list nature of the content is now clear to screen reader users. Additionally, screen reader users will navigate through page content by jumping from list to list, so anyone doing this will also find the pagination controls just fine.

Adding the navigation links

Now we’ve got the structure of the component set up, let’s add in some navigation links. It is important to keep in mind that these are indeed links, even if they might visually resemble buttons, so <a> tags are definitely correct here:

<nav aria-label="Article pagination">
    <ul>
        <li>
            <a href="/articles/page1.html">1</a>
        </li>
        <li>
            <a href="/articles/page2.html">2</a>
        </li>
        <li>
            <a href="/articles/page3.html">3</a>
        </li>
        <li>
            <a href="/articles/page2.html">Next</a>
        </li>
    </ul>
</nav>

It is important to note that in the example above, the current page is assumed to be the first one, hence why there is no “Previous” control. When the user is on the first page of a listing, there should not be a “Previous” control and when they’re on the last page of a listing, there should not be a “Next” control, not even in an inactive state. It is simply best to omit those controls when they aren’t needed.

Ensuring sufficient target size

The next aspect to consider is the size of these controls on the page. We need to ensure readability and enough clickable area for users with limited motor skills. The key targets to aim for here are a minimum size of 24px by 24px for WCAG AA compliance and 44px by 44px for WCAG AAA compliance.

Here are some visual examples of both AA and AAA minimum sizes by just adding some visually sizing and spacing to the links:

AA compliance size

A screenshot showing basic pagination buttons, marked up to show their dimensions being at least 24 by 24 pixels in order to be WCAG AA compliant

AAA compliance size

A screenshot showing basic pagination buttons, marked up to show their dimensions being at least 44 by 44 pixels in order to be WCAG AAA compliant

To achieve these, the following styling declarations were made:

nav ul li a {
    display: block;
    min-width: 24px;
    min-height: 24px;
    font-size: 14px;
    text-align: center;
    border: 1px solid #888888;
    border-radius: 5px;
    line-height: 22px;
    padding: 0 5px;
}

The differences between these two examples for styling are the following to just increase the size on screen and sit a little more comfortably in the larger size:

min-width: 44px;
min-height: 44px;
font-size: 18px;
line-height: 42px;
padding: 0 5px;

Adding further improvements

We can take this a little further to really improve things for all users. Let’s start by improving the announcement of each link for screen reader users. While the context clues are now there for the purpose of each link, we can do better on how they are announced. Adding visually hidden <span> elements can help make screen reader announcements clearer:

<li>
    <a href="/articles/page1.html">span class="visually-hidden">Page </span>1</a>
</li>
...
<li>
    <a href="/articles/page2.html">Next<span class="visually-hidden"> Page</span></a>
</li>

New styling:

.visually-hidden {
    position: absolute;
    font-size: 0;
    opacity: 0;
}

This will give a bit more content to explain the purpose of each link. Adding this to the “next” and “previous” controls will also help improve the clarity of the purpose of these links.

Confirming the user’s current page

Next, we want to help users more easily identify which page they are currently on in the pagination. Rather than convert the current page into something other than a link (remember; consistency is really important for accessibility), we’ll just add a simple aria attribute:

<a href="/articles/page1.html" aria-current="page"><span class="visually-hidden">Page </span>1</a>

This means screen readers will announce this link as being the user’s current page nice and clearly. We can also use that attribute as a handy target for some visual styling to indicate the same to sighted users:

nav ul li a[aria-current="page"] {
    background-color: #0000ef;
    color: white;
}

The result of which looks like this:

A screenshot showing basic pagination buttons, with the current page clearly indicated through visual means

How to handle extensive pagination options

When pagination controls run to a large number, rather than show all of the numbers in the pagination controls, we can show some either side of the current page and then some separators. There are a few things to keep in mind; 1) the separators should exist within the list structure, but not be links; 2) the purpose of the separators should be clear to all users; 3) the separators should not look like the links.

<li>
    <a href="/articles/page97.html">Previous<span class="visually-hidden"> Page</span></a>
</li>
<li>
    <a href="/articles/page1.html"><span class="visually-hidden">Page </span>1</a>
</li>
<li>⋯</li>
<li>
    <a href="/articles/page97.html"><span class="visually-hidden">Page </span>97</a>
</li>
<li>
    <a href="/articles/page98.html" aria-current="page"><span class="visually-hidden">Page </span>98</a>
</li>
<li>
    <a href="/articles/page99.html"><span class="visually-hidden">Page </span>99</a>
</li>
li>⋯</li>
<li>
    <a href="/articles/page200.html"><span class="visually-hidden">Page </span>200</a>
</li>
<li>
    <a href="/articles/page99.html">Next<span class="visually-hidden"> Page</span></a>
</li>

For the separators, we have some placeholder ellipses. These will visually show the break between the links before and after. For screen reader users, the list item will be read, but not present a link, indicating the break to them as well.

Another popular choice for the visual presentation of “next” and “previous” links is to replace the words with arrows pointing left and right. These arrows do not convey inherent meaning outside of their visual presentation, so it is best to keep the text label for the link present but visually hidden for the benefit of screen reader users. The arrows are then decorative, and can be hidden from screen reader users.

<li>
    <a href="/articles/page1.html"><span class="visually-hidden">Previous Page</span><span class="arrow-previous"></span></a>
</li>
<li>
    <a href="/articles/page1.html"><span class="visually-hidden">Page </span>1</a>
</li>
<li>
    <a href="/articles/page2.html" aria-current="page"><span class="visually-hidden">Page </span>2</a>
</li>
<li>
    <a href="/articles/page3.html"><span class="visually-hidden">Page </span>3</a>
</li>
<li>
    <a href="/articles/page3.html"><span class="visually-hidden">Next Page</span><span class="arrow-next"></span></a>
</li>

Finally, to ensure we retain important visual distinction on the controls, the following are all important to consider when styling a pagination component;

  1. Colour contrast. Ensure a 4.5:1 colour contrast ratio between link text and its background. Ensure a 3:1 colour contrast ratio between the button edges and surrounding pixels.
  2. Do not rely on color alone to denote links; use additional signifiers like underlines.
  3. Do not remove default browser-default focus outlines without replacing them with highly visible, custom focus styling for keyboard-only users.

The finished component

Putting this all together, we have pagination markup that looks something like the content below:

<nav aria-label="Article pagination">
    <ul>
        <li>
            <a href="/articles/page1.html">Previous<span class="visually-hidden"> Page</span></a>
        </li>
        <li>
            <a href="/articles/page1.html"><span class="visually-hidden">Page </span>1</a>
        </li>
        <li>
            <a href="/articles/page2.html" aria-current="page"><span class="visually-hidden">Page </span>2</a>
        </li>
        <li>
            <a href="/articles/page3.html"><span class="visually-hidden">Page </span>3</a>
        </li>
        <li>
            <a href="/articles/page3.html">Next<span class="visually-hidden"> Page</span></a>
        </li>
    </ul>
</nav>

I also used the following basic styling declaration on this:

* { box-sizing: border-box; } nav ul {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    list-style: none;
    column-gap: 5px;
}
nav ul li a {
    display: block;
    min-width: 44px;
    min-height: 44px;
    font-size: 18px;
    line-height: 42px;
    text-align: center;
    border: 1px solid #888888;
    border-radius: 5px;
    line-height: 42px;
    padding: 0 10px;
}
nav ul li a:focus {
    outline: 2px solid #0000ef;
    outline-offset: 2px;
}
nav ul li a:hover {
    background-color: #0000ef;
    border-color: #0000ef;
    color: white;
}
.visually-hidden {
    position: absolute;
    font-size: 0;
    opacity: 0;
}
nav ul li a[aria-current="page"] {
    background-color: #0000ef;
    border-color: #0000ef;
    color: white;
}

All in all, pagination components are a pivotal part of offering good navigation through a listings page and there are some fundamental parts that need to be done in order to make these accessible. Beyond this baseline, there’s a lot that can be done to improve these components and make a really accessible component that is simple and easy for everyone to use.

Richard Albary

About the Author

Richard is an accessibility auditor here at Recite Me. Prior to this, he has extensive experience as a front-end web developer, which gave him an opportunity to build countless accessible web components.
Richard Albary
Accessibility Auditor at Recite Me
Type
Job Titles
Share

Related Content