pagination.md 6.54 KB
Newer Older
Mark Otto's avatar
Mark Otto committed
1
---
Mark Otto's avatar
Mark Otto committed
2
layout: docs
Mark Otto's avatar
Mark Otto committed
3
title: Pagination
Mark Otto's avatar
Mark Otto committed
4
description: Documentation and examples for showing pagination links.
5
group: components
Mark Otto's avatar
Mark Otto committed
6
7
---

Mark Otto's avatar
Mark Otto committed
8
Pagination links indicate a series of related content exists across multiple pages. Typically these are used where a multi-page approach to long lists of content improves general performance, such as in search results or inboxes.
Mark Otto's avatar
Mark Otto committed
9

Mark Otto's avatar
Mark Otto committed
10
11
12
13
14
## Contents

* Will be replaced with the ToC, excluding the "Contents" header
{:toc}

Mark Otto's avatar
Mark Otto committed
15
## Overview
Mark Otto's avatar
Mark Otto committed
16

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
We use a large block of connected links for our pagination, making links hard to miss and easily scalable—all while providing large hit areas. Pagination is built with list HTML elements so screen readers can announce the number of available links. Use a wrapping `<nav>` element to identify it as a navigation section to screen readers and other assistive technologies.

In addition, as pages likely have more than one such navigation section, it's advisable to provide a descriptive `aria-label` for the `<nav>` to reflect its purpose. For example, if the pagination component is used to navigate between a set of search results, an appropriate label could be `aria-label="Search results pages"`.

{% example html %}
<nav aria-label="Page navigation example">
  <ul class="pagination">
    <li class="page-item"><a class="page-link" href="#">Previous</a></li>
    <li class="page-item"><a class="page-link" href="#">1</a></li>
    <li class="page-item"><a class="page-link" href="#">2</a></li>
    <li class="page-item"><a class="page-link" href="#">3</a></li>
    <li class="page-item"><a class="page-link" href="#">Next</a></li>
  </ul>
</nav>
{% endexample %}
Mark Otto's avatar
Mark Otto committed
32

Mark Otto's avatar
Mark Otto committed
33
34
35
36
## Working with icons

Looking to use an icon or symbol in place of text for some pagination links? Be sure to provide proper screen reader support with `aria` attributes and the `.sr-only` utility.

Mark Otto's avatar
Mark Otto committed
37
{% example html %}
Mark Otto's avatar
Mark Otto committed
38
<nav aria-label="Page navigation example">
Mark Otto's avatar
Mark Otto committed
39
  <ul class="pagination">
Chris Rebert's avatar
Chris Rebert committed
40
    <li class="page-item">
Chris Rebert's avatar
Chris Rebert committed
41
      <a class="page-link" href="#" aria-label="Previous">
Mark Otto's avatar
Mark Otto committed
42
43
44
45
        <span aria-hidden="true">&laquo;</span>
        <span class="sr-only">Previous</span>
      </a>
    </li>
Chris Rebert's avatar
Chris Rebert committed
46
47
48
49
    <li class="page-item"><a class="page-link" href="#">1</a></li>
    <li class="page-item"><a class="page-link" href="#">2</a></li>
    <li class="page-item"><a class="page-link" href="#">3</a></li>
    <li class="page-item">
Chris Rebert's avatar
Chris Rebert committed
50
      <a class="page-link" href="#" aria-label="Next">
Mark Otto's avatar
Mark Otto committed
51
52
53
54
        <span aria-hidden="true">&raquo;</span>
        <span class="sr-only">Next</span>
      </a>
    </li>
Mark Otto's avatar
Mark Otto committed
55
56
  </ul>
</nav>
Mark Otto's avatar
Mark Otto committed
57
{% endexample %}
Mark Otto's avatar
Mark Otto committed
58

Mark Otto's avatar
Mark Otto committed
59
## Disabled and active states
Mark Otto's avatar
Mark Otto committed
60

61
Pagination links are customizable for different circumstances. Use `.disabled` for links that appear un-clickable and `.active` to indicate the current page.
Mark Otto's avatar
Mark Otto committed
62

63
While the `.disabled` class uses `pointer-events: none` to _try_ to disable the link functionality of `<a>`s, that CSS property is not yet standardized and doesn't account for keyboard navigation. As such, you should always add `tabindex="-1"` on disabled links and use custom JavaScript to fully disable their functionality.
64

Mark Otto's avatar
Mark Otto committed
65
{% example html %}
66
<nav aria-label="...">
Mark Otto's avatar
Mark Otto committed
67
  <ul class="pagination">
Chris Rebert's avatar
Chris Rebert committed
68
    <li class="page-item disabled">
69
      <a class="page-link" href="#" tabindex="-1">Previous</a>
Mark Otto's avatar
Mark Otto committed
70
    </li>
71
    <li class="page-item"><a class="page-link" href="#">1</a></li>
Chris Rebert's avatar
Chris Rebert committed
72
    <li class="page-item active">
73
      <a class="page-link" href="#">2 <span class="sr-only">(current)</span></a>
Mark Otto's avatar
Mark Otto committed
74
    </li>
Chris Rebert's avatar
Chris Rebert committed
75
76
    <li class="page-item"><a class="page-link" href="#">3</a></li>
    <li class="page-item">
