See this example:
Company | Contact | Country |
---|---|---|
Alfreds Futterkiste | Maria Anders | Germany |
Centro comercial Moctezuma | Francisco Chang | Mexico |
Ernst Handel | Roland Mendel | Austria |
Island Trading | Helen Bennett | UK |
Laughing Bacchus Winecellars | Yoshi Tannamuri | Canada |
Magazzini Alimentari Riuniti | Giovanni Rovelli | Italy |
An HTML table is defined with the <table> tag.
Each table row is defined with the <tr> tag. A table header is defined with the <th> tag. By default, table headings are bold and centered. A table data/cell is defined with the <td> tag.
See this example:
Note: The <td> elements are the data containers of the table.
They can contain all sorts of HTML elements; text, images, lists, other tables, etc.
If you do not specify a border for the table, it will be displayed without borders.
A border is set using the CSS border property:
See this example:
Remember to define borders for both the table and the table cells.
If you want the borders to collapse into one border, add the CSS border-collapse property:
See this example:
Cell padding specifies the space between the cell content and its borders.
If you do not specify a padding, the table cells will be displayed without padding.
To set the padding, use the CSS padding property:
See this example:
By default, table headings are bold and centered.
To left-align the table headings, use the CSS text-align property:
See this example:
Border spacing specifies the space between the cells.
To set the border spacing for a table, use the CSS border-spacing property:
See this example:
Note: If the table has collapsed borders, border-spacing has no effect.
To make a cell span more than one column, use the colspan attribute:
See this example:
To make a cell span more than one row, use the rowspan attribute:
See this example:
To add a caption to a table, use the
See this example:
Note: The <caption> tag must be inserted immediately after the <table> tag.