bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths
Learn/HTML/HTML Foundations
HTML•HTML Foundations

HTML Table Headers

HTML tables can have headers for each column or row, or for many columns/rows.

EMILTOBIASLINUS
8:00
9:00
10:00
11:00
12:00
13:00
MONTUEWEDTHUFRI
8:00
9:00
10:00
11:00
12:00
DECEMBER

HTML Table Headers

Table headers are defined with th elements. Each th element represents a table cell.

Example

Formatted code
  <table>
  <tr>
    <th>Firstname</th>

  <th>Lastname</th>
    <th>Age</th>
  </tr>

  <tr>
    <td>Jill</td>
    <td>Smith</td>

  <td>50</td>
  </tr>
  <tr>
    <td>Eve</td>

  <td>Jackson</td>
    <td>94</td>
  </tr>
</table>

Live preview

Vertical Table Headers

To use the first column as table headers, define the first cell in each row as a <th> element:

Example

Formatted code
  <table>
  <tr>
    <th>Firstname</th>

  <td>Jill</td>
    <td>Eve</td>
  </tr>

  <tr>

  <th>Lastname</th>
    <td>Smith</td>

  <td>Jackson</td>
  </tr>
  <tr>
    <th>Age</th>
    <td>94</td>

  <td>50</td>
  </tr>
</table>

Live preview

Align Table Headers

By default, table headers are bold and centered:

FirstnameLastnameAge
JillSmith50
EveJackson94

To left-align the table headers, use the CSS text-align property:

th {
 text-align: left;
}

Header for Multiple Columns

You can have a header that spans over two or more columns.

NameAge
JillSmith50
EveJackson94

To do this, use the colspan attribute on the <th> element:

Example

Formatted code
  <table>
  <tr>
    <th colspan="2">Name</th>
    <th>Age</th>
  </tr>

  <tr>
    <td>Jill</td>
    <td>Smith</td>

  <td>50</td>
  </tr>
  <tr>
    <td>Eve</td>

  <td>Jackson</td>
    <td>94</td>
  </tr>
</table>

Live preview

You will learn more about colspan and rowspan in the Table colspan & rowspan chapter.

Table Caption

You can add a caption that serves as a heading for the entire table.

MonthSavings

To add a caption to a table, use the <caption> tag:

Example

Formatted code
<table style="width:100%">
 <caption>Monthly savings</caption>
 <tr>
   <th>Month</th>
   <th>Savings</th>
 </tr>
 <tr>
   <td>January</td>
   <td>$100</td>
 </tr>
 <tr>
   <td>February</td>
   <td>$50</td>
 </tr>

</table>

Live preview

Note

The <caption> tag should be inserted immediately after the <table> tag.

Previous

HTML Table Sizes

Next

HTML Table Padding & Spacing

This chapter

Overview
56

Lessons

191m

Read time

1. HTML Tutorial2. HTML Introduction3. HTML Editors4. HTML Elements5. HTML Attributes6. HTML Headings7. HTML Paragraphs8. HTML Styles9. HTML Text Formatting10. HTML Comments11. HTML Colors12. HTML RGB and RGBA Colors13. HTML HEX Colors14. HTML HSL and HSLA Colors15. HTML Styles - CSS16. HTML Links17. HTML Links - Different Colors18. HTML Links - Create Bookmarks19. HTML Images20. HTML Image Maps21. HTML Background Images22. HTML <picture> Element23. HTML Favicon24. HTML Page Title25. HTML Tables26. HTML Table Borders27. HTML Table Sizes28. HTML Table Headers29. HTML Table Padding & Spacing30. HTML Table Colspan & Rowspan31. HTML Table Styling32. HTML Table Colgroup33. HTML Lists34. HTML Unordered Lists35. HTML Ordered Lists36. HTML Other Lists37. HTML Block and Inline Elements38. HTML Div Element39. HTML class Attribute40. HTML id Attribute41. HTML Buttons42. HTML Iframes43. HTML JavaScript44. HTML File Paths45. HTML - The Head Element46. HTML Layout Elements and Techniques47. HTML Responsive Web Design48. HTML Computer Code Elements49. HTML Semantic Elements50. HTML Style Guide51. HTML Entities52. HTML Symbols53. Using Emojis in HTML54. HTML Encoding (Character Sets)55. HTML Uniform Resource Locators56. HTML Versus XHTML

On this page

HTML Table HeadersVertical Table HeadersAlign Table HeadersHeader for Multiple ColumnsTable Caption