표
가는 구분선으로 데이터 행을 나누고, 열 제목에서 정렬 순서를 바꿀 수 있으며, 숫자의 자릿수가 가지런히 맞는 표입니다.
이 페이지의 내용
표는 가는 구분선으로 데이터 행을 나눕니다. 열 제목은 한층 뚜렷한 구분선 위에 차분하게 표시하고, 행의 데이터에는 본문 글자색을 사용합니다. <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>를 가운데 정렬하고 굵게 표시하더라도 표의 일관된 모양은 유지됩니다.
같은 클래스는 독립형 CSS로 사용할 때도 ARIA 역할로 구성한 표에 표, 행, 셀의 표시 방식을 적용합니다.
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 요소 또는 접근성 역할로 구성한 그리드 |
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입니다. |