View on GitHub

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" href="#" tabindex="-1" aria-disabled="true">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.

<nav aria-label="Page navigation example">
  <ul class="pagination justify-content-center">
    <li class="page-item disabled">
      <a class="page-link" href="#" tabindex="-1" aria-disabled="true">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>
<nav aria-label="Page navigation example">
  <ul class="pagination justify-content-end">
    <li class="page-item disabled">
      <a class="page-link" href="#" tabindex="-1" aria-disabled="true">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 behaviour

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" href="#" tabindex="-1" aria-disabled="true" aria-label="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>

Sass

Variables

$pagination-padding-y:              null;
$pagination-padding-x:              null;

$pagination-color:                  null;
$pagination-bg:                     $white;
$pagination-border-width:           $border-width;
$pagination-border-radius:          null;
$pagination-margin-y:               $spacer; // Boosted mod
$pagination-margin-start:           $spacer * .5;
$pagination-border-color:           transparent;

$pagination-focus-box-shadow:       $input-btn-focus-box-shadow;
$pagination-focus-color:            $link-color;
$pagination-focus-bg:               null;
$pagination-focus-outline:          $pagination-border-width solid $pagination-focus-color;

$pagination-hover-color:            $link-color;
$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-variable-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-border:     $pagination-active-item-bg;
// End mod

Mixins

@mixin pagination-size($padding-y, $padding-x, $font-size, $border-radius) {
  .page-link {
    padding: $padding-y $padding-x;
    @include font-size($font-size);
  }

  .page-item {
    @if $pagination-margin-start == (-$pagination-border-width) {
      &:first-child {
        .page-link {
          @include border-start-radius($border-radius);
        }
      }

      &:last-child {
        .page-link {
          @include border-end-radius($border-radius);
        }
      }
    } @else {
      //Add border-radius to all pageLinks in case they have left margin
      .page-link {
        @include 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;
  }
}