Last Updated : 11 Jul, 2025
The cellspacing attribute in HTML is used to define the space between cells in a table. It controls the amount of space, in pixels, between the table cells. This spacing can make the table's content more readable by adding extra room between cells.
However, it's important to note that the cellspacing attribute is not supported in HTML5, and modern developers usually use CSS to manage the space between cells.
Syntax:Note: The <table> cellspacing Attribute is not supported by HTML 5.
<table cellspacing="pixels">Attribute Values:
Attribute Value
Description
pixels
It sets the space between the cells in terms of pixels.
Example 1: Table with CellspacingIn this example, we set the cellspacing attribute to 10 pixels, meaning there will be a 10-pixel gap between each cell.
html
<!DOCTYPE html>
<html>
<head>
<title>
HTML table cellspacing Attribute
</title>
<style>
body {
text-align: center;
}
table {
margin: 0 auto;
}
</style>
</head>
<body>
<h1 style="color: green;">
GeeksforGeeks
</h1>
<h2>HTML table cellspacing Attribute</h2>
<table border="1" cellspacing="15">
<caption>
Author Details
</caption>
<tr>
<th>NAME</th>
<th>AGE</th>
<th>BRANCH</th>
</tr>
<tr>
<td>BITTU</td>
<td>22</td>
<td>CSE</td>
</tr>
<tr>
<td>RAM</td>
<td>21</td>
<td>ECE</td>
</tr>
</table>
</body>
</html>
Output:
Example 2: Table with Different CellspacingLet’s try a different value for the cellspacing attribute. Here, we set the cellspacing to 10 pixels:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<title>Cellspacing Example</title>
<style>
body {
text-align: center;
}
table {
margin: 0 auto;
}
</style>
</head>
<body>
<h1 style="color: green;">
GeeksforGeeks
</h1>
<h2>Table with Cellspacing</h2>
<table border="1" cellspacing="10">
<tr>
<td>Row 1, Cell 1</td>
<td>Row 1, Cell 2</td>
</tr>
<tr>
<td>Row 2, Cell 1</td>
<td>Row 2, Cell 2</td>
</tr>
</table>
</body>
</html>
Output:
Supported Browsers:While the cellspacing attribute was once a common way to control the space between table cells in HTML, it is no longer supported in HTML5. Instead, you should use CSS for this purpose, which gives you greater control and flexibility.
HTML <table> cellspacing Attribute
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4