Forget About Table Cellspacing In HTML (And Learn The CSS Now)
Disclosure: Your support helps keep the site running! We earn a referral fee for some of the services we recommend on this page. Learn more
- Attribute of
- Create An HTML Table Quickly & Easily With Our Code Example
- What does
Forget About Table Cellspacing In HTML (And Learn The CSS Now)
do? - Was used to specify the distance between the individual cells of an HTML table. This element has been deprecated and CSS should be used to control table layout.
Controlling the Space Between Table Cells
The cellspacing
attribute was used to control the amount of space between cells of a table. This attribute has been deprecated, and if you want to add space between table cells you can do so with CSS. The cellspacing
attribute, which was used to add space between table data cells, should not be confused with the cellpadding
attribute, which was used to add space between the contents of a data cell and the edge of the cell. If you want to add space between table cells with CSS, you can do so with the border-spacing
property.
<style> table.example-table { border-spacing: 30px; border-collapse: separate; } </style> <table class="example-table"> <tr><td>First column</td><td>Second column</td><td>Third column</td></tr> <tr><td>First column</td><td>Second column</td><td>Third column</td></tr> <tr><td>First column</td><td>Second column</td><td>Third column</td></tr> </table>
Here’s how that bit of code looks rendered in the browser.
table.example-table{border-spacing: 30px; border-collapse: separate;}
First column | Second column | Third column |
First column | Second column | Third column |
First column | Second column | Third column |