Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Tables | HTML Course lesson | BraveProgrammer
  1. Courses
  2. /
  3. HTML Course

Lesson 55 of 55

·HTML

Tables

10 min

Course progress100%

What you'll learn

Keep these ideas in mind as you work through the lesson.

5 points
  • Basic table markup (`<table>`, `<tr>`, `<td>`, `<th>`)
  • Semantic grouping (`<thead>`, `<tbody>`, `<tfoot>`)
  • Captions and accessibility best practices
  • Cell spanning with `colspan`/`rowspan`
  • Responsive table techniques using overflow containers
  • Tabular Data (<table>)

    <table>
      <caption>Quarterly Sales</caption>
      <thead>
        <tr>
          <th scope='col'>Region</th>
          <th scope='col'>Q1</th>
          <th scope='col'>Q2</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <th scope='row'>North America</th>
          <td>1200</td>
          <td>1300</td>
        </tr>
        <tr>
          <th scope='row'>Europe</th>
          <td>900</td>
          <td>950</td>
        </tr>
      </tbody>
    </table>
    

    Key elements

    • <caption> – Provides a textual description for screen readers and improves SEO.
    • <thead>, <tbody>, <tfoot> – Group rows semantically; aids screen‑reader navigation.
    • scope – Clarifies whether a <th> labels a column (col) or a row (row).
    • colspan, rowspan – Merge cells when needed (e.g., for section headers).

    Accessibility tips

    • Never use tables for layout – use CSS Grid or Flexbox instead.
    • Provide a concise, unique <caption>.
    • Use scope or id/headers attributes for complex tables.
    • For mobile devices, wrap the table in a container with overflow-x:auto to allow horizontal scrolling without breaking the layout.

    Responsive table pattern

    .responsive-table {
      width: 100%;
      border-collapse: collapse;
      overflow-x:auto;
    }
    

    Apply the class to the <table> element to create a scrollable table on small screens.

    Tip: Test your tables with a screen reader (e.g., NVDA) to verify that headings are announced correctly and that the table is navigable.


    Quick checklist for tables

    1. <caption> present and descriptive? ✅
    2. <th> elements include scope attribute? ✅
    3. Table wrapped in a scrolling container for mobile? ✅
    4. No presentational attributes (e.g., border="1")? ✅
    5. Complex tables use id/headers for cell relationships? ✅

    If any answer is “no”, adjust the markup accordingly.

    Make it stickPractice what you've learned1 quiz · 2 practical tests · Optional activities from HTML CourseBrowse activities
    Previous lessonListsCourse completeBack to the curriculumBack to HTML Course curriculum