HTML & CSS: Tables 1 |
|
Table Structure
Tables are a widely-used way of organizing and presenting tabular information on the Web. Let's use a table to present common elements for setting up tables:
Element | Description |
---|---|
table | Sets up a table |
tr | Declares a row |
th | Declares a header cell in a row |
td | Defines a cell in a row |
Table Components
A table has three main components, thead, tbody and tfoot:
Element | Description |
---|---|
thead | Holds one or more rows together into a header |
tbody | Holds the main rows |
tfoot | Holds the rows in the footer |
Table Formatting
A table has several CSS formatting properties:
Property | Description |
---|---|
border-collapse | Determines whether there is space between adjacent cells. Options are 'collapse' (no space) and 'separate' (space). |
border-spacing | Indicates the space between adjacent cells (when the border is not collapsed) |
border | A 'shorthand' CSS property that can set several border properties in 1 line. (Note how it is used in the example below.) |
padding | Space between a cell's contents and its border |
text-align | Align horizontally |
vertical-align | Align vertically |
An Example