ナビゲーション

v2.1.0
ナビゲーション

ページネーション

長い一覧を分割したページへのリンクを横一列に表示し、現在のページは押し込まれた状態で示します。

このページの内容

ページネーションは、長い一覧を分割した各ページへのリンクを <nav> の中に横一列に並べます。リンクには控えめな正方形のボタンを使います。現在のページには aria-current="page" を指定し、押されたトグルのようにくぼんだ状態で表示します。スタイルシートは、リンクの横並びと途中のページを省略するための表示を用意しています。ガイドの章のように、タイトルがあり順に読むページにはページャーを使います。

ページネーション

<nav aria-label="Pagination">  <ol class="pagination">    <li>      <a class="btn btn-quiet btn-square btn-sm" href="#page-1" aria-label="Previous page">        <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">          <path d="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" transform="rotate(180 8 8)" />        </svg>      </a>    </li>    <li><a class="btn btn-quiet btn-square btn-sm" href="#page-1" aria-label="Page 1">1</a></li>    <li>      <a class="btn btn-quiet btn-square btn-sm" href="#page-2" aria-label="Page 2" aria-current="page">        2      </a>    </li>    <li><a class="btn btn-quiet btn-square btn-sm" href="#page-3" aria-label="Page 3">3</a></li>    <li class="pagination-gap" aria-hidden="true">…</li>    <li><a class="btn btn-quiet btn-square btn-sm" href="#page-24" aria-label="Page 24">24</a></li>    <li>      <a class="btn btn-quiet btn-square btn-sm" href="#page-3" aria-label="Next page">        <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">          <path d="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" />        </svg>      </a>    </li>  </ol></nav>
import ChevronLeftIcon from '@master/icons-react/native/16/soft/chevron-left'import ChevronRightIcon from '@master/icons-react/native/16/soft/chevron-right'<nav aria-label="Pagination">  <ol className="pagination">    <li>      <a className="btn btn-quiet btn-square btn-sm" href="#page-1" aria-label="Previous page">        <ChevronLeftIcon className="icon" />      </a>    </li>    <li><a className="btn btn-quiet btn-square btn-sm" href="#page-1" aria-label="Page 1">1</a></li>    <li>      <a className="btn btn-quiet btn-square btn-sm" href="#page-2" aria-label="Page 2" aria-current="page">        2      </a>    </li>    <li><a className="btn btn-quiet btn-square btn-sm" href="#page-3" aria-label="Page 3">3</a></li>    <li className="pagination-gap" aria-hidden="true">…</li>    <li>      <a className="btn btn-quiet btn-square btn-sm" href="#page-24" aria-label="Page 24">24</a>    </li>    <li>      <a className="btn btn-quiet btn-square btn-sm" href="#page-3" aria-label="Next page">        <ChevronRightIcon className="icon" />      </a>    </li>  </ol></nav>
<script>  import ChevronLeftIcon from '@master/icons-svelte/native/16/soft/chevron-left'  import ChevronRightIcon from '@master/icons-svelte/native/16/soft/chevron-right'</script><nav aria-label="Pagination">  <ol class="pagination">    <li>      <a class="btn btn-quiet btn-square btn-sm" href="#page-1" aria-label="Previous page">        <ChevronLeftIcon class="icon" />      </a>    </li>    <li><a class="btn btn-quiet btn-square btn-sm" href="#page-1" aria-label="Page 1">1</a></li>    <li>      <a class="btn btn-quiet btn-square btn-sm" href="#page-2" aria-label="Page 2" aria-current="page">        2      </a>    </li>    <li><a class="btn btn-quiet btn-square btn-sm" href="#page-3" aria-label="Page 3">3</a></li>    <li class="pagination-gap" aria-hidden="true">…</li>    <li><a class="btn btn-quiet btn-square btn-sm" href="#page-24" aria-label="Page 24">24</a></li>    <li>      <a class="btn btn-quiet btn-square btn-sm" href="#page-3" aria-label="Next page">        <ChevronRightIcon class="icon" />      </a>    </li>  </ol></nav>
<script setup>import ChevronLeftIcon from '@master/icons-vue/native/16/soft/chevron-left'import ChevronRightIcon from '@master/icons-vue/native/16/soft/chevron-right'</script><template>  <nav aria-label="Pagination">    <ol class="pagination">      <li>        <a class="btn btn-quiet btn-square btn-sm" href="#page-1" aria-label="Previous page">          <ChevronLeftIcon class="icon" />        </a>      </li>      <li><a class="btn btn-quiet btn-square btn-sm" href="#page-1" aria-label="Page 1">1</a></li>      <li>        <a class="btn btn-quiet btn-square btn-sm" href="#page-2" aria-label="Page 2" aria-current="page">          2        </a>      </li>      <li><a class="btn btn-quiet btn-square btn-sm" href="#page-3" aria-label="Page 3">3</a></li>      <li class="pagination-gap" aria-hidden="true">…</li>      <li>        <a class="btn btn-quiet btn-square btn-sm" href="#page-24" aria-label="Page 24">24</a>      </li>      <li>        <a class="btn btn-quiet btn-square btn-sm" href="#page-3" aria-label="Next page">          <ChevronRightIcon class="icon" />        </a>      </li>    </ol>  </nav></template>

