Tool Blog HTML Table Guide
← Back to Tool
📊

HTML Table — Complete Guide to Creating and Styling Tables (2025)

HTML tables are one of the most practical, everyday tools in web development. Pricing pages, comparison charts, schedules, data reports, sports scores — all of these are tables. This guide teaches you everything: how to build one from scratch, how to merge cells, how to style it beautifully with CSS, and how to make it work perfectly on mobile phones.

✍️ By UTS Sites 📅 Updated: 2025 ⏱️ 14 min read 🎯 Beginner to Advanced

Every code example in this guide is copy-paste ready. Paste any example into our free HTML Editor Online Pro and see it rendered live in your browser instantly — no setup, no login needed.

📖

What is an HTML Table and When Should You Use One?

An HTML table is a structured grid of rows and columns used to display data in an organized, readable format. It's one of the oldest and most useful elements in HTML — and one of the most misunderstood.

Before we get into how to build tables, let's get one important thing out of the way: HTML tables are for data, not for layout. In the early days of the web (before CSS), developers used tables to control the layout of entire pages — putting navigation in one column and content in another. That practice is completely outdated and wrong. Don't do it. Use CSS Flexbox or CSS Grid for layouts.

So when should you actually use an HTML table? Use a table when your data genuinely has a row-and-column relationship — when it would look like a spreadsheet in Excel. Good examples include:

  • Pricing plans comparison (Basic vs Pro vs Enterprise)
  • Product specifications (dimensions, weight, materials)
  • Class schedules or timetables
  • Sports statistics or leaderboards
  • Financial data, invoices, expense reports
  • Feature comparison charts
  • Employee or contact directories
💡

Quick Rule: If your data would make sense in a spreadsheet like Excel or Google Sheets, it probably belongs in an HTML table. If it's just a list, use <ul>. If it's layout, use CSS Grid or Flexbox.

🏗️

The Basic HTML Table Structure — Every Tag Explained

An HTML table is built using a specific set of tags that work together. Here is the most basic table you can create — three rows, three columns:

Simplest HTML Table — Copy This First <table> <tr> <th>Name</th> <th>Subject</th> <th>Score</th> </tr> <tr> <td>Arjun</td> <td>Mathematics</td> <td>92</td> </tr> <tr> <td>Priya</td> <td>Science</td> <td>88</td> </tr> </table>
Live Preview — What this looks like in a browser
NameSubjectScore
ArjunMathematics92
PriyaScience88
scroll

That's the foundation. Now let's understand what every single table tag does — because using them correctly is what separates well-structured HTML from messy code:

TagFull NameWhat it does
<table>TableThe outer container that wraps the entire table. Everything else goes inside this.
<tr>Table RowCreates a horizontal row. Every row in your table needs a <tr> tag.
<th>Table HeaderA header cell — bold and centered by default. Use for column titles. Has semantic meaning: tells browsers and screen readers this is a header.
<td>Table DataA regular data cell. This is where your actual content goes in every non-header row.
<thead>Table HeadGroups the header row(s). Not required but strongly recommended — helps browsers, screen readers, and CSS target headers specifically.
<tbody>Table BodyGroups the main data rows. Makes the table structure clear and enables separate styling of body rows.
<tfoot>Table FooterGroups footer rows — totals, summaries, notes at the bottom. Optional but semantically useful.
<caption>Table CaptionA title/description for the table. Appears above the table. Great for accessibility and SEO.
<colgroup>Column GroupDefines groups of columns for styling. Use with <col> to apply CSS to entire columns at once.
scroll

The Proper Full Table Structure (Best Practice)

The minimal table works — but a properly structured table uses <thead>, <tbody>, and <tfoot>. This is not just about being a perfectionist. These tags genuinely matter:

  • Screen readers use <thead> to announce column headers when reading data cells
  • When printing a long table that spans pages, browsers repeat the <thead> on every page automatically
  • CSS can target thead, tbody, and tfoot separately for clean, maintainable styling
  • Google uses semantic structure to understand your table data
