HTML Tables can be used to arrange content on a web page. In the past, using tables was the only practical way to achieve a custom page layout. In today’s web page development, you have alternatives such as using div elements and CSS.
However, many web developers still prefer to use tables for customizing the layout of their pages. Tables may seem difficult at first, but after working through this tutorial and some practice, you will quickly become familiarized with them.
The table Element
A table is divided into rows (
A
Cell 1A | Cell 1B |
Cell 2A | Cell 2B |
Table Headers
Table headers can be used if you want to specify that a row in the table should be treated as a header. Header information in a table is defined with the
Modern browsers apply different formatting to your header elements. Alternatively, you can use CSS to apply your own custom settings.
Col A | Col B |
---|---|
Cell 1A | Cell 1B |
Cell 2A | Cell 2B |
Spanning rows and cells
Just as you would with a spreadsheet document, there will be instances where you need to span multiple rows or cells.
You can do so by using the rowspan and colspan attributes in the
Col A | Col B | Col C |
---|---|---|
Row 1 Cell 1 | Row 1 Cell 2 | Row 1 Cell 3 |
Row 2 Cell 2 | Row 2 Cell 3 | |
Row 3 Cell 1 |
Padding and Spacing
You can use the cellpadding and cellspacing attributes to adjust the white space on your tables. Although using CSS is the preferred method.
Spacing will affect the distance between the cells, while padding affects the distance between cell borders and the content within the cell.
Cell 1A | Cell 1B |
Cell 2A | Cell 2B |
Table Captions
The