HTML Tables

Learn how to tables in a web page using HTML elements.

HTML tables are a way to display data in a tabular format in HTML documents. They are created using the <table> element, along with its related elements such as <tr>, <th>, <td>, and <caption>.

Here is an example of a simple HTML table:

<table>
  <caption>Sample Table</caption>
  <tr>
    <th>Header 1</th>
    <th>Header 2</th>
  </tr>
  <tr>
    <td>Row 1, Column 1</td>
    <td>Row 1, Column 2</td>
  </tr>
  <tr>
    <td>Row 2, Column 1</td>
    <td>Row 2, Column 2</td>
  </tr>
</table>

In this example, the <table> element defines the table, the <caption> element defines a caption for the table, the <tr> elements define table rows, the <th> elements define header cells, and the <td> elements define data cells.

HTML tables can also be styled using CSS, which provides more control over their appearance and formatting.

Last updated