pagination.md 5.94 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
4
group: components
Mark Otto's avatar
Mark Otto committed
5
6
---

7
Provide pagination links for your site or app with the multi-page pagination component, or the simpler [pager alternative](#pager).
Mark Otto's avatar
Mark Otto committed
8

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

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

Mark Otto's avatar
Mark Otto committed
14
15
16
17
18
## Default pagination

Simple pagination inspired by Rdio, great for apps and search results. The large block is hard to miss, easily scalable, and provides large click areas.

{% example html %}
Mark Otto's avatar
Mark Otto committed
19
20
<nav>
  <ul class="pagination">
Chris Rebert's avatar
Chris Rebert committed
21
    <li class="page-item">
Chris Rebert's avatar
Chris Rebert committed
22
      <a class="page-link" href="#" aria-label="Previous">
Mark Otto's avatar
Mark Otto committed
23
24
25
26
        <span aria-hidden="true">&laquo;</span>
        <span class="sr-only">Previous</span>
      </a>
    </li>
Chris Rebert's avatar
Chris Rebert committed
27
28
29
30
31
32
    <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="#">4</a></li>
    <li class="page-item"><a class="page-link" href="#">5</a></li>
    <li class="page-item">
Chris Rebert's avatar
Chris Rebert committed
33
      <a class="page-link" href="#" aria-label="Next">
Mark Otto's avatar
Mark Otto committed
34
35
36
37
        <span aria-hidden="true">&raquo;</span>
        <span class="sr-only">Next</span>
      </a>
    </li>
Mark Otto's avatar
Mark Otto committed
38
39
  </ul>
</nav>
Mark Otto's avatar
Mark Otto committed
40
{% endexample %}
Mark Otto's avatar
Mark Otto committed
41

Mark Otto's avatar
Mark Otto committed
42
43
44
45
### Disabled and active states

Links are customizable for different circumstances. Use `.disabled` for unclickable links and `.active` to indicate the current page.

46
47
48
{% callout warning %}
#### Link functionality caveat

49
The `.disabled` class uses `pointer-events: none` to try to disable the link functionality of `<a>`s, but that CSS property is not yet standardized. In addition, even in browsers that do support `pointer-events: none`, keyboard navigation remains unaffected, meaning that sighted keyboard users and users of assistive technologies will still be able to activate these links. So to be safe, add a `tabindex="-1"` attribute on these links (to prevent them from receiving keyboard focus) and use custom JavaScript to disable their functionality.
50
51
52
{% endcallout %}


Mark Otto's avatar
Mark Otto committed
53
{% example html %}
Mark Otto's avatar
Mark Otto committed
54
55
<nav>
  <ul class="pagination">
Chris Rebert's avatar
Chris Rebert committed
56
    <li class="page-item disabled">
57
      <a class="page-link" href="#" tabindex="-1" aria-label="Previous">
Mark Otto's avatar
Mark Otto committed
58
59
60
61
        <span aria-hidden="true">&laquo;</span>
        <span class="sr-only">Previous</span>
      </a>
    </li>
Chris Rebert's avatar
Chris Rebert committed
62
    <li class="page-item active">
Chris Rebert's avatar
Chris Rebert committed
63
      <a class="page-link" href="#">1 <span class="sr-only">(current)</span></a>
Mark Otto's avatar
Mark Otto committed
64
    </li>
Chris Rebert's avatar
Chris Rebert committed
65
66
67
68
69
    <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="#">4</a></li>
    <li class="page-item"><a class="page-link" href="#">5</a></li>
    <li class="page-item">
Chris Rebert's avatar
Chris Rebert committed
70
      <a class="page-link" href="#" aria-label="Next">
Mark Otto's avatar
Mark Otto committed
71
72
73
74
        <span aria-hidden="true">&raquo;</span>
        <span class="sr-only">Next</span>
      </a>
    </li>
Mark Otto's avatar
Mark Otto committed
75
76
  </ul>
</nav>
Mark Otto's avatar
Mark Otto committed
77
78
{% endexample %}

79
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
80

81
{% example html %}
Mark Otto's avatar
Mark Otto committed
82
83
<nav>
  <ul class="pagination">
Chris Rebert's avatar
Chris Rebert committed
84
    <li class="page-item disabled">
Chris Rebert's avatar
Chris Rebert committed
85
      <span class="page-link" aria-label="Previous">
Mark Otto's avatar
Mark Otto committed
86
87
88
89
        <span aria-hidden="true">&laquo;</span>
        <span class="sr-only">Previous</span>
      </span>
    </li>
Chris Rebert's avatar
Chris Rebert committed
90
    <li class="page-item active"><span class="page-link">1 <span class="sr-only">(current)</span></span></li>
Mark Otto's avatar
Mark Otto committed
91
92
  </ul>
</nav>
93
{% endexample %}
Mark Otto's avatar
Mark Otto committed
94
95


Mark Otto's avatar
Mark Otto committed
96
97
98
99
100
### Sizing

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

{% example html %}
Mark Otto's avatar
Mark Otto committed
101
102
<nav>
  <ul class="pagination pagination-lg">
Chris Rebert's avatar
Chris Rebert committed
103
    <li class="page-item">
Chris Rebert's avatar
Chris Rebert committed
104
      <a class="page-link" href="#" aria-label="Previous">
Mark Otto's avatar
Mark Otto committed
105
106
107
108
        <span aria-hidden="true">&laquo;</span>
        <span class="sr-only">Previous</span>
      </a>
    </li>
Chris Rebert's avatar
Chris Rebert committed
109
110
111
112
    <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
113
      <a class="page-link" href="#" aria-label="Next">
Mark Otto's avatar
Mark Otto committed
114
115
116
117
        <span aria-hidden="true">&raquo;</span>
        <span class="sr-only">Next</span>
      </a>
    </li>
Mark Otto's avatar
Mark Otto committed
118
119
  </ul>
</nav>
Mark Otto's avatar
Mark Otto committed
120
121
122
{% endexample %}

{% example html %}
Mark Otto's avatar
Mark Otto committed
123
124
<nav>
  <ul class="pagination pagination-sm">
Chris Rebert's avatar
Chris Rebert committed
125
    <li class="page-item">
Chris Rebert's avatar
Chris Rebert committed
126
      <a class="page-link" href="#" aria-label="Previous">
Mark Otto's avatar
Mark Otto committed
127
128
129
130
        <span aria-hidden="true">&laquo;</span>
        <span class="sr-only">Previous</span>
      </a>
    </li>
Chris Rebert's avatar
Chris Rebert committed
131
132
133
134
    <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
135
      <a class="page-link" href="#" aria-label="Next">
Mark Otto's avatar
Mark Otto committed
136
137
138
139
        <span aria-hidden="true">&raquo;</span>
        <span class="sr-only">Next</span>
      </a>
    </li>
Mark Otto's avatar
Mark Otto committed
140
141
  </ul>
</nav>
Mark Otto's avatar
Mark Otto committed
142
{% endexample %}
Mark Otto's avatar
Mark Otto committed
143

Mark Otto's avatar
Mark Otto committed
144
## Pager
Mark Otto's avatar
Mark Otto committed
145

Mark Otto's avatar
Mark Otto committed
146
Quick previous and next links for simple pagination implementations with light markup and styles. It's great for simple sites like blogs or magazines.
Mark Otto's avatar
Mark Otto committed
147

Mark Otto's avatar
Mark Otto committed
148
149
150
151
152
### Default example

By default, the pager centers links.

{% example html %}
Mark Otto's avatar
Mark Otto committed
153
154
155
156
157
158
<nav>
  <ul class="pager">
    <li><a href="#">Previous</a></li>
    <li><a href="#">Next</a></li>
  </ul>
</nav>
Mark Otto's avatar
Mark Otto committed
159
{% endexample %}
Mark Otto's avatar
Mark Otto committed
160

Mark Otto's avatar
Mark Otto committed
161
162
163
164
165
### Aligned links

Alternatively, you can align each link to the sides:

{% example html %}
Mark Otto's avatar
Mark Otto committed
166
167
<nav>
  <ul class="pager">
168
169
    <li class="pager-prev"><a href="#">Older</a></li>
    <li class="pager-next"><a href="#">Newer</a></li>
Mark Otto's avatar
Mark Otto committed
170
171
  </ul>
</nav>
Mark Otto's avatar
Mark Otto committed
172
173
174
175
{% endexample %}


### Optional disabled state
Mark Otto's avatar
Mark Otto committed
176

177
Pager links also support the `.disabled` class (though note that the same advice about keyboard focus as for the default pagination applies here as well).
Mark Otto's avatar
Mark Otto committed
178

179
{% example html %}
Mark Otto's avatar
Mark Otto committed
180
181
<nav>
  <ul class="pager">
182
    <li class="pager-prev disabled"><a href="#" tabindex="-1">Older</a></li>
183
    <li class="pager-next"><a href="#">Newer</a></li>
Mark Otto's avatar
Mark Otto committed
184
185
  </ul>
</nav>
186
{% endexample %}