SA-21/06, C-11, Asapur, Varanasi, UP support@kamaldnp.com +91 8318013442
HTML
1. HTML Introduction: What is HTML? Learn with Examples 2. Best Free HTML Editors: Notepad to VS Code for Beginners 3. HTML Basic Structure: Doctype, Head, Body Explained 4. HTML Elements Explained: Tags, Content & Empty Elements 5. HTML Attributes List: href, src, alt, width, title & More 6. HTML Headings h1 to h6: Which Heading Tag to Use When 7. HTML Paragraphs: p Tag, br Line Breaks & pre Text 8. HTML Style Attribute: Colour, Font Size & Alignment 9. HTML Text Formatting Tags: bold, italic, mark & More 10. HTML Comments: How to Add Notes & Hide Code in HTML 11. HTML Colors: Names, HEX, RGB & HSL Colour Codes 12. HTML CSS: Inline, Internal & External Stylesheets 13. HTML Links: a Tag, href, New Tab & Email Links 14. HTML Images: img Tag, src, alt, Width & Formats 15. HTML Favicon: Create & Add a Browser Tab Icon 16. HTML Title Tag: How to Write a Good Page Title 17. HTML Tables: table, tr, th, td, colspan & rowspan 18. HTML Lists: ul, ol, dl & Nested Lists Explained 19. HTML Block vs Inline Elements: div, p, span Explained 20. HTML Div Tag: Group Content & Build Page Layouts 21. HTML Class Attribute: Style Many Elements at Once 22. HTML id Attribute: Unique IDs, Links, CSS & JavaScript 23. HTML Iframes: Embed YouTube, Maps & Pages in HTML 24. HTML JavaScript: script Tag, Clicks & First Example 25. HTML File Paths: Relative vs Absolute Paths Explained 26. HTML Head Element: title, meta, charset & viewport 27. HTML Layout: header, nav, main, footer Page Structure 28. HTML Responsive Design: Viewport, Images & Media Queries 29. Semantic HTML Tags: header, nav, main, article & footer 30. HTML Forms: input, label, select, checkbox & Submit 31. HTML Entities: & < > © with Examples 32. HTML Audio & Video Tags: controls, source & Fallback 33. HTML Accessibility: alt Text, Labels, Landmarks & ARIA 34. HTML Meta Tags & SEO: charset, viewport, OG Tags 35. HTML Quotations: blockquote, q, cite, abbr & address
Final Test — Certificate ₹10
Try this code live
Lesson 17 of 35

HTML Tables: table, tr, th, td, colspan & rowspan

4 min read · Free · No login needed

Tables show data in rows and columns — timetables, price lists, exam schemes, comparison charts. A table is built from four tags: <table> for the whole table, <tr> for each row, <th> for a header cell, and <td> for a normal data cell.

Diagram — see how it fits together
Diagram: parts of an HTML table

Structure of a table

Every row is a <tr>. Inside a row, you put cells. The first row usually uses <th> (header) cells, which browsers show in bold and centred. All other rows use <td> cells. A table with 3 rows and 3 columns has 3 <tr> elements, each holding 3 cells.

Caption, colspan and rowspan

  • <caption> — a title for the table, placed right after <table>.
  • colspan="2" — a cell that stretches across 2 columns.
  • rowspan="2" — a cell that stretches across 2 rows.

Tables are for data, not layout

In the old days, websites were laid out with tables. Never do that today — use CSS for layout. Tables are only for real tabular data. A table used for layout is hard to make responsive, and screen readers read it out in a confusing order.

Tip: Add a little CSS — borders, padding, and a light background on alternate rows — and even a plain table becomes easy to read. Zebra striping (every second row shaded) helps the eye follow a row across wide tables.

What each table tag is for

A table is a grid. <table> is the whole grid. <tr> is one row of the grid. <th> is a header cell — the label at the top of a column. <td> is a normal data cell. For longer tables you can also group rows with <thead> (the header rows), <tbody> (the data rows), and <tfoot> (the footer rows).

Table tags and attributes

Tag / AttributeValueDescription
<caption>textThe table's title, placed right after <table>.
<thead>—Groups the header rows of the table.
<tbody>—Groups the main data rows.
colspana numberMakes a cell stretch across that many columns.
rowspana numberMakes a cell stretch across that many rows.
scopecol or rowTells screen readers whether a <th> labels a column or a row.

Here is a header cell that tells a screen reader it labels a whole column:

<tr><th scope="col">Subject</th><th scope="col">Marks</th></tr>
Note: Count your cells carefully. If a row has 3 columns, every other row must also add up to 3 — a cell with colspan="2" counts as 2. If the numbers do not match, the browser draws the table crooked and it is hard to see why.
Tip: Give your header cells scope="col". It costs nothing, and it lets a blind user hear "Subject" announced before each value in that column — the table suddenly makes sense to them.

Common mistakes

  • Using a table to lay out a page — that is the job of CSS, not tables.
  • Using <td> for header cells — headers must be <th>, so they look bold and read correctly.
  • Forgetting <tr> — cells must always sit inside a row, never directly inside <table>.
  • Letting colspan and rowspan numbers not add up — count the columns in every row.

