본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

표

원문 보기 위키 갱신

표 (Table)

표(Table) 컴포넌트는 정보를 행과 열로 정리해서 사용자가 더 쉽게 비교하고 훑어볼 수 있게 하는 컴포넌트예요. 데이터가 많을 때 구조를 잡아주는 데 유용하죠.

출처: 문서

본문

표 컴포넌트를 사용해서 사용자가 정보를 더 쉽게 비교하고 훑어볼 수 있게 해주세요.

<table class="govuk-table">
  <caption class="govuk-table__caption govuk-table__caption--m">Dates and amounts</caption>
  <thead class="govuk-table__head">
    <tr class="govuk-table__row">
      <th scope="col" class="govuk-table__header">Date</th>
      <th scope="col" class="govuk-table__header">Amount</th>
    </tr>
  </thead>
  <tbody class="govuk-table__body">
    <tr class="govuk-table__row">
      <th scope="row" class="govuk-table__header">First 6 weeks</th>
      <td class="govuk-table__cell">£109.80 per week</td>
    </tr>
    <tr class="govuk-table__row">
      <th scope="row" class="govuk-table__header">Next 33 weeks</th>
      <td class="govuk-table__cell">£109.80 per week</td>
    </tr>
    <tr class="govuk-table__row">
      <th scope="row" class="govuk-table__header">Total estimated pay</th>
      <td class="govuk-table__cell">£4,282.20</td>
    </tr>
  </tbody>
</table>

어떤 때 사용하나요

사용자가 행과 열의 정보를 비교할 수 있게 하려면 표 컴포넌트를 사용하세요.

어떤 때 사용하지 말아야 하나요

페이지에서 콘텐츠의 레이아웃을 잡는 데 표 컴포넌트를 절대 사용하지 마세요. 대신 그리드 시스템을 사용하세요.

어떻게 동작하나요

표 캡션 (Table captions)

`` 요소를 사용해서 제목을 쓰는 것처럼 표를 설명하세요. 캡션은 사용자가 표를 찾고, 탐색하고, 이해하는 데 도움이 돼요.

표 캡션에는 다른 스타일 옵션이 있어요. govuk-table__caption--s, govuk-table__caption--m, govuk-table__caption--l, govuk-table__caption--xl 클래스를 사용해서 기본보다 더 크거나 작게 만들 수 있어요.

<table class="govuk-table">
  <caption class="govuk-table__caption govuk-table__caption--l">Months and rates</caption>
  <thead class="govuk-table__head">
    <tr class="govuk-table__row">
      <th scope="col" class="govuk-table__header">Month you apply</th>
      <th scope="col" class="govuk-table__header">Rate for vehicles</th>
    </tr>
  </thead>
  <tbody class="govuk-table__body">
    <tr class="govuk-table__row">
      <th scope="row" class="govuk-table__header">January</th>
      <td class="govuk-table__cell">£95</td>
    </tr>
  </tbody>
</table>

표 헤더 (Table headers)

표 헤더를 사용해서 행과 열이 무엇을 나타내는지 사용자에게 알려주세요. 보조 기술 사용자가 행 헤더와 열 헤더를 구분할 수 있도록 scope 속성을 사용하세요.

표 컴포넌트를 사용하는 방법은 2가지가 있어요. HTML을 직접 사용할 수도 있고, Nunjucks나 GOV.UK Prototype Kit을 사용한다면 Nunjucks 매크로를 쓸 수도 있어요.

<table class="govuk-table">
  <caption class="govuk-table__caption govuk-table__caption--m">Dates and amounts</caption>
  <thead class="govuk-table__head">
    <tr class="govuk-table__row">
      <th scope="col" class="govuk-table__header">Date</th>
      <th scope="col" class="govuk-table__header">Amount</th>
    </tr>
  </thead>
  <tbody class="govuk-table__body">
    <tr class="govuk-table__row">
      <th scope="row" class="govuk-table__header">First 6 weeks</th>
      <td class="govuk-table__cell">£109.80 per week</td>
    </tr>
  </tbody>
</table>

표 안의 숫자 (Numbers in a table)

숫자 열을 비교할 때는 표 셀에서 숫자를 오른쪽으로 정렬하세요.

<table class="govuk-table">
  <caption class="govuk-table__caption govuk-table__caption--m">Months and rates</caption>
  <thead class="govuk-table__head">
    <tr class="govuk-table__row">
      <th scope="col" class="govuk-table__header">Month you apply</th>
      <th scope="col" class="govuk-table__header govuk-table__header--numeric">Rate for bicycles</th>
      <th scope="col" class="govuk-table__header govuk-table__header--numeric">Rate for vehicles</th>
    </tr>
  </thead>
  <tbody class="govuk-table__body">
    <tr class="govuk-table__row">
      <th scope="row" class="govuk-table__header">January</th>
      <td class="govuk-table__cell govuk-table__cell--numeric">£85</td>
      <td class="govuk-table__cell govuk-table__cell--numeric">£95</td>
    </tr>
  </tbody>
</table>

커스텀 열 너비 (Custom column widths)

너비 오버라이드 클래스를 사용해서 표 열의 너비를 설정할 수 있어요.

