HTML Table & Form

HTML Table

A table in HTML consists of table cells inside rows and columns.
The content of every table is enclosed by these two tags : <table></table>.

Caption

The <caption> element defines a table caption. 
It must be inserted immediately after the <table> tag.

Elements to specify each part of a table


  1. The <thead> tag is used to group header content in an HTML table. 
  1. The <tbody> tag is used to group the body content in an HTML table.
  1. The <tfoot> tag is used to group footer content in an HTML table.

These tags must be:
  • used as a child of a <table> element
  • inserted after any <caption> and <colgroup> elements
  • used in the order of <thead><tbody><tfoot>
  • have one or more <tr> tags inside

The <thead>, <tbody>, and <tfoot> elements will not affect the layout of the table by default. However, you can use CSS to style these elements.

Rows

The <tr> element defines a row of cells in a table.
The row's cells can then be established using a mix of <td> (data cell) and <th> (header cell) elements.

Cells

  1. Each table cell is defined by the <td> element.
  1. The <th> (table headers) are special cells that go at the start of a row or column and define the type of data that row or column contains.

Basic Srtucture


<table>
  <caption>Table Caption</caption>
  <thead>
    <tr>
      <th>column A</th>
      <th>column B</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>1A</td>
      <td>2A</td>
    </tr>
    <tr>
      <td>1B</td>
      <td>2B</td>
    </tr>
  </tbody>