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

Pagination - 图1

  1. <nav aria-label="Page navigation example">
  2. <ul class="pagination">
  3. <li class="page-item"><a class="page-link" href="#">Previous</a></li>
  4. <li class="page-item"><a class="page-link" href="#">1</a></li>
  5. <li class="page-item"><a class="page-link" href="#">2</a></li>
  6. <li class="page-item"><a class="page-link" href="#">3</a></li>
  7. <li class="page-item"><a class="page-link" href="#">Next</a></li>
  8. </ul>
  9. </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.

Pagination - 图2

  1. <nav aria-label="Page navigation example">
  2. <ul class="pagination">
  3. <li class="page-item">
  4. <a class="page-link" href="#" aria-label="Previous">
  5. <span aria-hidden="true">&laquo;</span>
  6. </a>
  7. </li>
  8. <li class="page-item"><a class="page-link" href="#">1</a></li>
  9. <li class="page-item"><a class="page-link" href="#">2</a></li>
  10. <li class="page-item"><a class="page-link" href="#">3</a></li>
  11. <li class="page-item">
  12. <a class="page-link" href="#" aria-label="Next">
  13. <span aria-hidden="true">&raquo;</span>
  14. </a>
  15. </li>
  16. </ul>
  17. </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.

Pagination - 图3

  1. <nav aria-label="...">
  2. <ul class="pagination">
  3. <li class="page-item disabled">
  4. <a class="page-link" href="#" tabindex="-1" aria-disabled="true">Previous</a>
  5. </li>
  6. <li class="page-item"><a class="page-link" href="#">1</a></li>
  7. <li class="page-item active" aria-current="page">
  8. <a class="page-link" href="#">2</a>
  9. </li>
  10. <li class="page-item"><a class="page-link" href="#">3</a></li>
  11. <li class="page-item">
  12. <a class="page-link" href="#">Next</a>
  13. </li>
  14. </ul>
  15. </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.

Pagination - 图4

  1. <nav aria-label="...">
  2. <ul class="pagination">
  3. <li class="page-item disabled">
  4. <span class="page-link">Previous</span>
  5. </li>
  6. <li class="page-item"><a class="page-link" href="#">1</a></li>
  7. <li class="page-item active" aria-current="page">
  8. <span class="page-link">2</span>
  9. </li>
  10. <li class="page-item"><a class="page-link" href="#">3</a></li>
  11. <li class="page-item">
  12. <a class="page-link" href="#">Next</a>
  13. </li>
  14. </ul>
  15. </nav>

Sizing

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

Pagination - 图5

  1. <nav aria-label="...">
  2. <ul class="pagination pagination-lg">
  3. <li class="page-item active" aria-current="page">
  4. <span class="page-link">1</span>
  5. </li>
  6. <li class="page-item"><a class="page-link" href="#">2</a></li>
  7. <li class="page-item"><a class="page-link" href="#">3</a></li>
  8. </ul>
  9. </nav>

Pagination - 图6

  1. <nav aria-label="...">
  2. <ul class="pagination pagination-sm">
  3. <li class="page-item active" aria-current="page">
  4. <span class="page-link">1</span>
  5. </li>
  6. <li class="page-item"><a class="page-link" href="#">2</a></li>
  7. <li class="page-item"><a class="page-link" href="#">3</a></li>
  8. </ul>
  9. </nav>

Alignment

Change the alignment of pagination components with flexbox utilities.

Pagination - 图7

  1. <nav aria-label="Page navigation example">
  2. <ul class="pagination justify-content-center">
  3. <li class="page-item disabled">
  4. <a class="page-link" href="#" tabindex="-1" aria-disabled="true">Previous</a>
  5. </li>
  6. <li class="page-item"><a class="page-link" href="#">1</a></li>
  7. <li class="page-item"><a class="page-link" href="#">2</a></li>
  8. <li class="page-item"><a class="page-link" href="#">3</a></li>
  9. <li class="page-item">
  10. <a class="page-link" href="#">Next</a>
  11. </li>
  12. </ul>
  13. </nav>

Pagination - 图8

  1. <nav aria-label="Page navigation example">
  2. <ul class="pagination justify-content-end">
  3. <li class="page-item disabled">
  4. <a class="page-link" href="#" tabindex="-1" aria-disabled="true">Previous</a>
  5. </li>
  6. <li class="page-item"><a class="page-link" href="#">1</a></li>
  7. <li class="page-item"><a class="page-link" href="#">2</a></li>
  8. <li class="page-item"><a class="page-link" href="#">3</a></li>
  9. <li class="page-item">
  10. <a class="page-link" href="#">Next</a>
  11. </li>
  12. </ul>
  13. </nav>

Sass

Variables

  1. $pagination-padding-y: .375rem;
  2. $pagination-padding-x: .75rem;
  3. $pagination-padding-y-sm: .25rem;
  4. $pagination-padding-x-sm: .5rem;
  5. $pagination-padding-y-lg: .75rem;
  6. $pagination-padding-x-lg: 1.5rem;
  7. $pagination-color: $link-color;
  8. $pagination-bg: $white;
  9. $pagination-border-width: $border-width;
  10. $pagination-border-radius: $border-radius;
  11. $pagination-margin-start: -$pagination-border-width;
  12. $pagination-border-color: $gray-300;
  13. $pagination-focus-color: $link-hover-color;
  14. $pagination-focus-bg: $gray-200;
  15. $pagination-focus-box-shadow: $input-btn-focus-box-shadow;
  16. $pagination-focus-outline: 0;
  17. $pagination-hover-color: $link-hover-color;
  18. $pagination-hover-bg: $gray-200;
  19. $pagination-hover-border-color: $gray-300;
  20. $pagination-active-color: $component-active-color;
  21. $pagination-active-bg: $component-active-bg;
  22. $pagination-active-border-color: $pagination-active-bg;
  23. $pagination-disabled-color: $gray-600;
  24. $pagination-disabled-bg: $white;
  25. $pagination-disabled-border-color: $gray-300;
  26. $pagination-transition: color .15s ease-in-out, background-color .15s ease-in-out, border-color .15s ease-in-out, box-shadow .15s ease-in-out;
  27. $pagination-border-radius-sm: $border-radius-sm;
  28. $pagination-border-radius-lg: $border-radius-lg;

Mixins

  1. @mixin pagination-size($padding-y, $padding-x, $font-size, $border-radius) {
  2. .page-link {
  3. padding: $padding-y $padding-x;
  4. @include font-size($font-size);
  5. }
  6. .page-item {
  7. @if $pagination-margin-start == (-$pagination-border-width) {
  8. &:first-child {
  9. .page-link {
  10. @include border-start-radius($border-radius);
  11. }
  12. }
  13. &:last-child {
  14. .page-link {
  15. @include border-end-radius($border-radius);
  16. }
  17. }
  18. } @else {
  19. //Add border-radius to all pageLinks in case they have left margin
  20. .page-link {
  21. @include border-radius($border-radius);
  22. }
  23. }
  24. }
  25. }