# Difference Between Cellpadding and Cellspacing

In HTML, cellpadding and cellspacing are the two attributes used for formatting table cells. Both cellpadding and cellspacing are used to insert whitespaces in the table cells. The most basic difference between cellpadding and cellspacing is that the cellpadding is used to set the whitespace between cell edge and cell content, whereas cellspacing is used to set the whitespace between two cells.

Read through this article to find out more about cellpadding and cellspacing and how they are different from each other.

## What is Cellpadding?

In HTML table formatting, cellpadding is the attribute which is used to set the whitespace between the cell edge and the cell content. In simple words, cellpadding is the attribute of the table tag (<table>) that set the distance between the cell border and cell content.

In HTML, the value assigned to the cellpadding attribute can be in pixels or percentage. This value could be 0 depending on the requirements of user. The cellpadding attribute of the table tag is supported in the older versions of HTML, but HTML5 does not allow the use of cellpadding.

### Syntax

Use the following syntax to apply cellpadding −

<table cellpadding="value" >.....</table>


## What is Cellspacing?

Cellspacing is again an attribute of table tag in HTML. It is used to control the distance between two adjacent cells. Thus, a web developer can easily change the space between edges of different adjacent cells. It is primary used to improve the clarity of the table.

### Syntax

Use the following syntax to apply cellspacing −

<table cellspacing="value" >.....</table>


Now, let us discuss the important differences between cellpadding and cellspacing in detail.

## Difference between Cellpadding and Cellspacing

The following table highlights all the important differences between cellpadding and cellspacing −

Key Cellpadding Cellspacing
Associated with It is associated with a single cell. It is associated with more than a single cell.
Use It helps to control the white space that is present between the border of the cell and the contents within the cell. It helps to set the space between the single cells.
Default Value The default value of cell padding is 1. The default cell spacing value is 2.
Effectiveness It is used as an effective method. It is less effective than cell padding.
Created using It is created using HTML <table> tag. It can be created using HTML <table> tag.
Type The type of attribute is set to 'cellpadding'. The type of attribute is set to 'cellspacing'.
Example <table cellpadding="value" >.....</table> <table cellspacing="value" >.....</table>

## Conclusion

Both Cellpadding and cellspacing are the attributes of table tag in HTML. But, they are completely different from each other as highlighted in the above table. The most significant difference between cellpadding and cellspacing is that cellpadding defines the whitespace within the cell between the content and border of the cell, whereas cellspacing controls the whitespace between borders of two adjacent cells.

Advertisements