#「前へ」と「次へ」のみ

ページ数が不明な場合や、ページ数が重要でない場合は、ラベル付きのボタン 2 つで十分です。リンク自体は無効化できないため、最初のページでは「前へ」に aria-disabled="true" を指定し、href を外してください。

「前へ」と「次へ」のみ

<nav class="flex items-center gap-xs" aria-label="Pagination">  <a class="btn btn-sm" aria-disabled="true">Previous</a>  <span class="text-sm fg-text-muted px-xs">Page 1 of 24</span>  <a class="btn btn-sm" href="#page-2">Next</a></nav>
<nav className="flex items-center gap-xs" aria-label="Pagination">  <a className="btn btn-sm" aria-disabled="true">Previous</a>  <span className="text-sm fg-text-muted px-xs">Page 1 of 24</span>  <a className="btn btn-sm" href="#page-2">Next</a></nav>
<nav class="flex items-center gap-xs" aria-label="Pagination">  <a class="btn btn-sm" aria-disabled="true">Previous</a>  <span class="text-sm fg-text-muted px-xs">Page 1 of 24</span>  <a class="btn btn-sm" href="#page-2">Next</a></nav>
<template>  <nav class="flex items-center gap-xs" aria-label="Pagination">    <a class="btn btn-sm" aria-disabled="true">Previous</a>    <span class="text-sm fg-text-muted px-xs">Page 1 of 24</span>    <a class="btn btn-sm" href="#page-2">Next</a>  </nav></template>

#アクセシビリティ

  • リストを <nav aria-label="Pagination"> で囲み、現在のページに aria-current="page" を指定してください。
  • 数字だけではリンク先が伝わりにくいため、各ページへのリンクに「3 ページ目」などの aria-label を指定してください。
  • 省略表示は操作要素ではないため、aria-hidden="true" で支援技術から隠してください。

#クラス

クラス説明
paginationaria-label を指定した nav 内の ol 要素に適用し、ページリンクを横に並べます。等幅数字を使うため、ページが変わっても行の幅は変わりません。
pagination-gapページを省略した箇所に表示する省略記号。操作対象ではないため、aria-hidden="true" で支援技術から隠します。

#ソース

@master/ui/components/pagination.css
/* * Pagination: the pages of a long list, as a row of links inside a <nav>. * The links are quiet square buttons; the current page has aria-current="page" and stays sunk into a well, * which the button stylesheet draws. This file supplies the row and the gap that stands for skipped pages. */@layer components.ui {  .pagination {    display: flex;    flex-wrap: wrap;    align-items: center;    gap: 2px;    min-width: 0;    margin: 0;    padding: 0;    font-variant-numeric: tabular-nums;    list-style: none;    /* A button's font shorthand resets the figures, so the pages take the tabular ones on themselves. */    .btn {      font-variant-numeric: tabular-nums;    }    /*     * Pages stand 2px apart, so on touch a page's target grows only above and below, never over its neighbor;     * and pages that wrap onto a second row stand 12px apart there, the two reaches, for the same reason.     */    @media (pointer: coarse) {      row-gap: .75rem;      .btn::after {        @apply --touch-target-block;      }    }  }  /* An ellipsis where pages are left out. It is not a control, so hide it from assistive technology. */  .pagination-gap {    display: grid;    place-items: center;    min-width: 2rem;    height: 2rem;    color: var(--color-text-muted);    font-size: .78125rem;    user-select: none;    -webkit-user-select: none;  }}