Example explained

  • <style> — draws a 1px border around the table and every cell, and adds padding so the text does not touch the edges. Without it, the table would be invisible lines of plain text.
  • <table> — starts the table. Everything about the table sits between this tag and </table>.
  • <caption>Weekly Class Schedule</caption> — the table's title, shown above it. It must come right after <table>.
  • <tr><th>Day</th><th>Subject</th><th>Time</th></tr> — the header row. The <th> cells are bold, centred headers that label each column.
  • <tr><td>Monday</td><td>HTML Basics</td><td>10:00 AM</td></tr> — a data row. The <td> cells hold the actual values, one per column.

Example

Example
<!DOCTYPE html>
<html>
<head>
<title>Tables</title>
<style>
table, th, td { border: 1px solid #999; border-collapse: collapse; }
th, td { padding: 8px 12px; }
</style>
</head>
<body>

<table>
<caption>Weekly Class Schedule</caption>
<tr><th>Day</th><th>Subject</th><th>Time</th></tr>
<tr><td>Monday</td><td>HTML Basics</td><td>10:00 AM</td></tr>
<tr><td>Tuesday</td><td>CSS Styling</td><td>10:00 AM</td></tr>
</table>

</body>
</html>

Output

Output — how it looks in the browser
Output of HTML Tables: table, tr, th, td, colspan & rowspan

Try it yourself — live editor

Change the code below and press Run to see the result instantly. No file to save, no login needed.

Result

Frequently asked questions

The questions learners ask most about this lesson — read the question, then open it to see the answer.

1. Which tags build an HTML table?

table for the whole table, tr for each row, th for a header cell, and td for a normal data cell.

2. What do colspan and rowspan do?

colspan stretches a cell across columns, and rowspan stretches it across rows.

3. Should tables be used for page layout?

No, tables are only for real tabular data. Use CSS for layout, since layout tables are hard to make responsive.

Why learn this yourself — and not just ask AI?

AI can write code for you, but it cannot think for you. When you learn HTML yourself, your brain builds the real skill: you understand why a page looks the way it does, you can fix it when it breaks, and you can answer it in an exam or an interview without help. That is the skill that gets you a job — not a copied answer.

Get certified — just ₹10

Finish all 35 lessons, pass the test (80%), pay ₹10 and get your certificate.

Take the test

Prefer watching? Video courses teach the same topics step by step.

Go further with a full course

Free tutorials teach you the basics. Our paid courses add live projects, mentorship and a certificate.

Advanced Cyber Security Industrial Training
₹5,000
View
Summer Training in Python Programming 2026
₹3,000
View
AI Prompt Engineering Webinar 2026
View
Browse all courses
HTML — Lessons
1. HTML Introduction: What is HTML? Learn with Examples 2. Best Free HTML Editors: Notepad to VS Code for Beginners 3. HTML Basic Structure: Doctype, Head, Body Explained 4. HTML Elements Explained: Tags, Content & Empty Elements 5. HTML Attributes List: href, src, alt, width, title & More 6. HTML Headings h1 to h6: Which Heading Tag to Use When 7. HTML Paragraphs: p Tag, br Line Breaks & pre Text 8. HTML Style Attribute: Colour, Font Size & Alignment 9. HTML Text Formatting Tags: bold, italic, mark & More 10. HTML Comments: How to Add Notes & Hide Code in HTML 11. HTML Colors: Names, HEX, RGB & HSL Colour Codes 12. HTML CSS: Inline, Internal & External Stylesheets 13. HTML Links: a Tag, href, New Tab & Email Links 14. HTML Images: img Tag, src, alt, Width & Formats 15. HTML Favicon: Create & Add a Browser Tab Icon 16. HTML Title Tag: How to Write a Good Page Title 17. HTML Tables: table, tr, th, td, colspan & rowspan 18. HTML Lists: ul, ol, dl & Nested Lists Explained 19. HTML Block vs Inline Elements: div, p, span Explained 20. HTML Div Tag: Group Content & Build Page Layouts 21. HTML Class Attribute: Style Many Elements at Once 22. HTML id Attribute: Unique IDs, Links, CSS & JavaScript 23. HTML Iframes: Embed YouTube, Maps & Pages in HTML 24. HTML JavaScript: script Tag, Clicks & First Example 25. HTML File Paths: Relative vs Absolute Paths Explained 26. HTML Head Element: title, meta, charset & viewport 27. HTML Layout: header, nav, main, footer Page Structure 28. HTML Responsive Design: Viewport, Images & Media Queries 29. Semantic HTML Tags: header, nav, main, article & footer 30. HTML Forms: input, label, select, checkbox & Submit 31. HTML Entities: & < > © with Examples 32. HTML Audio & Video Tags: controls, source & Fallback 33. HTML Accessibility: alt Text, Labels, Landmarks & ARIA 34. HTML Meta Tags & SEO: charset, viewport, OG Tags 35. HTML Quotations: blockquote, q, cite, abbr & address
Final Test — Certificate ₹10

🤖 KAMALDNP AI Assistant

Ask about courses, website & more

Hi! I'm KAMALDNP AI Assistant. Ask me about our courses, website features, or anything else! 😊
Please wait 5s...
🤖 KAMALDNP Assistant ✕

Request human callback:

🔐 Login Required
✕

Please log in to download. You will stay on this page after logging in!

New here? Register now →