HTML Tables

HTML Tables are used to display data in rows and columns using table, tr, td, and th tags.

6 views
5 min read
Try It Yourself

Experiment with the code in an interactive editor

What are Tables?

Tables are like spreadsheets (Excel) — they show data in rows and columns.

Basic table structure:

1<table border="1">
2    <caption>Employee Directory</caption>
3    <thead>
4        <tr>
5            <th>Name</th>
6            <th>Position</th>
7            <th>Salary</th>
8        </tr>
9    </thead>
10    <tbody>
11        <tr>
12            <td>John Doe</td>
13            <td>Developer</td>
14            <td>$60,000</td>
15        </tr>
16        <tr>
17            <td>Jane Smith</td>
18            <td>Manager</td>
19            <td>$75,000</td>
20        </tr>
21    </tbody>
22</table>

Table parts explained:

Tag

Full Form

Purpose

<table>

Table

Wraps the whole table

<caption>

Caption

Title of the table

<thead>

Table Head

Header section (usually column names)

<th>

Table Header

A header cell (bold by default)

<tbody>

Table Body

Main content section

<tr>

Table Row

A single row

<td>

Table Data

A normal cell

When to use tables:

  • Showing price lists

  • Displaying comparison charts

  • Showing schedules/timetables

  • Financial data

  • NOT for layout (use CSS Grid/Flexbox instead)