Home

HTML - simple table


Simple Table Code

<table>
 <thead>
 <tr>
  <th>heading col 1</th>
  <th>heading col 2</th>
 </tr>
 </thead>
 <tr>
  <td>row 1, column 1</td>
  <td>row 1, column 2</td>
 </tr>
 <tr>
  <td>row 2, column 1</td>
  <td>row 2, column 2</td>
 </tr>
</table>
heading col 1 heading col 2
row 1, column 1 row 1, column 2
row 2, column 1 row 2, column 2

Table with border code

<table border="1">
 <thead>
 <tr>
  <th>heading column 1</th>
  <th>heading column 2</th>
 </tr>
 </thead>
 <tr>
  <td>row 1, column 1</td>
  <td>row 1, column 2</td>
 </tr>
 <tr>
  <td>row 2, column 1</td>
  <td>row 2, column 2</td>
 </tr>
</table>
heading column 1 heading column 2
row 1, column 1 row 1, column 2
row 2, column 1 row 2, column 2

table with cellpadding and cellspacing

<table border="1" cellpadding="4" cellspacing="6" >
 <thead>
 <tr>
  <th>heading column 1</th>
  <th>heading column 2</th>
 </tr>
 </thead>
 <tr>
  <td>row 1, column 1</td>
  <td>row 1, column 2</td>
 </tr>
 <tr>
  <td>row 2, column 1</td>
  <td>row 2, column 2</td>
 </tr>
</table>
heading column 1 heading column 2
row 1, column 1 row 1, column 2
row 2, column 1 row 2, column 2

Table with background color

In XHTML 1.1 the attribute 'bgcolor' is not permitted for the <td> tag.

<table border="1" >
 <thead>
 <tr>
  <th>heading column 1</th>
  <th>heading column 2</th>
 </tr>
 </thead>
 <tr>
  <td bgcolor="yellow" >row 1, column 1</td>
  <td>row 1, column 2</td>
 </tr>
 <tr>
  <td>row 2, column 1</td>
  <td>row 2, column 2</td>
 </tr>
</table>
heading column 1 heading column 2
row 1, column 1 row 1, column 2
row 2, column 1 row 2, column 2