Smal SEO Tool

CSS Tables

CSS provides several properties to control the layout and appearance of HTML tables, making them easier to read and more visually appealing.

Table Borders

To specify table borders in CSS, use the border property. The border-collapse: collapse; property is key to making the borders look clean by collapsing them into a single border.

Example

css
table, th, td {
  border: 1px solid black;
  border-collapse: collapse;
}
Try it Yourself »

Table Width and Height

The width and height properties can be used to set the size of the table, as well as individual cells.

Example

css
table { width: 100%; }
th { height: 70px; }
Try it Yourself »

Text Alignment

Use text-align to control the horizontal alignment (left, right, center) and vertical-align to control the vertical alignment (top, middle, bottom) of content within table cells.

Example

css
td { text-align: center; }
th { vertical-align: bottom; }
Try it Yourself »

Zebra-Striped Tables

Zebra-striping (adding alternating background colors to rows) makes tables much easier to read. This can be done easily with the :nth-child(even) or :nth-child(odd) pseudo-class.

Example

css
tr:nth-child(even) {
  background-color: #f2f2f2;
}
Try it Yourself »

Test Yourself with an Exercise

Which property makes table borders collapse into a single border?