This cookbook pattern demonstrates the navigation pattern used to display pagination, where the user can move between pages of content such as search results.

Links to sets of pages in a paged listing

要求

The pagination pattern typically displays items in a row. To ensure that the pagination is understandable by people using a screenreader, we mark the items up as a list inside a <nav> element, and then use CSS to display the layout visually as a row.

Typically, the pagination component will be centered horizontally underneath the content.

Recipe

Download this example

Choices made

This pattern is laid out using flexbox — one flex container nested inside another. The <nav> element is designated a flex container in order that we can center the list inside using the justify-content 特性。

The list itself also becomes a flex container to lay the items out as a row. To space the items out we will use a margin on the flex items.

Alternative methods

Once the column-gap property has implementation in browsers this could be used instead of margins to space out the items.

.pagination {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  column-gap: 2px;
}
					

可访问性关注

We want to ensure that a person using a screenreader understands what this navigation does, and where they will go when clicking a link. To help with this we have added aria-label="pagination" on the <nav> 元素。

We have also added some additional content that would be read by a screenreader but is hidden visually, and set the aria-hidden attribute on the paging arrows.

The "See Also" section at the end of this document has links to related accessibility topics.

浏览器兼容性

The various layout methods have different browser support. See the charts below for details on basic support for the properties used.

The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.

Include the compat data for key properties you used, as in the example below which includes align-items.

justify-content

更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
Supported in Flex Layout Chrome 完整支持 52
完整支持 52
部分支持 29 注意事项
注意事项 Older versions of the specification treat absolute positioned children as though they are a 0 by 0 flex item. Later specification versions take the children out of the flow and set their positions based on align and justify properties. Chrome implements the new behavior beginning with Chrome 52.
完整支持 Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Edge 完整支持 12 Firefox 完整支持 20 注意事项
完整支持 20 注意事项
注意事项 Before Firefox 27, Firefox supported only single-line flexbox.
不支持 18 — 20 Disabled
Disabled From version 18 until version 20 (exclusive): this feature is behind the layout.css.flexbox.enabled preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
preference (needs to be set to ). To change preferences in Firefox, visit about:config.
IE 完整支持 11 Opera 完整支持 12.1 Safari 完整支持 9 WebView Android 完整支持 52
完整支持 52
部分支持 4.4 注意事项
注意事项 Older versions of the specification treat absolute positioned children as though they are a 0 by 0 flex item. Later specification versions take the children out of the flow and set their positions based on align and justify properties. Chrome implements the new behavior beginning with Chrome 52.
完整支持 Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Chrome Android 完整支持 52
完整支持 52
部分支持 29 注意事项
注意事项 Older versions of the specification treat absolute positioned children as though they are a 0 by 0 flex item. Later specification versions take the children out of the flow and set their positions based on align and justify properties. Chrome implements the new behavior beginning with Chrome 52.
完整支持 Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Firefox Android 完整支持 20 注意事项
完整支持 20 注意事项
注意事项 Before Firefox 27, Firefox supported only single-line flexbox.
不支持 18 — 20 Disabled
Disabled From version 18 until version 20 (exclusive): this feature is behind the layout.css.flexbox.enabled preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
preference (needs to be set to ). To change preferences in Firefox, visit about:config.
Opera Android 完整支持 12.1 Safari iOS 完整支持 9 Samsung Internet Android 完整支持 6.0
完整支持 6.0
部分支持 2.0 注意事项
注意事项 Older versions of the specification treat absolute positioned children as though they are a 0 by 0 flex item. Later specification versions take the children out of the flow and set their positions based on align and justify properties. Chrome implements the new behavior beginning with Chrome 52.
完整支持 Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Supported in Grid Layout Chrome 完整支持 57 Edge 完整支持 16 Firefox 完整支持 52 IE 不支持 No Opera 完整支持 44 Safari 完整支持 10.1 WebView Android 完整支持 57 Chrome Android 完整支持 52 Firefox Android 完整支持 52 Opera Android 完整支持 43 Safari iOS 完整支持 10.3 Samsung Internet Android 完整支持 6.2

图例

完整支持

完整支持

不支持

不支持

见实现注意事项。

见实现注意事项。

用户必须明确启用此特征。

用户必须明确启用此特征。

要求使用供应商前缀或不同名称。

要求使用供应商前缀或不同名称。

column-gap in Flex layout

更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
Supported in Flex Layout Chrome 完整支持 84 Edge 完整支持 84 Firefox 完整支持 63 IE 不支持 No Opera 完整支持 70 Safari 不支持 No WebView Android 完整支持 84 Chrome Android 完整支持 84 Firefox Android 完整支持 63 Opera Android 不支持 No Safari iOS 不支持 No Samsung Internet Android 不支持 No

图例

完整支持

完整支持

不支持

不支持

另请参阅

元数据

  • 最后修改:
  1. CSS
  2. CSS 参考
  3. Layout cookbook
  4. 指南
    1. Breadcrumb Navigation
    2. Card
    3. Center an element
    4. Column layouts
    5. Contribute a recipe
    6. Grid wrapper
    7. List group with badges
    8. Pagination
    9. Recipe: Media objects
    10. Split Navigation
    11. Sticky footers

Copyright  © 2014-2026 乐数软件    

工业和信息化部: 粤ICP备14079481号-1