HTML table - how to use <table> tag

The HTML <table> tag is used to define a HTML table. the table can contain any number of rows and columns and can be styled as needed.

Tables are sometimes used for page layout, however, div tag and CSS should be used for layout.

Attributes

The table tag supports the global and event attributes.

sortable
Defines that the table is sortable

Examples:

<table border="1"> <tr><th>Country</th><th>Capital</th><th>City</th></tr> <tr><td>China</td><td>Beijing</td><td>Shanghai</td></tr> <tr><td>India</td><td>New Delhi</td><td>Hyderabad</td></tr> <tr><td>Australia</td><td>Canberra</td><td>Sydney</td></tr> </table>


<table border="1"> <thead> <tr><th>Country</th><th>Capital</th><th>City</th></tr> </thead> <tbody> <tr><td>China</td><td>Beijing</td><td>Shanghai</td></tr> <tr><td>India</td><td>New Delhi</td><td>Hyderabad</td></tr> </tbody> <tfoot> <tr><td>Table</td><td>Ends</td><td>Here</td></tr> </tfoot> </table>

Related HTML tags and Useful Links:

  • <table> - used to define a table
  • <thead> - used to define header of the table
  • <tbody> - used to define the table body
  • <tfoot> - used to define footer of the table
  • <th> - used to define header cells
  • <tr> - used to define table row
  • <td> - used to define the cell of the table
  • <caption> - used to define caption / title of the table
  • <col> - used to define properties of columns defined within the <colgroup> tag
  • <colgroup> - used to group one or more columns
  • Learn more about HTML table