Account
Categories

HTML Tables


Definition:

When you want to show data in rows and columns, you can use the <table>...</table> element.

Inside this element, <tr> is used for rows, <th> is used for headings, and <td> is used for table data.

All these tags together make a complete table structure.

Syntax (No Attributes)

<table>
  <tr>
    <th>Header 1</th>
    <th>Header 2</th>
  </tr>
  <tr>
    <td>Data 1</td>
    <td>Data 2</td>
  </tr>
</table>

Syntax (With Attributes)

<table border="1" cellpadding="5" cellspacing="0" style="margin:auto;">
  <tr>
    <th>Header 1</th>
    <th>Header 2</th>
  </tr>
  <tr>
    <td>Data 1</td>
    <td>Data 2</td>
  </tr>
</table>

Where:

  • <table> → Table structure
  • <tr> → Table row
  • <td> → Table data
  • <th> → Table heading

Example:

<table border="1">
  <tr>
    <th>Name</th>
    <th>City</th>
  </tr>

  <tr>
    <td>Neha</td>
    <td>Mumbai</td>
  </tr>

  <tr>
    <td>Shilpa</td>
    <td>Delhi</td>
  </tr>
</table>

Output:

Name City
Neha Mumbai
Shilpa Delhi