HTML table Cellpadding attributes

The HTML cellpadding attribute is used to specify the amount of space between the content of a cell and its border. It is used within the Table tag and can be applied to individual cells or to the entire table. The value of cellpadding is specified in pixels or as a percentage of the width of the cell.

For example, consider the following code snippet:

<table cellpadding="10">
  <tr>
    <td>Cell 1</td>
    <td>Cell 2</td>
  </tr>
  <tr>
    <td>Cell 3</td>
    <td>Cell 4</td>
  </tr>

In this example, the cellpadding attribute is set to 10 pixels. This means that there will be 10 pixels of space between the content of each cell and its border. The result is a table with cells that are visually separated from each other by a margin of 10 pixels.

It is important to note that cellpadding only affects the space between the content of the cell and its border. It does not affect the space between cells or the table border. To adjust the space between cells, the cellspacing attribute should be used.

The cellpadding attribute can also be applied to individual cells within a table. To do this, the cellpadding attribute is added to the TD or TH tag, like so:

<table>
  <tr>
    <th cellpadding="10">Column 1</th>
    <th>Column 2</th>
  </tr>
  <tr>
    <td>Cell 1</td>
    <td cellpadding="5">Cell 2</td>
  </tr>
</table>

In this example, the cellpadding attribute is applied to the first column header and the second cell in the second row. The result is that the first column header has 10 pixels of space between its content and its border, while the second cell in the second row has 5 pixels of space between its content and its border.

The cellpadding attribute can also be set to a value of “0” to remove all space between the content of the cell and its border. This can be useful for creating tables with a clean and minimalist design.

Overall, the cellpadding attribute is a powerful tool for controlling the appearance of tables within a webpage. By adjusting the amount of space between the content of cells and their borders, web developers can create tables that are visually appealing and easy to read. However, it is important to use cellpadding in conjunction with other table attributes, such as cellspacing and border, to achieve the desired appearance and functionality of the tabl