mc0de
Advanced HTML · Lesson 02 of 13

HTML Tables

Turn rows and columns into something useful! Learn how to organize data, create clear headers, group information, and build accessible tables that make sense to everyone.

HTMLRows & Columns Accessible DataHands-On Practice
● ● ●   tables.html
<table>
  <tr>
    <th>Skill</th>
    <th>Level</th>
  </tr>
  <tr>
    <td>HTML</td>
    <td>Advanced</td>
  </tr>
</table>
SkillLevel
HTMLAdvanced
01 / Getting Started

Why Use HTML Tables?

Think about a class schedule, a product comparison, or a list of monthly expenses. Sometimes information is easier to understand when it’s arranged into rows and columns.

That’s exactly what HTML tables are for: presenting data with meaningful relationships between rows and columns.

My Coding Goals
LanguageGoal
HTMLBuild structured pages
CSSDesign beautiful layouts
JavaScriptAdd interactivity
Remember: Tables are for tabular data, not for arranging the overall layout of a website. Use CSS Grid or Flexbox for page layouts.
02 / The Basics

Meet the Table Elements

Every table starts with <table>. Inside it, you’ll build rows using <tr>, header cells using <th>, and regular data cells using <td>.

Your first table
<table>
  <tr>
    <th>Name</th>
    <th>Favorite Language</th>
  </tr>
  <tr>
    <td>Alex</td>
    <td>HTML</td>
  </tr>
  <tr>
    <td>Sam</td>
    <td>Python</td>
  </tr>
</table>
NameFavorite Language
AlexHTML
SamPython

Each <tr> creates a new row. The cells inside that row determine the columns. Your browser understands the structure even before you add CSS styling.

03 / Clear Labels

Give Your Table a Title and Headers

Tables become much easier to understand when readers know what the information represents.

Use <caption> for the table’s title and scope="col" or scope="row" to identify header relationships.

Captions and accessible headers
<table>
  <caption>Weekly Study Hours</caption>
  <tr>
    <th scope="col">Day</th>
    <th scope="col">Hours</th>
  </tr>
  <tr>
    <th scope="row">Monday</th>
    <td>2</td>
  </tr>
  <tr>
    <th scope="row">Tuesday</th>
    <td>3</td>
  </tr>
</table>
Weekly Study Hours
DayHours
Monday2
Tuesday3
Accessibility tip: Clear header relationships help people using screen readers understand which data belongs to each row or column.
04 / Better Organization

Meet the Head, Body, and Footer

For larger tables, HTML lets you group different sections with <thead>, <tbody>, and <tfoot>.

A table with sections
<table>
  <thead>
    <tr>
      <th scope="col">Course</th>
      <th scope="col">Hours</th>
    </tr>
  </thead>
  <tbody>
    <tr><td>HTML</td><td>3</td></tr>
    <tr><td>CSS</td><td>2</td></tr>
  </tbody>
  <tfoot>
    <tr><th scope="row">Total</th><td>5</td></tr>
  </tfoot>
</table>
CourseHours
HTML3
CSS2
Total5

These sections make your code easier to read and maintain. They also give you useful hooks when styling tables with CSS.

05 / Combining Cells

Make Cells Span Rows or Columns

Sometimes a heading needs to stretch across multiple columns, or a category applies to several rows.

Use colspan to span columns and rowspan to span rows.

Combining cells
<table>
  <tr>
    <th colspan="2">My Learning Plan</th>
  </tr>
  <tr>
    <th scope="col">Day</th>
    <th scope="col">Topic</th>
  </tr>
  <tr><td>Monday</td><td>HTML</td></tr>
  <tr><td>Tuesday</td><td>CSS</td></tr>
</table>
My Learning Plan
DayTopic
MondayHTML
TuesdayCSS
Try this: Experiment with rowspan="2" in the sandbox. Remember that a cell spanning two rows occupies space in both rows, so you must account for that when adding other cells.
06 / Styling Tables

Make Your Data Easier to Read

A little CSS can transform a plain table into something much more readable. Borders, spacing, alternating row colors, and hover effects all help.

Simple table styling
<style>
  table {
    width: 100%;
    border-collapse: collapse;
  }
  th, td {
    border: 1px solid #cbd5e1;
    padding: 12px;
    text-align: left;
  }
  thead {
    background: #dff7f4;
  }
  tbody tr:nth-child(even) {
    background: #f1f5f9;
  }
</style>

For narrow screens, put a wide table inside a container with overflow-x: auto so visitors can scroll horizontally without breaking the layout.

Design tip: Don’t rely on colors alone to communicate meaning. Keep labels clear and make sure the text has enough contrast.
07 / Best Practices

Build Tables Everyone Can Understand

Before publishing a table, ask yourself whether someone can understand the information quickly and navigate it easily.

  • Use tables for data, not for page layout.
  • Add a descriptive <caption> when it helps explain the table.
  • Use real header cells and appropriate scope attributes.
  • Group complex data logically with table sections.
  • Use rowspan and colspan carefully; complex spanning can make tables harder to navigate.
  • Allow wide tables to scroll on smaller screens.
  • Keep data accurate, readable, and consistently formatted.

A well-structured table doesn’t just look organized. It makes information genuinely easier to use.

🚀 mC0de Challenge

Build a Weekly Learning Schedule

You’ve learned the building blocks. Now create a schedule that shows what you’re studying throughout the week!

Your Mission

  1. Create a table with a descriptive caption.
  2. Add three columns: Day, Topic, and Study Time.
  3. Include at least four days of learning activities.
  4. Use <thead> and <tbody>.
  5. Use scope="col" for column headings.
  6. Add a footer showing your total study hours.
Extra challenge: Add alternating row colors and a category heading using colspan. Make your table something you’d be proud to share!
💻 Interactive HTML Sandbox

Build Your Table!

Edit the HTML, add your own schedule, and run the code to see your table come to life. Try different headings, rows, and styles!

Live Result
Lesson 02 Recap

What You’ve Learned

You’re Getting Organized!

You’ve turned plain information into structured, readable data. That’s a skill you’ll use in schedules, reports, dashboards, comparisons, and much more.

  • How to create tables using rows and cells.
  • How to add captions and accessible headers.
  • How to group tables with heads, bodies, and footers.
  • How to span rows and columns.
  • How to style tables for readability.

Next up: Iframes — discover how to bring other content into your web pages!

Your Learning Journey

0 / 13 Completed

Keep going! Every completed lesson brings you closer to mastering Advanced HTML.

🎉

Nice Work!

You've learned how to organize information into meaningful rows and columns, create accessible headers, and build your own weekly learning schedule. You're making great progress!