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 (element), and each row is divided into cells (element). Theelement is used to store “table data”. Aelement can contain text and other HTML elements such as links, images, and even other tables. Here is an example of a basic table.

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 theelement. Modern browsers apply different formatting to your header elements. Alternatively, you can use CSS to apply your own custom settings.

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 theelement. Here is an example.

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.

Table Captions

Theelement defines a table caption. This element must be inserted immediately after the starting

tag. You can specify only one caption per table. By default, the table caption will be center-aligned above a table. However, you can use the CSS properties text-align and caption-side can be used to align and place the caption. Table captions are supported by all modern browsers. Here is an example.

Grouping Columns Together

The and

elements can be used to group columns in a table for formatting. This is helpful when you need to format one or more columns rather than applying a style for each cell in each row. Here is an example.

The

,, andelements can be used to group rows within a table, much like the colgroup and col elements. These elements establish a header, body, and footer section in your table. Browsers can use these elements to treat each of these sections independently. Using these elements is also very helpful when formatting rows. Here is an example of its use. Tables appear to be a bit complicated when compared to other HTML elements. However, they are still very useful when you need to display data in an organized fashion.