TABLES11 min20 XP

Tables

Learn Tables with live examples, interactive editor, and Shiv AI code review.

HTML Tables

Tables display data in rows and columns. Use tables only for tabular data — comparison charts, schedules, pricing tables, spreadsheet-like content. Do NOT use tables for page layout (that is what CSS is for).

Complete Table Structure

Example 1 — Full Table with thead, tbody, tfoot
<table>
  <!-- thead: column headers -->
  <thead>
    <tr>
      <th scope="col">Course</th>
      <th scope="col">Lessons</th>
      <th scope="col">Price</th>
    </tr>
  </thead>
  <!-- tbody: data rows -->
  <tbody>
    <tr>
      <td>HTML</td>
      <td>22</td>
      <td>Free</td>
    </tr>
    <tr>
      <td>CSS</td>
      <td>18</td>
      <td>Free</td>
    </tr>
  </tbody>
  <!-- tfoot: summary row -->
  <tfoot>
    <tr>
      <td colspan="2">Total Lessons</td>
      <td>40</td>
    </tr>
  </tfoot>
</table>
CourseLessonsPrice
HTML22Free
CSS18Free
Total Lessons40
scope="col" on th tells screen readers this is a column header. colspan="2" makes a cell span 2 columns.

Merging Cells: colspan and rowspan

Example 2 — colspan and rowspan
<table>
  <thead>
    <tr>
      <th>Day</th>
      <!-- colspan spans 2 columns -->
      <th colspan="2">CIWeb Schedule</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <!-- rowspan spans 2 rows -->
      <td rowspan="2">Mon</td>
      <td>HTML Lesson</td>
      <td>9 AM</td>
    </tr>
    <tr>
      <td>CSS Lesson</td>
      <td>11 AM</td>
    </tr>
  </tbody>
</table>
DayCIWeb Schedule
MonHTML Lesson9 AM
CSS Lesson11 AM
colspan merges cells horizontally. rowspan merges cells vertically. Both take a number indicating how many to merge.
Tables Are Not for Layout

In the early web, developers used tables to create multi-column layouts. This is wrong by modern standards. Tables are for tabular data only. Use CSS Flexbox or Grid for page layout — it is faster, cleaner, and more accessible.

Tables and Accessibility

Always use thead, tbody, and th with scope. Screen readers use these to announce column and row headers when navigating cells. A table without proper structure sounds like random numbers being read aloud to a blind user.

Why caption Exists

Add a caption tag as the first child of table to give it a visible title. Screen readers announce the caption before reading the table, so users know what the data is about before hearing any cells.

CIWeb HTML Course • 22 Lessons • Free

Explain with Analogies

Shiv AI explains this lesson using real-life analogies. No code — just clear examples.

Click the Explain tab to generate analogies.
index.html
Live Preview
Write code then click Deep Analyze

What is the correct use of colspan?

Explanationcolspan spans a table cell across multiple columns horizontally. rowspan spans multiple rows vertically. Both take a number value.
Build Challenge
Course Comparison Table
Build a table with thead, tbody, tfoot, th with scope, and at least one colspan.
Requirements (5 to pass)
table
thead
tbody
th with scope
colspan or rowspan
solution.html
Preview
Community Wall
Lesson 8
0/500
0/20 lines
as
Recent Posts
Lesson 8 only
AI
Shiv AI
Online