テーブル
細い罫線でデータ行を区切り、列見出しで並べ替え、数値の桁をそろえられます。
このページの内容
テーブルはデータ行を細い罫線で区切ります。列見出しには控えめなキャプションと少し強めの罫線を使い、データ行は本文色で表示します。<table> に table を指定し、各 <tr> に table-row、列見出しに table-heading、データセルと行見出しに table-cell を指定します。テーブル自体には背景がないため、シート または カード の中に配置します。
テーブル
<div class="sheet overflow-hidden"> <table class="table"> <thead> <tr class="table-row"> <th class="table-heading" scope="col">Project</th> <th class="table-heading" scope="col">Status</th> <th class="table-heading" scope="col">Region</th> <th class="table-heading table-numeric" scope="col">Requests</th> </tr> </thead> <tbody> <tr class="table-row"> <th class="table-cell table-primary" scope="row">Atlas</th> <td class="table-cell"><span class="badge badge-success badge-dot">Ready</span></td> <td class="table-cell">Tokyo</td> <td class="table-cell table-numeric">1,284,019</td> </tr> <tr class="table-row"> <th class="table-cell table-primary" scope="row">Borealis</th> <td class="table-cell"><span class="badge badge-warning badge-dot">Degraded</span></td> <td class="table-cell">Frankfurt</td> <td class="table-cell table-numeric">94,201</td> </tr> <tr class="table-row"> <th class="table-cell table-primary" scope="row">Cirrus</th> <td class="table-cell"><span class="badge badge-dot">Draft</span></td> <td class="table-cell">Virginia</td> <td class="table-cell table-numeric">0</td> </tr> </tbody> </table></div><div className="sheet overflow-hidden"> <table className="table"> <thead> <tr className="table-row"> <th className="table-heading" scope="col">Project</th> <th className="table-heading" scope="col">Status</th> <th className="table-heading" scope="col">Region</th> <th className="table-heading table-numeric" scope="col">Requests</th> </tr> </thead> <tbody> <tr className="table-row"> <th className="table-cell table-primary" scope="row">Atlas</th> <td className="table-cell"><span className="badge badge-success badge-dot">Ready</span></td> <td className="table-cell">Tokyo</td> <td className="table-cell table-numeric">1,284,019</td> </tr> <tr className="table-row"> <th className="table-cell table-primary" scope="row">Borealis</th> <td className="table-cell"> <span className="badge badge-warning badge-dot">Degraded</span> </td> <td className="table-cell">Frankfurt</td> <td className="table-cell table-numeric">94,201</td> </tr> <tr className="table-row"> <th className="table-cell table-primary" scope="row">Cirrus</th> <td className="table-cell"><span className="badge badge-dot">Draft</span></td> <td className="table-cell">Virginia</td> <td className="table-cell table-numeric">0</td> </tr> </tbody> </table></div><div class="sheet overflow-hidden"> <table class="table"> <thead> <tr class="table-row"> <th class="table-heading" scope="col">Project</th> <th class="table-heading" scope="col">Status</th> <th class="table-heading" scope="col">Region</th> <th class="table-heading table-numeric" scope="col">Requests</th> </tr> </thead> <tbody> <tr class="table-row"> <th class="table-cell table-primary" scope="row">Atlas</th> <td class="table-cell"><span class="badge badge-success badge-dot">Ready</span></td> <td class="table-cell">Tokyo</td> <td class="table-cell table-numeric">1,284,019</td> </tr> <tr class="table-row"> <th class="table-cell table-primary" scope="row">Borealis</th> <td class="table-cell"><span class="badge badge-warning badge-dot">Degraded</span></td> <td class="table-cell">Frankfurt</td> <td class="table-cell table-numeric">94,201</td> </tr> <tr class="table-row"> <th class="table-cell table-primary" scope="row">Cirrus</th> <td class="table-cell"><span class="badge badge-dot">Draft</span></td> <td class="table-cell">Virginia</td> <td class="table-cell table-numeric">0</td> </tr> </tbody> </table></div><template> <div class="sheet overflow-hidden"> <table class="table"> <thead> <tr class="table-row"> <th class="table-heading" scope="col">Project</th> <th class="table-heading" scope="col">Status</th> <th class="table-heading" scope="col">Region</th> <th class="table-heading table-numeric" scope="col">Requests</th> </tr> </thead> <tbody> <tr class="table-row"> <th class="table-cell table-primary" scope="row">Atlas</th> <td class="table-cell"><span class="badge badge-success badge-dot">Ready</span></td> <td class="table-cell">Tokyo</td> <td class="table-cell table-numeric">1,284,019</td> </tr> <tr class="table-row"> <th class="table-cell table-primary" scope="row">Borealis</th> <td class="table-cell"><span class="badge badge-warning badge-dot">Degraded</span></td> <td class="table-cell">Frankfurt</td> <td class="table-cell table-numeric">94,201</td> </tr> <tr class="table-row"> <th class="table-cell table-primary" scope="row">Cirrus</th> <td class="table-cell"><span class="badge badge-dot">Draft</span></td> <td class="table-cell">Virginia</td> <td class="table-cell table-numeric">0</td> </tr> </tbody> </table> </div></template>#セル
セルが行の見出しなら <th class="table-cell" scope="row">、行グループの見出しなら scope="rowgroup" を使います。見出しは先頭側に揃い、--font-weight-control が適用されます。ロールで構成したグリッド内で role="rowheader" を指定した table-cell にも、同じスタイルが適用されます。通常のセルは周囲と同じ文字の太さを保ちます。ブラウザー既定の <th> の中央揃えや太字が、テーブルのリズムを崩すことはありません。
同じクラスを使えば、ARIA ロールで構成したテーブルにも、テーブル、行、セルに対応する表示形式を適用できます。スタンドアロン CSS でも利用できます。
table-primaryは行を識別するセルに付け、その文字をコントラストの強いインク色で表示します。ほかのセルは本文色のままなので、行の名前が先に目に入ります。- 見出しと対応するセルに
table-numericを指定すると、末尾側に揃い、等幅数字で表示されます。桁が縦にそろい、桁数で数値の大きさを比べやすくなります。
#並べ替え
aria-sort="ascending" または aria-sort="descending" を指定した見出しの文字はコントラストの強いインク色になり、並べ替えの方向を示すシェブロンが付きます。順序を変更するには、見出しの中にボタンを置きます。スタイルシートは属性に応じて表示を変え、属性値の設定はスクリプトまたはサーバーが行います。
並べ替え
<div class="sheet overflow-hidden"> <table class="table table-compact"> <thead> <tr class="table-row"> <th class="table-heading" scope="col" aria-sort="ascending"> <button type="button" class="table-sort">Name</button> </th> <th class="table-heading" scope="col">Role</th> <th class="table-heading table-numeric" scope="col"> <button type="button" class="table-sort">Deployments</button> </th> </tr> </thead> <tbody> <tr class="table-row"> <td class="table-cell table-primary">Ada Lovelace</td> <td class="table-cell">Owner</td> <td class="table-cell table-numeric">412</td> </tr> <tr class="table-row"> <td class="table-cell table-primary">Alan Turing</td> <td class="table-cell">Admin</td> <td class="table-cell table-numeric">96</td> </tr> <tr class="table-row"> <td class="table-cell table-primary">Grace Hopper</td> <td class="table-cell">Member</td> <td class="table-cell table-numeric">1,204</td> </tr> </tbody> </table></div><div className="sheet overflow-hidden"> <table className="table table-compact"> <thead> <tr className="table-row"> <th className="table-heading" scope="col" aria-sort="ascending"> <button type="button" className="table-sort">Name</button> </th> <th className="table-heading" scope="col">Role</th> <th className="table-heading table-numeric" scope="col"> <button type="button" className="table-sort">Deployments</button> </th> </tr> </thead> <tbody> <tr className="table-row"> <td className="table-cell table-primary">Ada Lovelace</td> <td className="table-cell">Owner</td> <td className="table-cell table-numeric">412</td> </tr> <tr className="table-row"> <td className="table-cell table-primary">Alan Turing</td> <td className="table-cell">Admin</td> <td className="table-cell table-numeric">96</td> </tr> <tr className="table-row"> <td className="table-cell table-primary">Grace Hopper</td> <td className="table-cell">Member</td> <td className="table-cell table-numeric">1,204</td> </tr> </tbody> </table></div><div class="sheet overflow-hidden"> <table class="table table-compact"> <thead> <tr class="table-row"> <th class="table-heading" scope="col" aria-sort="ascending"> <button type="button" class="table-sort">Name</button> </th> <th class="table-heading" scope="col">Role</th> <th class="table-heading table-numeric" scope="col"> <button type="button" class="table-sort">Deployments</button> </th> </tr> </thead> <tbody> <tr class="table-row"> <td class="table-cell table-primary">Ada Lovelace</td> <td class="table-cell">Owner</td> <td class="table-cell table-numeric">412</td> </tr> <tr class="table-row"> <td class="table-cell table-primary">Alan Turing</td> <td class="table-cell">Admin</td> <td class="table-cell table-numeric">96</td> </tr> <tr class="table-row"> <td class="table-cell table-primary">Grace Hopper</td> <td class="table-cell">Member</td> <td class="table-cell table-numeric">1,204</td> </tr> </tbody> </table></div><template> <div class="sheet overflow-hidden"> <table class="table table-compact"> <thead> <tr class="table-row"> <th class="table-heading" scope="col" aria-sort="ascending"> <button type="button" class="table-sort">Name</button> </th> <th class="table-heading" scope="col">Role</th> <th class="table-heading table-numeric" scope="col"> <button type="button" class="table-sort">Deployments</button> </th> </tr> </thead> <tbody> <tr class="table-row"> <td class="table-cell table-primary">Ada Lovelace</td> <td class="table-cell">Owner</td> <td class="table-cell table-numeric">412</td> </tr> <tr class="table-row"> <td class="table-cell table-primary">Alan Turing</td> <td class="table-cell">Admin</td> <td class="table-cell table-numeric">96</td> </tr> <tr class="table-row"> <td class="table-cell table-primary">Grace Hopper</td> <td class="table-cell">Member</td> <td class="table-cell table-numeric">1,204</td> </tr> </tbody> </table> </div></template>table-compact は行を詰めて表示します。長い一覧にざっと目を通すときに適しています。
#行の選択と、開ける行
aria-selected="true" を指定した行は、一段浮き上がったシートとして表示します。テーブルに table-interactive を指定すると、メニュー の項目と同じように、テーブル本体のすべての行がチップと同じ色合いでポインターに反応します。どちらも行全体に適用されるため、セルの境界に継ぎ目が出ません。
選択
<div class="sheet overflow-hidden"> <table class="table table-interactive"> <thead> <tr class="table-row"> <th class="table-heading" scope="col"> <input type="checkbox" class="checkbox" aria-label="Select all"> </th> <th class="table-heading" scope="col">Domain</th> <th class="table-heading" scope="col">Certificate</th> </tr> </thead> <tbody> <tr class="table-row" aria-selected="true"> <td class="table-cell"> <input type="checkbox" class="checkbox" checked aria-label="Select atlas.dev"> </td> <td class="table-cell table-primary">atlas.dev</td> <td class="table-cell">Renews in 61 days</td> </tr> <tr class="table-row"> <td class="table-cell"> <input type="checkbox" class="checkbox" aria-label="Select docs.atlas.dev"> </td> <td class="table-cell table-primary">docs.atlas.dev</td> <td class="table-cell">Renews in 12 days</td> </tr> </tbody> </table></div><div className="sheet overflow-hidden"> <table className="table table-interactive"> <thead> <tr className="table-row"> <th className="table-heading" scope="col"> <input type="checkbox" className="checkbox" aria-label="Select all" /> </th> <th className="table-heading" scope="col">Domain</th> <th className="table-heading" scope="col">Certificate</th> </tr> </thead> <tbody> <tr className="table-row" aria-selected="true"> <td className="table-cell"> <input type="checkbox" className="checkbox" defaultChecked aria-label="Select atlas.dev" /> </td> <td className="table-cell table-primary">atlas.dev</td> <td className="table-cell">Renews in 61 days</td> </tr> <tr className="table-row"> <td className="table-cell"> <input type="checkbox" className="checkbox" aria-label="Select docs.atlas.dev" /> </td> <td className="table-cell table-primary">docs.atlas.dev</td> <td className="table-cell">Renews in 12 days</td> </tr> </tbody> </table></div><div class="sheet overflow-hidden"> <table class="table table-interactive"> <thead> <tr class="table-row"> <th class="table-heading" scope="col"> <input type="checkbox" class="checkbox" aria-label="Select all"> </th> <th class="table-heading" scope="col">Domain</th> <th class="table-heading" scope="col">Certificate</th> </tr> </thead> <tbody> <tr class="table-row" aria-selected="true"> <td class="table-cell"> <input type="checkbox" class="checkbox" checked aria-label="Select atlas.dev"> </td> <td class="table-cell table-primary">atlas.dev</td> <td class="table-cell">Renews in 61 days</td> </tr> <tr class="table-row"> <td class="table-cell"> <input type="checkbox" class="checkbox" aria-label="Select docs.atlas.dev"> </td> <td class="table-cell table-primary">docs.atlas.dev</td> <td class="table-cell">Renews in 12 days</td> </tr> </tbody> </table></div><template> <div class="sheet overflow-hidden"> <table class="table table-interactive"> <thead> <tr class="table-row"> <th class="table-heading" scope="col"> <input type="checkbox" class="checkbox" aria-label="Select all"> </th> <th class="table-heading" scope="col">Domain</th> <th class="table-heading" scope="col">Certificate</th> </tr> </thead> <tbody> <tr class="table-row" aria-selected="true"> <td class="table-cell"> <input type="checkbox" class="checkbox" checked aria-label="Select atlas.dev"> </td> <td class="table-cell table-primary">atlas.dev</td> <td class="table-cell">Renews in 61 days</td> </tr> <tr class="table-row"> <td class="table-cell"> <input type="checkbox" class="checkbox" aria-label="Select docs.atlas.dev"> </td> <td class="table-cell table-primary">docs.atlas.dev</td> <td class="table-cell">Renews in 12 days</td> </tr> </tbody> </table> </div></template>#幅の広いテーブル
テーブルは列を保ちます。カードを縦に並べる形に変えると、同じ列の値を見比べられるというテーブルの利点が失われるためです。テーブルが配置先の列より広くなる場合は、インライン軸方向にスクロールする スクロール領域 で囲みます。画面外に列が続く側の端はフェードします。table-sticky を使うと、行をスクロールしても見出しが表示されたままになります。
幅の広いテーブル
<div class="sheet overflow-hidden"> <div class="scroll-area scroll-area-inline" tabindex="0" role="region" aria-label="Deployments"> <table class="table"> <thead> <tr class="table-row"> <th class="table-heading" scope="col">Deployment</th> <th class="table-heading" scope="col">Branch</th> <th class="table-heading" scope="col">Commit</th> <th class="table-heading" scope="col">Author</th> <th class="table-heading table-numeric" scope="col">Duration</th> </tr> </thead> <tbody> <tr class="table-row"> <td class="table-cell table-primary whitespace-nowrap">atlas-9f2c1a</td> <td class="table-cell whitespace-nowrap">main</td> <td class="table-cell whitespace-nowrap">Soften every edge</td> <td class="table-cell whitespace-nowrap">Ada Lovelace</td> <td class="table-cell table-numeric">48s</td> </tr> <tr class="table-row"> <td class="table-cell table-primary whitespace-nowrap">atlas-71be0d</td> <td class="table-cell whitespace-nowrap">feature/anchors</td> <td class="table-cell whitespace-nowrap">Glide the segmented thumb</td> <td class="table-cell whitespace-nowrap">Alan Turing</td> <td class="table-cell table-numeric">1m 02s</td> </tr> </tbody> </table> </div></div><div className="sheet overflow-hidden"> <div className="scroll-area scroll-area-inline" tabIndex={0} role="region" aria-label="Deployments"> <table className="table"> <thead> <tr className="table-row"> <th className="table-heading" scope="col">Deployment</th> <th className="table-heading" scope="col">Branch</th> <th className="table-heading" scope="col">Commit</th> <th className="table-heading" scope="col">Author</th> <th className="table-heading table-numeric" scope="col">Duration</th> </tr> </thead> <tbody> <tr className="table-row"> <td className="table-cell table-primary whitespace-nowrap">atlas-9f2c1a</td> <td className="table-cell whitespace-nowrap">main</td> <td className="table-cell whitespace-nowrap">Soften every edge</td> <td className="table-cell whitespace-nowrap">Ada Lovelace</td> <td className="table-cell table-numeric">48s</td> </tr> <tr className="table-row"> <td className="table-cell table-primary whitespace-nowrap">atlas-71be0d</td> <td className="table-cell whitespace-nowrap">feature/anchors</td> <td className="table-cell whitespace-nowrap">Glide the segmented thumb</td> <td className="table-cell whitespace-nowrap">Alan Turing</td> <td className="table-cell table-numeric">1m 02s</td> </tr> </tbody> </table> </div></div><div class="sheet overflow-hidden"> <div class="scroll-area scroll-area-inline" tabindex="0" role="region" aria-label="Deployments"> <table class="table"> <thead> <tr class="table-row"> <th class="table-heading" scope="col">Deployment</th> <th class="table-heading" scope="col">Branch</th> <th class="table-heading" scope="col">Commit</th> <th class="table-heading" scope="col">Author</th> <th class="table-heading table-numeric" scope="col">Duration</th> </tr> </thead> <tbody> <tr class="table-row"> <td class="table-cell table-primary whitespace-nowrap">atlas-9f2c1a</td> <td class="table-cell whitespace-nowrap">main</td> <td class="table-cell whitespace-nowrap">Soften every edge</td> <td class="table-cell whitespace-nowrap">Ada Lovelace</td> <td class="table-cell table-numeric">48s</td> </tr> <tr class="table-row"> <td class="table-cell table-primary whitespace-nowrap">atlas-71be0d</td> <td class="table-cell whitespace-nowrap">feature/anchors</td> <td class="table-cell whitespace-nowrap">Glide the segmented thumb</td> <td class="table-cell whitespace-nowrap">Alan Turing</td> <td class="table-cell table-numeric">1m 02s</td> </tr> </tbody> </table> </div></div><template> <div class="sheet overflow-hidden"> <div class="scroll-area scroll-area-inline" tabindex="0" role="region" aria-label="Deployments"> <table class="table"> <thead> <tr class="table-row"> <th class="table-heading" scope="col">Deployment</th> <th class="table-heading" scope="col">Branch</th> <th class="table-heading" scope="col">Commit</th> <th class="table-heading" scope="col">Author</th> <th class="table-heading table-numeric" scope="col">Duration</th> </tr> </thead> <tbody> <tr class="table-row"> <td class="table-cell table-primary whitespace-nowrap">atlas-9f2c1a</td> <td class="table-cell whitespace-nowrap">main</td> <td class="table-cell whitespace-nowrap">Soften every edge</td> <td class="table-cell whitespace-nowrap">Ada Lovelace</td> <td class="table-cell table-numeric">48s</td> </tr> <tr class="table-row"> <td class="table-cell table-primary whitespace-nowrap">atlas-71be0d</td> <td class="table-cell whitespace-nowrap">feature/anchors</td> <td class="table-cell whitespace-nowrap">Glide the segmented thumb</td> <td class="table-cell whitespace-nowrap">Alan Turing</td> <td class="table-cell table-numeric">1m 02s</td> </tr> </tbody> </table> </div> </div></template>#アクセシビリティ
- 各セルが列見出しとともに読み上げられるように、ネイティブの
<table>内に<thead>と<tbody>を使い、列見出しにscope="col"を指定します。 - キーボードでスクロールできるよう、スクロール領域のラッパーには
tabindex="0"とrole="region"を指定し、ラベルを付けます。 - 選択状態は、行の
aria-selectedとチェックボックスの状態の両方で、意図的に伝えます。
#クラス
| クラス | 説明 |
|---|---|
table | ネイティブのテーブル、またはロールで構成したグリッド |
table-row | 行 |
table-heading | 列見出し。控えめなキャプションと、データ行よりはっきりした罫線 |
table-cell | インライン方向の始端に揃えたデータセルまたは行見出しです。ネイティブの scope=row/rowgroup または role=rowheader を使う場合は、ブラウザー既定の太字に代えて、テーマのコントロール用フォントウェイトを適用します。 |
table-sort | 並べ替え可能な見出しの中で順序を変えるボタンです。ポインターが重なると見出しの語句がチップの上に表示され、並べ替え済みの列のシェブロンを含みます。 |
table-title | caption に適用する表の名前です。見出しの上、開始側の端にそろえたタイトルになります。 |
table-primary | 行を識別するセルです。強調用の前景色で表示します。table-cell と併用します |
table-numeric | 見出しまたはセルに使う右揃えの等幅数字table-heading または table-cell と併用します |
table-compact | 流し読みする長いリスト向けの、間隔を詰めた行table と併用します |
table-interactive | セルを含む行はポインター操作に反応し、フォーカスリングを表示table と併用します |
table-sticky | データ行をスクロールしても、見出しは表示されたままです。table と併用します |
#カスタムプロパティ
| プロパティ | 既定値 | 説明 |
|---|---|---|
--table-padding-x | 1rem | 見出しとセルのインライン方向のパディング。コンパクトなテーブルでは .75rem |
--table-padding-y | .75rem | セルのブロック方向のパディング。コンパクトなテーブルでは .4375rem |