HTML-Tables Cheatsheet

Html:Tables

Table Example using Html and CSS:
<tr> The table row element is used to add rows to a table before adding table data and table headings.
<td> The table data element, <td>, can be nested inside a table row element,<td>, to add a cell of data to a table.
<th> The table heading element, <th>, is used to add titles to rows and columns of a table and must be enclosed in a table row element,<tr>.
<thead> The table head element, <thead>, defines the headings of table columns encapsulated in table rows.
<tbody> The table body element, <tbody>, is a semantic element that will contain all table data other than table heading and table footer content. If used, <tbody> will contain all table row <tr> elements, and indicates that <tr> elements make up the body of the table. <table> cannot have both <tbody> and <tr> as direct children.

The table row element: <tr>

The table row element is used to add rows to a table before adding table data and table headings.

Example:

...

The table data element: <td>

The table data element, <td>, can be nested inside a table row element,<td>, to add a cell of data to a table.

Example:

cell one data cell two data

The Table Head Element: <thead>

The table head element, <thead>, defines the headings of table columns encapsulated in table rows.

Example:

heading 1 heading 2
col 1 col 2

The rowspan Attribute:

Similar to colspan, the rowspan attribute on a table header or table data element indicates how many rows that particular cell should span within the table. The rowspan value is set to 1 by default and will take any positive integer up to 65534.

Example:

row 1: col 1 col 2
row 2 (this row will span 2 rows): col 1 col 2
col 1 col 2
row 3: col 1 col 2

Table Body Element: <tbody>

The table body element, <tbody>, is a semantic element that will contain all table data other than table heading and table footer content. If used, <tbody> will contain all table row <tr> elements, and indicates that <tr> elements make up the body of the table. <table> cannot have both <tbody> and <tr> as direct children.

Example:

row 1
row 2
row 3

Table Heading Element: <th>

The table heading element, <th>, is used to add titles to rows and columns of a table and must be enclosed in a table row element,<tr>.

Example:

column one column two
1 2

Colspan Attribute:

The colspan attribute on a table header <th> or table data <td> element indicates how many columns that particular cell should span within the table. The colspan value is set to 1 by default and will take any positive integer between 1 and 1000.

Example:

row 1: col 1 col 2 col 3
row 2: col 1 (will span 2 columns) col 2 col 3