Properly Structured HTML Table — Use This Template <table> <caption>Monthly Sales Report — Q1 2025</caption> <thead> <tr> <th scope="col">Month</th> <th scope="col">Revenue</th> <th scope="col">Orders</th> <th scope="col">Growth</th> </tr> </thead> <tbody> <tr> <td>January</td> <td>₹1,24,500</td> <td>248</td> <td>+12%</td> </tr> <tr> <td>February</td> <td>₹1,38,200</td> <td>276</td> <td>+11%</td> </tr> <tr> <td>March</td> <td>₹1,62,800</td> <td>325</td> <td>+18%</td> </tr> </tbody> <tfoot> <tr> <td><strong>Q1 Total</strong></td> <td><strong>₹4,25,500</strong></td> <td><strong>849</strong></td> <td><strong>+14%</strong></td> </tr> </tfoot> </table>

Always add scope="col" to column header cells (<th>) and scope="row" to row header cells. This tells screen readers exactly which cells a header applies to — making your table fully accessible for visually impaired users.

🔀

colspan and rowspan — Merging Table Cells

Sometimes your table data doesn't fit neatly into equal-sized cells. You need one cell to span across multiple columns or rows. That's exactly what colspan and rowspan are for — and they're one of the trickier parts of HTML tables that trips up a lot of beginners.

colspan — Span Across Multiple Columns

colspan="n" makes a single cell take up the width of n columns. Think of it as merging cells horizontally — like merging cells in Excel.

colspan Example — Merging Columns <table> <thead> <tr> <!-- This header spans all 3 columns --> <th colspan="3">Student Exam Results — 2025</th> </tr> <tr> <th>Student</th> <th>Theory</th> <th>Practical</th> </tr> </thead> <tbody> <tr> <td>Rahul Verma</td> <td>78</td> <td>45</td> </tr> <tr> <td>Anita Sharma</td> <td>91</td> <td>48</td> </tr> </tbody> </table>
Live Preview — colspan in action
Student Exam Results — 2025
StudentTheoryPractical
Rahul Verma7845
Anita Sharma9148
scroll

rowspan — Span Across Multiple Rows

rowspan="n" makes a single cell take up the height of n rows — merging cells vertically. This is very useful when a category label applies to multiple rows of data below it.

rowspan Example — Merging Rows <table> <thead> <tr> <th>Department</th> <th>Employee</th> <th>Role</th> </tr> </thead> <tbody> <tr> <!-- This cell spans 2 rows — covers both Design employees --> <td rowspan="2">Design</td> <td>Meera Patel</td> <td>UI Designer</td> </tr> <tr> <!-- No <td> for Department here — rowspan covers it --> <td>Vikas Nair</td> <td>UX Researcher</td> </tr> <tr> <td rowspan="2">Engineering</td> <td>Arjun Singh</td> <td>Frontend Dev</td> </tr> <tr> <td>Priya Sharma</td> <td>Backend Dev</td> </tr> </tbody> </table>
Live Preview — rowspan in action
DepartmentEmployeeRole
DesignMeera PatelUI Designer
Vikas NairUX Researcher
EngineeringArjun SinghFrontend Dev
Priya SharmaBackend Dev
scroll
⚠️

The most common rowspan/colspan mistake: When a cell spans multiple rows or columns, you must remove the corresponding cells from the rows/columns it covers. If you use rowspan="2", the next row should have one fewer <td> because that cell is already occupied by the rowspan. Forgetting this is why tables look broken.

🎨

Styling HTML Tables with CSS — 3 Professional Designs

An unstyled HTML table looks like something from 1998. The good news: with about 20 lines of CSS, you can make any table look genuinely professional. Here are three complete, ready-to-use table styles.

Style 1 — Clean Gradient Header Table

