Pagination
Pagination steps through a long list split over several pages, such as search results or
an archive. It is a nav of links with one class. The current page is marked
with aria-current, and an end with nowhere to go is plain text, not a link.
Numbered pages
Each page is a link, and the current one carries aria-current="page",
which both marks it for a screen reader and lights it up. Previous and Next take
rel="prev" and rel="next", which tell browsers and search
engines how the pages run. On the first page there is no previous one, so Previous is a
span: it shows where the control would be but cannot be clicked or
tabbed to.
<nav class="paging" aria-label="Pagination">
<span>Previous</span>
<a href="?page=1" aria-current="page">1</a>
<a href="?page=2">2</a>
<a href="?page=3">3</a>
<a href="?page=4">4</a>
<a href="?page=2" rel="next">Next</a>
</nav>
Long runs
With many pages, show the first and last, a few either side of the current one, and an
ellipsis for each gap. The ellipsis is a span, like a missing end.
<nav class="paging" aria-label="Pagination">
<a href="?page=6" rel="prev">Previous</a>
<a href="?page=1">1</a>
<span>…</span>
<a href="?page=6">6</a>
<a href="?page=7" aria-current="page">7</a>
<a href="?page=8">8</a>
<span>…</span>
<a href="?page=20">20</a>
<a href="?page=8" rel="next">Next</a>
</nav>
Previous and next only
When the page numbers do not matter, as in a blog or a step-by-step guide, keep just the two ends and say where the reader is between them.
<nav class="paging" aria-label="Pagination">
<a href="?page=2" rel="prev">Newer posts</a>
<span>Page 3 of 12</span>
<a href="?page=4" rel="next">Older posts</a>
</nav>
Accessibility
navandaria-label- A navigation landmark named Pagination. If the same control appears above and below a list, give both the same name: they do the same job.
aria-current="page"- Read out as "current page", so a screen reader user knows where they are without seeing the highlight.
- Plain text for dead ends
- A missing Previous or Next is a
span, so there is nothing to click and nothing in the Tab order that leads nowhere. - Real links
- Every page is an
awith anhref, so the pages can be opened in a new tab, bookmarked and followed by search engines.