Coding/Learn/html/tables
HTML Beginner Course
01.Introduction to HTML
02.Anatomy of an HTML Element
03.The Sacred HTML5 Skeleton
04.Headings (h1 to h6)
05.Paragraphs, Line Breaks & Dividers
06.Text Formatting & Emphasis
07.Hyperlinks & Navigation (<a>)
08.Images & The Sacred Alt Text (<img>)
09.Ordered & Unordered Lists (<ul>, <ol>, <li>)
10.Block vs Inline Elements
11.Generic Containers (<div> & <span>)
12.Semantic HTML (<header>, <nav>, <main>, <footer>)
13.Tables (<table>, <tr>, <th>, <td>)
14.Native Audio & Video Elements
15.The Invisible Brain (<head> & Meta Tags)
16.Interactive Forms (<form>)
17.Input Types (<input>)
18.Accessible Labels & Submit Buttons
19.Textareas & Select Dropdowns (<textarea>, <select>)
20.Capstone: Building Your First Web Profile Page
Course Certificate0%

Complete all lessons to earn

LearnHTML Tables (<table>, <tr>, <th>, <td>)
13 / 20 0%
Lesson 13 of 20
5 mins read

HTML Tables (<table>, <tr>, <th>, <td>)

PreviousNext Lesson
In Plain English

Tables are designed strictly for tabular data (rows and columns of numbers, specs, or comparison charts). A <table> contains rows <tr>, header cells <th>, and data cells <td>.

The Mental Model

"Think of an Excel spreadsheet. <table> is the whole spreadsheet sheet. <tr> is each numbered horizontal row (Row 1, Row 2). <th> is the bold column header ("Language", "Execution Time"), and <td> is each individual cell containing data."

Deep Dive: How It Works

<table>: The master table wrapper.

<tr>: "Table Row". Every horizontal line of data is a <tr>.

<th>: "Table Header cell". Renders text bold and centered by default, indicating column or row titles.

<td>: "Table Data cell". Contains standard cell values.

Semantic Table Sections: Use <thead> (header rows), <tbody> (main data rows), and <tfoot> (totals row) for large datasets.

Syntax Blueprint

<table>
  <tr><th>Language</th><th>Speed</th></tr>
  <tr><td>C++</td><td>Fast</td></tr>
</table>

Rows (tr) holding header cells (th) or standard data cells (td).

PointCore Rules to Remember

Point star
Data Only, Never Layouts: Never use tables to layout page designs—use CSS Flexbox/Grid instead!
Point star
th = Header Cells: Always use <th> in the first row for accessibility.
Point star
Colspan & Rowspan: Use colspan="2" to make a single cell stretch across two columns.

Common Beginner Traps & How to Fix Them

Mistake:Putting text directly inside <table> without <tr> and <td>

Why it happens: Forgetting that tables require strict hierarchical row/cell structure.

How to fix: Always wrap cells in <tr> tags: <table><tr><td>Value</td></tr></table>.

Pro Tip: Add border="1" or CSS border styling to make gridlines visible immediately!

Live Interactive Example

Hit Run Code to see it live
A Clean Comparison Table
HTML5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Live Browser Preview
Click "Preview / Apply" to view the rendered output.
How it works: The <thead> defines column titles and <tbody> holds the data records.

Your Turn: Micro Challenge

No pressure! Edit the starter code below and test your solution with instant feedback.

Micro Exercise

Build a 2-row table

  • PointCreate a <table> with a <tr> row containing two <th> headers: "Item" and "Price"
  • PointAdd a second <tr> row containing two <td> cells: "Coffee" and "$3"
1
2
Browser Preview & Output
Click "Check HTML" to test your solution.

Finished reading and practicing?

Mark this lesson as completed to update your course progress.

PreviousNext Lesson
Overview100 SheetLearnCertificates