Pagination
<wa-pagination>
Pagination splits long lists of content into pages, letting users navigate between them.
Set total and page-size to generate numbered page buttons with previous and next controls. Use the label attribute to give the control an accessible name, which is especially helpful when more than one appears on the same page.
Pagination is a navigation control, not a form control.
It tracks the current page and emits events, but it doesn't submit a value with a form. Keep page in sync with your data by updating it in response to the wa-page-change event.
Examples
Appearance
Set the appearance attribute to change the pagination's visual style. Valid appearances are outlined (the default), filled, and plain.
Size
Pagination has no size attribute; set font-size on the control or any ancestor to scale it.
Number of Buttons
Use the sibling-count attribute to set how many pages show on each side of the current page (defaults to 2), and boundary-count to set how many show at the start and end (defaults to 1). Remaining pages collapse into an ellipsis, which jumps several pages toward that side when activated.
First and Last Buttons
Add the with-edges attribute to show buttons that jump to the first and last pages.
Previous and Next Buttons
Add the without-nav attribute to hide the previous and next buttons, leaving only the page numbers.
Summary
Add the with-summary attribute to show a summary of the items on the current page.
Compact
Set the format attribute to compact to replace the page numbers with a short "1 of 5" label between the previous and next buttons.
The compact format can be combined with other features, such as with-summary:
Custom Icons
Use the previous-icon, next-icon, first-icon, and last-icon slots to replace the default navigation icons.
Replacing an icon doesn't replace its label.
The navigation buttons keep their built-in accessible labels, so screen readers still announce them correctly.
Disabled
Add the disabled attribute to disable the entire pagination control.
Single Page
Add the hide-single-page attribute to render nothing when there's only one page of results. Since a single page renders nothing, this example is shown as code rather than a live preview.
<wa-pagination total="5" page-size="10" hide-single-page></wa-pagination>
Page Size Selector
Pair a select with the pagination control to let users change the page size. Update page-size when the selection changes, and reset to the first page.
Responding to Page Changes
When the user changes the page, the wa-page-change event is emitted with { page, pageSize } in event.detail. Update the page property to reflect the new page and load the corresponding data.
Setting the Page Programmatically
Set the page property to any valid page to change the current page without user interaction. Setting page directly doesn't emit wa-page-change.
Preventing a Page Change
Call event.preventDefault() on the wa-before-page-change event to cancel a page change, such as to guard against unsaved changes.
Rendering Links Instead of Buttons
Set the href-template attribute to render page items as links instead of buttons, using {page} as a placeholder for the page number. Every control links through the template, which works well for server-rendered pages.
In JavaScript, you can also set the hrefTemplate property to a function that receives the page number and returns the URL. This is handy when the URL doesn't follow a simple substitution. When server-rendering, set the href-template attribute to the closest equivalent as well, so the server and the browser render the same markup.
In link mode, the component navigates instead of updating itself.
Render it on the server with the correct page for each request. Disabled and boundary controls, such as previous on the first page, render as anchors with no href and aria-disabled set.
Customizing
Use the exported CSS parts to customize the pagination's appearance, where the button part targets every button at once. The plain appearance is a good starting point.
This example turns the control into a row of pill-shaped buttons, gives the navigation arrows a colorful circular treatment, and highlights the current page with a gradient and a soft glow.
Accessibility Considerations
Pagination ships with several accessibility behaviors built in:
- Page changes are announced. When the page changes, the new position is announced to screen readers through a shared live region, so the update isn't silent.
- Focus follows the page. After a control is activated, focus moves to the new current page rather than falling back to the top of the document, keeping keyboard users oriented.
- The current page is marked. The active page carries
aria-current="page", and disabled or boundary controls carryaria-disabledso assistive technology skips them. - Icons are direction-aware. The previous, next, first, and last icons flip automatically in right-to-left languages.
Give the control an accessible name with the label attribute whenever more than one pagination appears on a page, so screen reader users can tell them apart.
API
Importing
If you're using the autoloader or a hosted project, components load on demand — no manual import needed. To cherry-pick a component manually, use one of the following snippets.
Import this component directly from the CDN:
import 'https://ka-f.webawesome.com/[email protected]/components/pagination/pagination.js';
After installing Web Awesome via npm, import this component:
import '@awesome.me/webawesome/dist/components/pagination/pagination.js';
If you're self-hosting Web Awesome, import this component from your server:
import './webawesome/dist/components/pagination/pagination.js';
To import this component for React 18 or below, use the following code:
import WaPagination from '@awesome.me/webawesome/dist/react/pagination/index.js';
Slots
Learn more about using slots.
| Name | Description |
|---|---|
first-icon
|
An icon to use in lieu of the default first icon. |
last-icon
|
An icon to use in lieu of the default last icon. |
next-icon
|
An icon to use in lieu of the default next icon. |
previous-icon
|
An icon to use in lieu of the default previous icon. |
Attributes & Properties
Learn more about attributes and properties.
| Name | Description | Reflects |
|---|---|---|
appearanceappearance |
The pagination's visual appearance.
Type
'outlined' | 'filled' | 'plain'
Default
'outlined'
|
|
boundaryCountboundary-count |
The number of pages to always show at the start and end.
Type
number
Default
1
|
|
disableddisabled |
Disables the pagination.
Type
boolean
Default
false
|
|
formatformat |
The pagination's layout. The default
standard format shows the full page list with ellipses; compact collapses
it into a short "1 of 5" label flanked by the previous and next buttons, useful in tight spaces like toolbars and
cards.
Type
'standard' | 'compact'
Default
'standard'
|
|
hideSinglePagehide-single-page |
Renders nothing when there's only one page.
Type
boolean
Default
false
|
|
hrefTemplatehref-template |
A URL template used to render page items as links instead of buttons. When set, items render as
<a> elements for
SSR, SEO, and no-JS support. Provide a string with {page} as a placeholder for the page number, e.g.
/products?page={page}. In JavaScript, you can also assign a function that receives the page number and returns
the URL, e.g. el.hrefTemplate = page => \/products?page=${page}``.
Type
string | ((page: number) => string)
Default
''
|
|
labellabel |
A label that describes the pagination to assistive devices. This won't be shown on the screen, but it will be
announced by screen readers. Especially useful when more than one pagination control exists on the same page.
Type
string
Default
''
|
|
pagepage |
The current page, starting at 1.
Type
number
Default
1
|
|
pageSizepage-size |
The number of items shown per page.
Type
number
Default
10
|
|
siblingCountsibling-count |
The number of pages to show on each side of the current page.
Type
number
Default
2
|
|
totaltotal |
The total number of items to paginate.
Type
number
Default
0
|
|
totalPages |
The total number of pages, derived from
total and pageSize. |
|
withEdgeswith-edges |
Shows buttons that jump to the first and last pages.
Type
boolean
Default
false
|
|
withoutNavwithout-nav |
Hides the previous and next buttons.
Type
boolean
Default
false
|
|
withSummarywith-summary |
Shows a summary of the items on the current page, e.g. "1–10 of 237".
Type
boolean
Default
false
|
Events
Learn more about events.
| Name | Description |
|---|---|
wa-before-page-change |
Emitted when the page is about to change but before it does. Canceling this event with event.preventDefault() prevents the page from changing. |
wa-page-change |
Emitted after the page changes. |
Custom States
Learn more about custom states.
| Name | Description | CSS selector |
|---|---|---|
disabled |
Applied when the pagination is disabled. |
:state(disabled)
|
CSS Parts
Learn more about CSS parts.
| Name | Description | CSS selector |
|---|---|---|
button |
Every button or link, including page numbers and navigation controls. |
::part(button)
|
ellipsis |
An ellipsis for collapsed pages. Acts as a button that jumps several pages toward that side. |
::part(ellipsis)
|
first-button |
The first button. |
::part(first-button)
|
label |
The "1 of 5" label shown between the navigation buttons in the compact layout. |
::part(label)
|
last-button |
The last button. |
::part(last-button)
|
next-button |
The next button. |
::part(next-button)
|
page |
A page number button or link. |
::part(page)
|
page-current |
The current page number button or link. |
::part(page-current)
|
pages |
The list that wraps the page number items. |
::part(pages)
|
pagination |
The component's outer wrapper, a <nav> element. |
::part(pagination)
|
previous-button |
The previous button. |
::part(previous-button)
|
summary |
The summary of items on the current page, shown with the with-summary attribute. |
::part(summary)
|
base |
Deprecated. Use the pagination part instead. |
::part(base)
|
Dependencies
This component automatically imports the following elements. Sub-dependencies, if any exist, will also be included in this list.