Перейти к основному содержимому
← 📄 HTML & the platform·Модуль A4 · Урок 2
ЗаданиеBuild a 2-year quarterly comparison. Top header row: empty cell, then <th colspan='2' scope='colgroup'>2025</th>, <th colspan='2' scope='colgroup'>2026</th>. Second header row: Region, Q1, Q2, Q1, Q2 — all scope='col'. One body row: <th scope='row'>EU</th> + four data cells.

Сложные таблицы: colspan, rowspan, многоуровневые заголовки.

100 XP9 min
Теория

When one cell spans multiple columns or rows

<table>
  <thead>
    <tr>
      <th></th>
      <th colspan="2" scope="colgroup">2025</th>
      <th colspan="2" scope="colgroup">2026</th>
    </tr>
    <tr>
      <th scope="col">Region</th>
      <th scope="col">Q1</th>
      <th scope="col">Q2</th>
      <th scope="col">Q1</th>
      <th scope="col">Q2</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th scope="row">EU</th>
      <td>120</td><td>150</td><td>200</td><td>240</td>
    </tr>
  </tbody>
</table>

scope=colgroup / scope=rowgroup

When a header spans multiple columns (year heading over four quarter columns), use scope="colgroup" instead of scope="col". Same for rowgroup when a row header spans multiple body rows.

colspan and rowspan

<td colspan="3">Spans 3 columns</td>
<td rowspan="2">Spans 2 rows</td>

Used in headers AND data cells. Spanning data: think "merged cells" in Excel.

Empty top-left corner

When the very top-left cell of a table-with-row-headers is intentionally empty, just <th></th> is fine. Don't put a description there — screen readers will read it. Empty cell signals "no header for this column."

🔒

Зарегистрируйся чтобы кодить

Теория открыта всем. Интерактивный редактор, живой превью и проверка открываются с 7-дневным бесплатным trial — нужна карта, отмена в любое время.

Регистрация — бесплатный trial →

Первые 10 уроков в каждом треке — бесплатные. Карта не нужна.

← НазадСледующий урок →

Получай один совет по Python или веб-разработке — каждый день в почте

Коротко, без воды, без спама. Отписаться — в один клик.