HTML Table - 10 Tags and its Attributes (Reference)

Tech:
Html
Since:
1 year ago
Views:
2

The HTML table element is used to present tabular data in HTML. In HTML, a table is a way to organize data in a way that is easy to access and interpret.

<table>

Defines a table.

<table>
  // Table content
</table>

<caption>

Defines a table caption.

<table>
  <caption>
    Table title
  </caption>
  // Table content
</table>

<tr>

Defines a row in a table.

<table>
  <tr>
    // Table content
  </tr>
</table>

<th>

Defines a header cell in a table. Attributes - abbr, scope, colspan, rowspan, headers.

<table>
  <tr>
    <th>Heading 1</th>
    <th>Heading 2</th>
  </tr>
</table>

<td>

Defines a cell in a table. Attributes - colspan, rowspan, headers.

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

<thead>

Groups the header content in a table. Must have one or more tr tags inside.

<table>
  <thead>
    <tr>
      <th>Heading 1</th>
      <th>Heading 2</th>
    </tr>
  </thead>
</table>

<tbody>

Groups the body content in a table. Must have one or more tr tags inside.

<table>
  <tbody>
    <tr>
      <td>Data 1</td>
      <td>Data 2</td>
    </tr>
  </tbody>
</table>

<tfoot>

Groups the footer content in a table after tbody tag.

<table>
  <tfoot>
    <tr>
      <td>Data 1</td>
      <td>Data 2</td>
    </tr>
  </tfoot>
</table>

<colgroup>

Specifies a group of one or more columns in a table for formatting.

<table>
  <colgroup>
    <col span="2" style="background-color:red" />
    <col style="background-color:yellow" />
  </colgroup>
</table>

<col>

Specifies column properties for each column within a colgroup element. Attributes - span.

<table>
  <colgroup>
    <col span="2" style="background-color:red" />
    <col style="background-color:yellow" />
  </colgroup>
</table>