Pagination
On this page
Implementation guidelines
Basic Structure
<rh-pagination>must have a nested<ol>element with at least one nested<li>and<a>element.- Each
<a>element must have anhrefattribute that links to the corresponding page.
URL Structure Options
You can implement pagination URLs using any of these approaches:
Option 1: Hash fragments (recommended for client-side routing)
- Example:
example.redhat.com/search/#2,example.redhat.com/search/#3 - If using query parameters, ensure the hash comes after:
example.redhat.com/search/?q=test#2
Option 2: Query parameters
- Example:
example.redhat.com/search?page=2,example.redhat.com/search?page=3 - Can be combined with other query parameters:
example.redhat.com/search?q=test&page=2
Option 3: Path-based URLs
- Example:
example.redhat.com/search/page/2,example.redhat.com/search/page/3
Option 4: Manual control with aria-current
- Set
aria-current="page"on the current page's<a>element - Useful for server-side rendered pagination
How the Current Page is Determined
The component determines the active page in this order:
- Looking for an
aria-current="page"attribute on an<a>tag - Matching the full URL (pathname, search parameters, and hash) against each link's
href - If no match is found, the component logs a warning: "could not determine current link"
Importing
Add rh-pagination to your page with this import statement:
<script type="module">
import '@rhds/elements/rh-pagination/rh-pagination.js';
</script>
Copy to Clipboard
Copied!
Wrap lines
Overflow lines
To learn more about installing RHDS elements on your site using an import map read our getting started docs.
Lightdom CSS
This element requires you to load "Lightdom CSS" stylesheets for styling deeply slotted elements.
Note
Replace /path/to/ with path to the CSS file, whether local or CDN.
<link rel="stylesheet" href="/path/to/rh-pagination/rh-pagination-lightdom.css">
Usage
<rh-pagination>
<ol>
<li><a href="?page=1">1</a></li>
<li><a href="?page=2">2</a></li>
<li><a href="?page=3">3</a></li>
<li><a href="?page=4">4</a></li>
<li><a href="?page=5">5</a></li>
</ol>
</rh-pagination>
<link rel="stylesheet" href="../rh-pagination-lightdom.css">
<script type="module">
import '@rhds/elements/rh-pagination/rh-pagination.js';
</script>
Copy to Clipboard
Copied!
Wrap lines
Overflow lines
rh-pagination
A paginator allows users to navigate between pages of related content.
| Slot Name | Summary | Description |
|---|---|---|
go-to-page |
"Go to page" text, defaults to "Page" |
|
out-of |
||
|
An ordered list of links |
| Attribute | DOM Property | Description | Type | Default |
|---|---|---|---|---|
overflow |
overflow |
Override |
|
|
label |
label |
Accessible label for the 'nav' element |
|
|
label-first |
labelFirst |
Accessible label for the 'first page' button |
|
|
label-previous |
labelPrevious |
Accessible label for the 'previous page' button |
|
|
label-next |
labelNext |
Accessible label for the 'next page' button |
|
|
label-last |
labelLast |
Accessible label for the 'last page' button |
|
|
size |
size |
Change pagination size to small |
|
|
variant |
variant |
"Open" variant |
|
|
| Method Name | Description |
|---|---|
first() |
Navigate to the first page |
prev() |
Navigate to the previous page |
next() |
Navigate to the next page |
last() |
Navigate to the last page |
go(page: 'first' | 'prev' | 'next' | 'last' | number) |
Navigate to a specific page |
| Part Name | Summary | Description |
|---|---|---|
numeric |
shared container for the numeric controls at all widths |
|
container |
pagination container |
|
numeric-middle |
container for the numeric control at medium screen widths |
|
numeric-end |
container for the numeric control at small and large screen widths |
| CSS Property | Description | Default |
|---|---|---|
--rh-color-icon-status-disabled |
—
|
|
--rh-pagination-stepper-color |
Sets the stepper color. |
var(--rh-color-gray-50, #707070)
|
--rh-pagination-background-focused |
Sets the disabled stepper color. |
—
|
--rh-pagination-accent-color |
Sets the outline color when the page input has focus. |
var(--rh-color-interactive-primary-default)
|
| Token | Summary | Copy |
|---|---|---|
--rh-length-3xl
|
|
|
--rh-space-xs
|
|
|
--rh-color-interactive-primary-hover
|
|
|
--rh-color-interactive-primary-visited-default
|
|
|
--rh-color-interactive-primary-visited-hover
|
|
|
--rh-color-surface-lighter
|
|
|
--rh-color-surface-dark
|
|
|
--rh-color-text-primary-on-dark
|
|
|
--rh-color-border-subtle-on-light
|
|
|
--rh-color-text-secondary-on-dark
|
|
|
--rh-font-family-heading
|
|
|
--rh-font-size-heading-xs
|
|
|
--rh-border-width-lg
|
|
|
--rh-color-border-interactive
|
|
|
--rh-space-2xl
|
|
|
--rh-length-2xl
|
|
|
--rh-length-4xl
|
|
|
--rh-color-surface-lightest
|
|
|
--rh-color-surface-darkest
|
|
|
--rh-color-border-subtle
|
|
|
--rh-color-gray-60
|
|
|
--rh-color-text-primary
|
|
|
--rh-color-interactive-primary-default
|
|
|
--rh-space-sm
|
|
|
--rh-space-md
|
|
|
--rh-color-red-60
|
|
|
--rh-color-red-40
|
|
|
--rh-font-size-body-text-md
|
|
|
--rh-border-width-sm
|
|
|
--rh-color-gray-50
|
|
|
--rh-color-gray-40
|
|
|
--rh-border-radius-default
|
|
|
--rh-border-width-md
|
|
|
--rh-space-lg
|
|
Other libraries
To learn more about our other libraries, visit this page.
Feedback
To give feedback about anything on this page, contact us.