Pagination
Documentation and examples for showing pagination to indicate a series of related content exists across multiple pages.
Overview
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"
.
<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="#">Next</a></li>
</ul>
</nav>
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.
<nav aria-label="Page navigation example with icons">
<ul class="pagination">
<li class="page-item"><a class="page-link" href="#" aria-label="Previous"></a></li>
<li class="page-item"><a class="page-link" href="#" aria-label="Next"></a></li>
</ul>
</nav>
Disabled and active states
Pagination links are customizable for different circumstances. Use .disabled
for links that appear un-clickable and .active
to indicate the current page.
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.
<nav aria-label="...">
<ul class="pagination">
<li class="page-item disabled">
<a class="page-link">Previous</a>
</li>
<li class="page-item"><a class="page-link" href="#">1</a></li>
<li class="page-item active" aria-current="page">
<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>
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.
<nav aria-label="...">
<ul class="pagination">
<li class="page-item disabled">
<span class="page-link">Previous</span>
</li>
<li class="page-item"><a class="page-link" href="#">1</a></li>
<li class="page-item active" aria-current="page">
<span class="page-link">2</span>
</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>
Alignment
Change the alignment of pagination components with flexbox utilities. For example, with .justify-content-center
:
<nav aria-label="Page navigation example">
<ul class="pagination justify-content-center">
<li class="page-item disabled">
<a class="page-link">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>
Or with .justify-content-end
:
<nav aria-label="Page navigation example">
<ul class="pagination justify-content-end">
<li class="page-item disabled">
<a class="page-link">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>
Responsive behavior
To avoid pagination wrapping or overflowing, we limit the number or pagination item to display depending on breakpoint.
<nav aria-label="Page navigation example">
<ul class="pagination">
<li class="page-item disabled"><a class="page-link">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="#">4</a></li>
<li class="page-item active" aria-current="page">
<a class="page-link" href="#">5</a>
</li>
<li class="page-item"><a class="page-link" href="#">6</a></li>
<li class="page-item"><a class="page-link" href="#">7</a></li>
<li class="page-item"><a class="page-link" href="#">8</a></li>
<li class="page-item"><a class="page-link" href="#">9</a></li>
<li class="page-item"><a class="page-link" href="#">10</a></li>
<li class="page-item"><a class="page-link" href="#" aria-label="Next"></a></li>
</ul>
</nav>
Dark variant
Added in v5.2.1
Add .pagination-dark
to the .pagination
for a dark variant.
<nav aria-label="Dark page navigation example">
<ul class="pagination pagination-dark">
<li class="page-item disabled">
<a class="page-link">Previous</a>
</li>
<li class="page-item active" aria-current="page">
<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>
CSS
Variables
Added in v5.2.0
As part of Boosted’s evolving CSS variables approach, pagination now uses local CSS variables on .pagination
for enhanced real-time customization. Values for the CSS variables are set via Sass, so Sass customization is still supported, too.
--#{$prefix}pagination-padding-x: #{$pagination-padding-x};
--#{$prefix}pagination-padding-y: #{$pagination-padding-y};
--#{$prefix}pagination-padding-end: #{$pagination-padding-end}; // Boosted mod
--#{$prefix}pagination-margin-y: #{$pagination-margin-y}; // Boosted mod
--#{$prefix}pagination-margin-x-first-last: #{$pagination-margin-x-first-last}; // Boosted mod
@include rfs($pagination-font-size, --#{$prefix}pagination-font-size);
--#{$prefix}pagination-font-weight: #{$font-weight-bold}; // Boosted mod
--#{$prefix}pagination-color: #{$pagination-color};
--#{$prefix}pagination-bg: #{$pagination-bg};
--#{$prefix}pagination-border-width: #{$pagination-border-width};
--#{$prefix}pagination-border-color: #{$pagination-border-color};
--#{$prefix}pagination-border-radius: #{$pagination-border-radius};
--#{$prefix}pagination-hover-color: #{$pagination-hover-color};
--#{$prefix}pagination-hover-bg: #{$pagination-hover-bg};
--#{$prefix}pagination-hover-border-color: #{$pagination-hover-border-color};
--#{$prefix}pagination-focus-color: #{$pagination-focus-color};
--#{$prefix}pagination-focus-bg: #{$pagination-focus-bg};
--#{$prefix}pagination-focus-box-shadow: #{$pagination-focus-box-shadow};
--#{$prefix}pagination-active-color: #{$pagination-active-color};
--#{$prefix}pagination-active-bg: #{$pagination-active-bg};
--#{$prefix}pagination-active-border-color: #{$pagination-active-border-color};
--#{$prefix}pagination-active-item-color: #{$pagination-active-item-color}; // Boosted mod
--#{$prefix}pagination-active-item-bg: #{$pagination-active-item-bg}; // Boosted mod
--#{$prefix}pagination-active-item-border-color: #{$pagination-active-item-border}; // Boosted mod
--#{$prefix}pagination-disabled-color: #{$pagination-disabled-color};
--#{$prefix}pagination-disabled-bg: #{$pagination-disabled-bg};
--#{$prefix}pagination-disabled-border-color: #{$pagination-disabled-border-color};
--#{$prefix}pagination-icon: #{$pagination-icon}; // Boosted mod
--#{$prefix}pagination-icon-size: #{$pagination-icon-size}; // Boosted mod
--#{$prefix}pagination-icon-width: #{$pagination-icon-width}; // Boosted mod
--#{$prefix}pagination-icon-height: #{$pagination-icon-height}; // Boosted mod
Customization through CSS variables can be seen on the .pagination-dark
modifier class where we override specific values without adding duplicate CSS selectors.
--#{$prefix}pagination-color: #{$pagination-dark-color}; // Boosted mod
--#{$prefix}pagination-bg: #{$pagination-dark-bg}; // Boosted mod
--#{$prefix}pagination-border-color: #{$pagination-dark-border-color}; // Boosted mod
--#{$prefix}pagination-hover-color: #{$pagination-dark-hover-color}; // Boosted mod
--#{$prefix}pagination-hover-bg: #{$pagination-dark-hover-bg}; // Boosted mod
--#{$prefix}pagination-hover-border-color: #{$pagination-dark-hover-border-color}; // Boosted mod
--#{$prefix}pagination-focus-color: #{$pagination-dark-focus-color}; // Boosted mod
--#{$prefix}pagination-focus-bg: #{$pagination-dark-focus-bg}; // Boosted mod
--#{$prefix}pagination-active-color: #{$pagination-dark-active-color}; // Boosted mod
--#{$prefix}pagination-active-bg: #{$pagination-dark-active-bg}; // Boosted mod
--#{$prefix}pagination-active-border-color: #{$pagination-dark-active-border-color}; // Boosted mod
--#{$prefix}pagination-active-item-color: #{$pagination-dark-active-item-color}; // Boosted mod
--#{$prefix}pagination-active-item-bg: #{$pagination-dark-active-item-bg}; // Boosted mod
--#{$prefix}pagination-active-item-border-color: #{$pagination-dark-active-item-border-color}; // Boosted mod
--#{$prefix}pagination-disabled-color: #{$pagination-dark-disabled-color}; // Boosted mod
--#{$prefix}pagination-disabled-bg: #{$pagination-dark-disabled-bg}; // Boosted mod
--#{$prefix}pagination-disabled-border-color: #{$pagination-dark-disabled-border-color}; // Boosted mod
Sass variables
Variables for all paginations:
$pagination-padding-y: null;
$pagination-padding-x: null;
$pagination-font-size: $font-size-base;
$pagination-color: null;
$pagination-bg: $white;
$pagination-border-radius: null; // Boosted mod
$pagination-border-width: $border-width;
$pagination-margin-y: $spacer; // Boosted mod
$pagination-margin-start: 0; // Boosted mod
$pagination-margin-x-first-last: $spacer * .5; // Boosted mod
$pagination-border-color: transparent; // Boosted mod
$pagination-focus-color: null; // Boosted mod
$pagination-focus-bg: null; // Boosted mod
$pagination-focus-box-shadow: 0 0 0 $focus-visible-inner-width var(--#{$prefix}focus-visible-inner-color); // Boosted mod
$pagination-focus-outline: null; // Boosted mod
$pagination-hover-color: var(--#{$prefix}link-color); // Boosted mod
$pagination-hover-bg: null;
$pagination-hover-border-color: $gray-500;
$pagination-active-color: $white;
$pagination-active-bg: $black;
$pagination-active-border-color: $pagination-active-bg;
$pagination-disabled-color: $gray-500;
$pagination-disabled-bg: $white;
$pagination-disabled-border-color: $pagination-disabled-color;
$pagination-transition: $transition-focus;
// Boosted mod
$pagination-padding-end: 1.125rem;
$pagination-icon: var(--#{$boosted-prefix}chevron-icon);
$pagination-icon-size: subtract($spacer * 2, $border-width * 2);
$pagination-icon-width: add(.5rem, 1px);
$pagination-icon-height: subtract(1rem, 1px);
$pagination-active-item-bg: $primary;
$pagination-active-item-color: color-contrast($pagination-active-item-bg);
$pagination-active-item-border: $pagination-active-item-bg;
// End mod
Variables for the dark pagination:
// Boosted mod
$pagination-dark-bg: $black;
$pagination-dark-color: color-contrast($pagination-dark-bg);
$pagination-dark-border-color: transparent;
$pagination-dark-hover-bg: $black;
$pagination-dark-hover-color: color-contrast($pagination-dark-hover-bg);
$pagination-dark-hover-border-color: $gray-700;
$pagination-dark-focus-bg: $black;
$pagination-dark-focus-color: color-contrast($pagination-dark-focus-bg);
$pagination-dark-active-bg: $white;
$pagination-dark-active-color: color-contrast($pagination-dark-active-bg);
$pagination-dark-active-border-color: $white;
$pagination-dark-active-item-bg: $brand-orange;
$pagination-dark-active-item-color: color-contrast($pagination-dark-active-item-bg);
$pagination-dark-active-item-border-color: $brand-orange;
$pagination-dark-disabled-bg: $black;
$pagination-dark-disabled-color: $gray-700;
$pagination-dark-disabled-border-color: $gray-700;
// End mod
Sass mixins
@mixin pagination-size($padding-y, $padding-x, $font-size, $border-radius) {
--#{$prefix}pagination-padding-x: #{$padding-x};
--#{$prefix}pagination-padding-y: #{$padding-y};
@include rfs($font-size, --#{$prefix}pagination-font-size);
--#{$prefix}pagination-border-radius: #{$border-radius};
}
// Boosted mod
// Ensure we only display `n` items:
// - the first `n/2` items
// - the last `n/2` items
// - including the .active one (so maybe not the `n/2`th last item)
@mixin pagination-max-items($pagination-max-items) {
display: none;
&.active,
&:nth-child(-n+#{$pagination-max-items * .5}),
&:nth-last-child(-n+#{$pagination-max-items * .5}) {
display: list-item;
}
}