77
      <a class="page-link" href="#">Next</a>
Mark Otto's avatar
Mark Otto committed
78
    </li>
Mark Otto's avatar
Mark Otto committed
79
80
  </ul>
</nav>
Mark Otto's avatar
Mark Otto committed
81
82
{% endexample %}

83
You can optionally swap out active or disabled anchors for `<span>`, or omit the anchor in the case of the prev/next arrows, to remove click functionality and prevent keyboard focus while retaining intended styles.
Mark Otto's avatar
Mark Otto committed
84

85
{% example html %}
86
<nav aria-label="...">
Mark Otto's avatar
Mark Otto committed
87
  <ul class="pagination">
Chris Rebert's avatar
Chris Rebert committed
88
    <li class="page-item disabled">
89
90
91
92
93
94
95
      <span class="page-link">Previous</span>
    </li>
    <li class="page-item"><a class="page-link" href="#">1</a></li>
    <li class="page-item active">
      <span class="page-link">
        2
        <span class="sr-only">(current)</span>
Mark Otto's avatar
Mark Otto committed
96
97
      </span>
    </li>
98
99
100
101
    <li class="page-item"><a class="page-link" href="#">3</a></li>
    <li class="page-item">
      <a class="page-link" href="#">Next</a>
    </li>
Mark Otto's avatar
Mark Otto committed
102
103
  </ul>
</nav>
104
{% endexample %}
Mark Otto's avatar
Mark Otto committed
105

Mark Otto's avatar
Mark Otto committed
106
## Sizing
Mark Otto's avatar
Mark Otto committed
107
108
109
110

Fancy larger or smaller pagination? Add `.pagination-lg` or `.pagination-sm` for additional sizes.

{% example html %}
111
<nav aria-label="...">
Mark Otto's avatar
Mark Otto committed
112
  <ul class="pagination pagination-lg">
Mark Otto's avatar
Mark Otto committed
113
114
    <li class="page-item disabled">
      <a class="page-link" href="#" tabindex="-1">Previous</a>
Mark Otto's avatar
Mark Otto committed
115
    </li>
Chris Rebert's avatar
Chris Rebert committed
116
117
118
119
    <li class="page-item"><a class="page-link" href="#">1</a></li>
    <li class="page-item"><a class="page-link" href="#">2</a></li>
    <li class="page-item"><a class="page-link" href="#">3</a></li>
    <li class="page-item">
Mark Otto's avatar
Mark Otto committed
120
      <a class="page-link" href="#">Next</a>
Mark Otto's avatar
Mark Otto committed
121
    </li>
Mark Otto's avatar
Mark Otto committed
122
123
  </ul>
</nav>
Mark Otto's avatar
Mark Otto committed
124
125
126
{% endexample %}

{% example html %}
127
<nav aria-label="...">
Mark Otto's avatar
Mark Otto committed
128
  <ul class="pagination pagination-sm">
Mark Otto's avatar
Mark Otto committed
129
130
131
132
133
134
    <li class="page-item disabled">
      <a class="page-link" href="#" tabindex="-1">Previous</a>
    </li>
    <li class="page-item"><a class="page-link" href="#">1</a></li>
    <li class="page-item"><a class="page-link" href="#">2</a></li>
    <li class="page-item"><a class="page-link" href="#">3</a></li>
Chris Rebert's avatar
Chris Rebert committed
135
    <li class="page-item">
Mark Otto's avatar
Mark Otto committed
136
137
138
139
140
      <a class="page-link" href="#">Next</a>
    </li>
  </ul>
</nav>
{% endexample %}
141
142
143

## Alignment

Bardi Harborow's avatar
Bardi Harborow committed
144
Change the alignment of pagination components with [flexbox utilities]({{ site.baseurl }}/utilities/flexbox/).
145
146
147
148
149
150

{% example html %}
<nav aria-label="Page navigation example">
  <ul class="pagination justify-content-center">
    <li class="page-item disabled">
      <a class="page-link" href="#" tabindex="-1">Previous</a>
Mark Otto's avatar
Mark Otto committed
151
    </li>
Chris Rebert's avatar
Chris Rebert committed
152
153
154
155
    <li class="page-item"><a class="page-link" href="#">1</a></li>
    <li class="page-item"><a class="page-link" href="#">2</a></li>
    <li class="page-item"><a class="page-link" href="#">3</a></li>
    <li class="page-item">
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
      <a class="page-link" href="#">Next</a>
    </li>
  </ul>
</nav>
{% endexample %}

{% example html %}
<nav aria-label="Page navigation example">
  <ul class="pagination justify-content-end">
    <li class="page-item disabled">
      <a class="page-link" href="#" tabindex="-1">Previous</a>
    </li>
    <li class="page-item"><a class="page-link" href="#">1</a></li>
    <li class="page-item"><a class="page-link" href="#">2</a></li>
    <li class="page-item"><a class="page-link" href="#">3</a></li>
    <li class="page-item">
      <a class="page-link" href="#">Next</a>
Mark Otto's avatar
Mark Otto committed
173
    </li>
Mark Otto's avatar
Mark Otto committed
174
175
  </ul>
</nav>
Mark Otto's avatar
Mark Otto committed
176
{% endexample %}