HTML Table Padding & Spacing

In this tutorial, you will learn HTML Table Padding & Spacing

Padding and spacing are important in HTML tables to make the data more visually appealing and easy to read. Here is a tutorial on how to control padding and spacing in HTML tables:

  • To set the padding for all the cells in the table, you can use the padding attribute on the <table> element. You can set the value of the attribute to any number of pixels you want.
<table padding="10px">
  • To set the padding for specific cells, you can use the padding attribute on the <td> or <th> elements.
<td padding="5px">
  • To set the spacing between cells, you can use the cellspacing attribute on the <table> element. You can set the value of the attribute to any number of pixels you want.
<table cellspacing="5px">
  • To set the spacing between the cells’ content and the cells’ border, you can use the cellpadding attribute on the <table> element. You can set the value of the attribute to any number of pixels you want.
<table cellpadding="5px">
  • If you want to control the padding and spacing using CSS, you can use the padding and margin properties.
td {
  padding: 10px;
}
table {
  margin: 20px;
}
  • You can also use box-sizing property to include the padding and border in the total width and height of an element.
table {
  box-sizing: border-box;
}

This is a basic tutorial on how to control padding and spacing in HTML tables, but there are many other attributes and CSS properties that you can use to customize the spacing and padding of your tables and make them more visually appealing.

Scroll to Top