The difference between cellpadding and cellspacing in HTML
Overview
In this Answer, we'll look at the two attributes of the table tag in HTML: cellpadding and cellspacing.
Whereas the cell padding attribute places space around the data, the cell spacing attribute places space around each cell in the table.
Syntax
<table cellspacing="" cellpadding=""></table>
Example
In the following example, we create three HTML tables, the first one without cell padding and cell spacing, the second one with cell padding, and the third one with cell spacing.
Explanation
In the code snippet above:
- Lines 7–10: We create an HTML table with
border=1and without cell spacing and cell padding. - Lines 16–19: We create an HTML table with
border=1andcellpadding=10. - Lines 25–28: We create an HTML table with
border=1andcellspacing=10.
The output of the code shows that space is created around the data in the second table, while space is created around the cell in the third table.
Free Resources
Copyright ©2026 Educative, Inc. All rights reserved