<table class="govuk-table">
  <caption class="govuk-table__caption govuk-table__caption--m">Month you apply</caption>
  <thead class="govuk-table__head">
    <tr class="govuk-table__row">
      <th scope="col" class="govuk-table__header govuk-!-width-one-half">Date</th>
      <th scope="col" class="govuk-table__header govuk-!-width-one-quarter">Rate for vehicles</th>
      <th scope="col" class="govuk-table__header govuk-!-width-one-quarter">Rate for bicycles</th>
    </tr>
  </thead>
  <tbody class="govuk-table__body">
    <tr class="govuk-table__row">
      <th scope="row" class="govuk-table__header">First 6 weeks</th>
      <td class="govuk-table__cell">£109.80 per week</td>
      <td class="govuk-table__cell">£59.10 per week</td>
    </tr>
  </tbody>
</table>

너비 오버라이드 클래스가 요구 사항을 충족하지 못한다면, 자체 너비 클래스를 만들어 표 헤더의 셀에 적용할 수 있어요. 이는 Nunjucks 매크로의 classes 옵션으로 추가하거나, 아래처럼 govuk-table__head 안의 개별 셀에 클래스를 직접 추가할 수 있어요.

이에 대해 더 알아보려면, 운영 환경에서 컴포넌트를 확장하고 수정하는 방법에 대한 안내를 읽어보세요.

<table class="govuk-table">
  <caption class="govuk-table__caption govuk-table__caption--m">Month you apply</caption>
  <thead class="govuk-table__head">
    <tr class="govuk-table__row">
      <th scope="col" class="govuk-table__header app-custom-class">Date</th>
      <th scope="col" class="govuk-table__header app-custom-class">Rate for vehicles</th>
      <th scope="col" class="govuk-table__header app-custom-class">Rate for bicycles</th>
    </tr>
  </thead>
  <tbody class="govuk-table__body">
    <tr class="govuk-table__row">
      <th scope="row" class="govuk-table__header">First 6 weeks</th>
      <td class="govuk-table__cell">£109.80 per week</td>
      <td class="govuk-table__cell">£59.10 per week</td>
    </tr>
  </tbody>
</table>

데이터가 많은 표 (Tables with a lot of data)

가능하다면 표 안의 데이터를 줄이도록 노력하세요. 데이터가 많다면, 여러 표나 여러 페이지로 정리해보세요.

데이터를 나눌 수 없다면, govuk-table--small-text-until-tablet CSS 클래스를 사용할 수 있어요. 이 클래스는 작은 화면에서 텍스트 크기를 줄여서 많은 양의 데이터 주변에 더 많은 빈 공간을 만들어줘요. 이렇게 하면 작은 화면에서 각 데이터 조각을 시각적으로 더 쉽게 구분할 수 있어요.

govuk-table--small-text-until-tablet CSS 클래스는 GOV.UK Frontend 5.2 이상에서만 사용할 수 있어요.

새로운 타이포그래피 스케일(type scale)을 사용하도록 서비스를 업데이트하는 방법에 대해 읽어보세요.

표에 데이터가 많지 않은 경우에는 이 클래스를 사용하지 마세요. 데이터의 양이 적을수록 텍스트가 크면 읽기가 더 쉽기 때문이에요.

<table class="govuk-table govuk-table--small-text-until-tablet">
  <caption class="govuk-table__caption govuk-table__caption--m">Dates and amounts</caption>
  <thead class="govuk-table__head">
    <tr class="govuk-table__row">
      <th scope="col" class="govuk-table__header">Date</th>
      <th scope="col" class="govuk-table__header">First amount</th>
      <th scope="col" class="govuk-table__header">Second amount</th>
    </tr>
  </thead>
  <tbody class="govuk-table__body">
    <tr class="govuk-table__row">
      <th scope="row" class="govuk-table__header">First 3 weeks</th>
      <td class="govuk-table__cell">£27.45 per week</td>
      <td class="govuk-table__cell">£33.90 per week</td>
    </tr>
  </tbody>
</table>

최근 변경 사항

| 날짜 | 변경 | 설명 | | Feb 2024 | GOV.UK Frontend v5.2.0 | govuk-table--small-text-until-tablet 수정자 클래스를 추가했어요. | | Feb 2021 | GOV.UK Frontend v3.11.0 | 캡션용 크기 수정자 클래스를 추가했어요. | | Jul 2019 | GOV.UK Frontend v3.0.0 | 콘텐츠의 기본 세로 정렬을 셀 상단으로 변경했어요. 행 헤더가 classes, rowspan, colspan 파라미터를 받도록 업데이트했어요. | | Jan 2019 | 안내 | 너비 오버라이드 클래스를 사용해 열 너비를 커스터마이즈하는 방법에 대한 안내를 추가했어요. | | Nov 2018 | GOV.UK Frontend v2.3.0 | 셀에 커스텀 HTML 속성을 전달하는 옵션을 추가했어요. |

이 컴포넌트 개선에 도움 주기

이 페이지가 유용하고, 관련성이 있으며, 최신 상태로 유지되도록 하려면 다음을 할 수 있어요:

  • GitHub의 ‘Table’ 토론에 참여해서 연구 내용을 공유하기
  • GitHub에서 변경 제안하기 – GitHub에서 변경 사항을 제안하는 방법에 대해 자세히 알아보기

더 알아보기 (Learn more)