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.

Difference between cellpadding and cellspacing in HTML

Explanation

In the code snippet above:

  • Lines 7–10: We create an HTML table with border=1 and without cell spacing and cell padding.
  • Lines 16–19: We create an HTML table with border=1 and cellpadding=10.
  • Lines 25–28: We create an HTML table with border=1 and cellspacing=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 ©2025 Educative, Inc. All rights reserved