<table> tag<td> (table data)<tr> (table row)<th> (table header) <table>
<tr>
<th>header 1<th/>
<th>header 2<th/>
<tr/>
<tr>
<td>1st row first cell<td/>
<td>1st row second cell<td/>
<tr/>
<tr>
<td>2nd row first cell<td/>
<td>2nd row second cell<td/>
<tr/>
<table/>
Result:
| HEADER 1 | HEADER 2 |
|---|---|
| 1st row first cell | 1st row second cell |
| 2nd row first cell | 2nd row second cell |
Use the colspan and rowspan attributes on the td tag.
<table>
<tr>
<td>1st row first cell<td/>
<td>1st row second cell<td/>
<tr/>
<tr>
<td colspan="2">2nd row big cell<td/>
<tr/>
<table/>
You can I add css style to each <td> separately, or you can use
the <colgroup> tag with the <col> tag to define, in html the
style of each columns.
<table>
<colgroup>
<col />
<col style="background-color: red; width: 42px" span="2" />
<colgroup/>
<tr>
<td>1st row first cell<td/>
<td>1st row second cell<td/>
<td>1st row third cell<td/>
<tr/>
<tr>
<td>2nd row first cell<td/>
<td>2nd row second cell<td/>
<td>2nd row third cell<td/>
<tr/>
<table/>
In the example, the first row has no style applied but is still specify with <col /> and
the second and third row have red background and 42px width apply. It apply on the two columns
with the span attribute.
Add a text above the table with the <caption> tag.
<table>
<caption>
Title of the table.
<caption/>
<tr>
<td>1st row first cell<td/>
<td>1st row second cell<td/>
<tr/>
<table/>
In more complex table, define the structure with <thead>, <tfoot> and <tbody>.
It is useful for styling with css.
<table>
<thead>
<tr>
<th>Header 1<th/>
<th>Header 2<th/>
<tr/>
<thead/>
<tfoot>
<tr>
<td colspan="2">footer text<td/>
<tr/>
<tfoot/>
<tbody>
<tr>
<td>1st row first cell<td/>
<td>1st row second cell<td/>
<tr/>
<tbody/>
<table/>
To make the table easier to read for screen reader, use the scope attribute on the header.
Either for column or row.
The value possible are: row, col, colgroup and rowgroup.
<table>
<tr>
<th scope="col">Header 1<th/>
<th scope="col">Header 2<th/>
<tr/>
<tr>
<td>1st row first cell<td/>
<td>1st row second cell<td/>
<tr/>
<table/>