CSS Table Designs

HTML table model allows us to arrange data in tabular presentation, using a model of horizontal rows and vertical columns. This lesson breaks down the CSS styling properties into their respective groups and shows you how to use them to format HTML tables using CSS instead of HTML tag attributes.

A simple HTML table structure with 3 rows and 3 columns.

css html table structure

HTML Source Code

How to set Table width and height in CSS

To specify Table width and height, use CSS width, height properties. Here the table width as 30% and height of the td set to 40px.


css table width css table height

Source Code

How to set the table column width in CSS

To specify column width in CSS, use the width property to td.


css column width

CSS Table Row height

You can set Row Height through CSS line-height property it set to each tr.

When you set this property, each row has heigh of 50 pixel.

css row height

CSS Table border

To specify table border in CSS, use the CSS border property.

In the above CSS code, the border property applied to Table,Table Head and each TD.

css table border

Full Source

CSS Collapse Table borders

The CSS Collapse property takes two values, separate and collapse.

separate : The separate value forced all cells have their own independent borders and allow spaces between those cells.

collapse : This value collapse all spaces between table borders and cells, so you can see as a single line border.


css table collapse border

CSS Table Text Align

You can align text horizontally and vertically in CSS. For horizontal alignment you can use CSS text-align property and for vertically you can use vertical-align property.

css table horizontal text align

css table vertical text align


css table text align

CSS Table Cell Padding

CellPadding is used to control the space between the contents of a Cell and the Cell borders. To specify cell padding in CSS, use the CSS padding property.


css table cell padding

CSS Table Cell Spacing

The Cellspacing attribute places space around each cell in the table. To specify cell Spacing in CSS, use the CSS border-spacing property.


css table cell spacing

Full Source