CSS — Clean Gradient Header table { width: 100%; border-collapse: collapse; border-radius: 10px; overflow: hidden; font-family: 'Plus Jakarta Sans', sans-serif; } thead tr { background: linear-gradient(135deg, #6a6edb, #9a9ef8); } th { color: white; font-weight: 700; padding: 12px 16px; text-align: left; font-size: 13px; } td { padding: 10px 16px; font-size: 13px; color: #44448a; border-bottom: 1px solid #c8c8f0; } tbody tr:hover { background: rgba(106, 110, 219, 0.08); cursor: pointer; } tbody tr:last-child td { border-bottom: none; }
Live Preview — Gradient Header Style
ProductCategoryPriceStock
HTML Editor ProDeveloper ToolFree✅ Live
CSS FrameworkFrontend₹999/mo✅ Live
JS LibraryJavaScript₹499/mo⏳ Beta
Design SystemUI/UX₹1,499/mo🔜 Soon
scroll

Style 2 — Striped Zebra Table

CSS — Striped Zebra Rows table { width: 100%; border-collapse: collapse; } th { background: #eaeaff; color: #0c0c2a; font-weight: 800; padding: 10px 14px; text-align: left; border-bottom: 2px solid #6a6edb; } td { padding: 9px 14px; color: #44448a; border-bottom: 1px solid #c8c8f0; } tbody tr:nth-child(even) td { background: #f5f5ff; /* This is the "zebra stripe" */ } tbody tr:hover td { background: #eaeaff; }
Live Preview — Striped Zebra Style
RankDeveloperLanguagePoints
🥇 1Arjun SinghJavaScript9,842
🥈 2Priya SharmaPython9,210
🥉 3Rahul VermaTypeScript8,775
4Meera PatelReact8,440
5Vikas NairNode.js8,120
scroll

Style 3 — Borderless Minimal Table

CSS — Borderless Minimal Style table { width: 100%; border-collapse: collapse; } th { color: #8888b8; font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; padding: 8px 14px; border-bottom: 1px solid #c8c8f0; text-align: left; } td { padding: 12px 14px; color: #0c0c2a; border-bottom: 1px solid #f0f0ff; font-size: 13px; } tbody tr:last-child td { border-bottom: none; }
📱

Responsive HTML Tables — Making Tables Work on Mobile

Tables are the element most likely to break on mobile. A table with 6 columns that looks perfect on a desktop will overflow and get cut off on a phone screen. There are three good solutions depending on your situation.

Solution 1 — Horizontal Scroll Wrapper (Easiest)

The simplest approach: wrap your table in a <div> with overflow-x: auto. On small screens, the table will scroll horizontally rather than getting cut off. Users can swipe to see all the data.

HTML + CSS — Horizontal Scroll Wrapper <!-- HTML: Wrap the table in this div --> <div class="table-scroll"> <table> <!-- your table here --> </table> </div> /* CSS */ .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; /* smooth scroll on iOS */ border-radius: 10px; } table { min-width: 600px; /* Forces table to stay at this width */ width: 100%; border-collapse: collapse; }

Solution 2 — Stack Cells on Mobile (Advanced)

For a more elegant mobile experience, you can completely restructure the table on small screens — stacking each row's data vertically instead of horizontally. This uses CSS and HTML data attributes to show the column label next to each value.

HTML — Add data-label to each td <tbody> <tr> <td data-label="Name">Arjun Singh</td> <td data-label="Role">Frontend Developer</td> <td data-label="Salary">₹85,000/mo</td> </tr> </tbody> /* CSS — Stack layout on mobile */ @media (max-width: 600px) { thead { display: none; } /* Hide header row on mobile */ tr { display: block; border: 1px solid #c8c8f0; border-radius: 8px; margin-bottom: 12px; padding: 8px; } td { display: flex; justify-content: space-between; padding: 6px 8px; border-bottom: 1px solid #f0f0ff; } td::before { content: attr(data-label); /* Shows the column label */ font-weight: 700; color: #0c0c2a; } }
📱

Test your table on mobile using our HTML Editor Online Pro. Switch to iPhone simulation mode to instantly see how your table behaves on a small screen — before you publish it.

💼

Real-World HTML Table Examples You Can Copy

Theory is great but real examples are better. Here are complete, ready-to-use HTML table templates for the most common use cases you'll encounter in real projects.

Pricing Table

HTML Pricing Comparison Table <div class="table-scroll"> <table> <caption>Plan Comparison — Choose the Right Plan for You</caption> <thead> <tr> <th>Feature</th> <th>Free</th> <th>Pro — ₹499/mo</th> <th>Enterprise</th> </tr> </thead> <tbody> <tr> <td>Storage</td> <td>1 GB</td> <td>50 GB</td> <td>Unlimited</td> </tr> <tr> <td>Custom Domain</td> <td></td> <td></td> <td></td> </tr> <tr> <td>Priority Support</td> <td></td> <td></td> <td>24/7 Dedicated</td> </tr> </tbody> </table> </div>

Class Timetable / Schedule

HTML Weekly Timetable Using colspan <table> <thead> <tr> <th>Time</th> <th>Monday</th> <th>Tuesday</th> <th>Wednesday</th> </tr> </thead> <tbody> <tr> <td>9:00 AM</td> <td>Mathematics</td> <!-- colspan spans Tuesday + Wednesday --> <td colspan="2">Lab Session (2 periods)</td> </tr> <tr> <td>10:00 AM</td> <td>Science</td> <td>English</td> <td>History</td> </tr> </tbody> </table>

Preview All These Tables Right Now — For Free

Copy any table code from this guide and paste it into HTML Editor Online Pro. See it rendered instantly. Switch to iPhone mode to check mobile layout. No signup, no download — it just works.

📊 Open HTML Editor Free →
⚠️

Common HTML Table Mistakes and How to Fix Them

These are the mistakes that trip up almost every beginner working with HTML tables. Learn them now so you don't spend an hour debugging later.

Mistake 1 — Unequal number of cells in rows

Every row in a table must have the same total number of cells (accounting for any colspan/rowspan values). If row 1 has 3 columns but row 2 has 2, your table will look broken with misaligned columns. Count your cells carefully. If you use colspan="2" in one row, the next row still needs enough cells to fill all columns.

Mistake 2 — Using tables for page layout

We already covered this, but it's worth repeating because it's so common. Tables are for data. Putting your navigation in a table cell and your content in another cell is wrong in 2025. Use CSS Flexbox (display: flex) or CSS Grid (display: grid) for layouts — always.

Mistake 3 — Forgetting border-collapse

By default, HTML table cells have double borders — a border on the cell and a border on the table. Without border-collapse: collapse in your CSS, your table looks like it has thick double-line borders everywhere. Always add this:

table { border-collapse: collapse; } /* Always add this */

Mistake 4 — No thead/tbody structure

Writing all rows directly inside <table> without <thead> and <tbody> works visually, but it's semantically wrong. Screen readers won't know which rows are headers. When printing a long table, headers won't repeat on each page. Always use the proper structural tags.

Mistake 5 — No scope attribute on th elements

The scope attribute on <th> tells screen readers and assistive technology whether a header applies to its column (scope="col") or its row (scope="row"). Without it, your table is not fully accessible. It's one attribute, two seconds of work — always add it.

Frequently Asked Questions About HTML Tables

Q: How do I add a border to an HTML table?
The right way is with CSS, not the old HTML border attribute. Add this to your CSS: table, th, td { border: 1px solid #c8c8f0; } and table { border-collapse: collapse; }. The border-collapse: collapse merges the cell borders into single lines instead of double lines.

Q: How do I make alternate rows different colors (zebra stripes)?
Use the CSS :nth-child selector: tbody tr:nth-child(even) { background-color: #f5f5ff; }. This applies the background only to even-numbered rows (2nd, 4th, 6th...) creating a striped pattern that makes long tables much easier to read.

Q: What is the difference between th and td?
<th> (Table Header) is a header cell — by default it's bold and centered. More importantly, it has semantic meaning: it tells browsers, search engines, and screen readers "this is a header that describes the data below/beside it." <td> (Table Data) is a regular data cell with no special semantic weight. Use <th> for column and row headers, <td> for everything else.

Q: How do I center text in a table cell?
Use CSS: td { text-align: center; } for horizontal centering. For vertical centering: td { vertical-align: middle; }. Avoid the old HTML align attribute — it's deprecated and shouldn't be used.

Q: Can I put images, buttons, and links inside table cells?
Yes, absolutely. A table cell <td> or <th> is just a container — you can put any HTML content inside it: images, links, buttons, forms, other elements. Many data tables include action buttons in the last column for edit/delete/view operations.

Q: How do I make a table sortable?
HTML alone can't sort tables — you need JavaScript for that. The simplest approach is to use a small JavaScript library like DataTables (free, open source). Or you can write a custom sort function using vanilla JavaScript that sorts the table rows when a header cell is clicked. This is a common intermediate JavaScript exercise.