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".

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="#">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.

html
<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.

html
<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.

html
<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:

html
<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:

html
<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.

html
<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

Deprecated in v5.3.3

Heads up! Dark variants for components are deprecated in Boosted v5.3.3. They are replaced by our contextual dark mode.

Add data-bs-theme="dark" to the .pagination or any ancestor element to enable a component-specific color mode. Learn more about our color modes.

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};
// Boosted mod: no --#{$prefix}pagination-focus-color
// Boosted mod: no --#{$prefix}pagination-focus-bg
// Boosted mod: no --#{$prefix}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

Sass variables

$pagination-padding-y:              null; // Boosted mod: instead of `.375rem`
$pagination-padding-x:              null; // Boosted mod: instead of `.75rem`
// Boosted mod: no $pagination-padding-y-sm
// Boosted mod: no $pagination-padding-x-sm
// Boosted mod: no $pagination-padding-y-lg
// Boosted mod: no $pagination-padding-x-lg

$pagination-font-size:              $font-size-base;

$pagination-color:                  inherit; // Boosted mod: instead of `var(--#{$prefix}link-color)`
$pagination-bg:                     transparent; // Boosted mod: instead of `var(--#{$prefix}body-bg)`
$pagination-border-radius:          var(--#{$prefix}border-radius);
$pagination-border-width:           var(--#{$prefix}border-width);
$pagination-margin-y:               $spacer; // Boosted mod
$pagination-margin-start:           0; // Boosted mod: instead of `calc($pagination-border-width * -1)`
$pagination-margin-x-first-last:    $spacer * .5; // Boosted mod
$pagination-border-color:           transparent; // Boosted mod: instead of `var(--#{$prefix}border-color)`

// Deprecated in v5.3.3
// fusv-disable
$pagination-focus-color:            null; // Boosted mod
$pagination-focus-bg:               null; // Boosted mod: instead of `var(--#{$prefix}secondary-bg)`
$pagination-focus-box-shadow:       0 0 0 $focus-visible-inner-width var(--#{$prefix}focus-visible-inner-color); // Boosted mod: no `$focus-ring-box-shadow`
$pagination-focus-outline:          null; // Boosted mod
// fusv-enable

$pagination-hover-color:            var(--#{$prefix}body-color); // Boosted mod: instead of `var(--#{$prefix}link-hover-color)`
$pagination-hover-bg:               var(--#{$prefix}secondary-bg); // Boosted mod: instead of `var(--#{$prefix}tertiary-bg)`
$pagination-hover-border-color:     $pagination-hover-bg; // Boosted mod: instead of `var(--#{$prefix}border-color)`

$pagination-active-color:           var(--#{$prefix}highlight-color); // Boosted mod: instead of `$component-active-color`
$pagination-active-bg:              var(--#{$prefix}highlight-bg); // Boosted mod: instead of `$component-active-bg`
$pagination-active-border-color:    $pagination-active-bg; // Boosted mod: instead of `$component-active-bg`

$pagination-disabled-color:         var(--#{$prefix}disabled-color); // Boosted mod: instead of `var(--#{$prefix}secondary-color)`
$pagination-disabled-bg:            transparent; // Boosted mod: instead of `var(--#{$prefix}secondary-bg)`
$pagination-disabled-border-color:  transparent; // Boosted mod: instead of `var(--#{$prefix}border-color)`

$pagination-transition:             $transition-focus; // Boosted mod: no color, bg-color, border-color, box-shadow

// Boosted mod: no $pagination-border-radius-sm
// Boosted mod: no $pagination-border-radius-lg

// Boosted mod
$pagination-padding-end:            1.125rem;
$pagination-icon:                   var(--#{$prefix}chevron-icon);
$pagination-icon-size:              subtract($spacer * 2, calc(var(--#{$prefix}border-width) * 2)); // stylelint-disable-line function-disallowed-list
$pagination-icon-width:             add(.5rem, 1px);
$pagination-icon-height:            subtract(1rem, 1px);

$pagination-active-item-bg:         $supporting-orange;
$pagination-active-item-color:      $black;
$pagination-active-item-border:     $pagination-active-item-bg;
// 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;
  }
}