Formatting HTML Tables

Formatting HTML Tables

Introduction

HTML tables can be formatted in various ways to enhance their appearance and readability. Let's explore some formatting options.

Table borders and spacing

You can add borders to your table using CSS. By default, tables have no borders, but you can apply styles to the <table> element to add borders around the table and its cells. Additionally, you can control the spacing between cells using CSS properties such as border-collapse and border-spacing.

Table alignment
HTML tables can be aligned horizontally or vertically within their parent container. You can use CSS properties like text-align and vertical-align to control the alignment of table data and headings.
Table background colors

Adding background colors to tables can make them visually appealing and distinguishable. You can apply background colors to individual cells or entire rows using CSS.

Table caption
A table caption provides a brief description or title for the table. It helps users understand the purpose or content of the table. You can add a caption using the <caption> element, which should be placed immediately after the opening <table> tag.