---
title: "How to use Cellpadding and Cellspacing Attributes in HTML code.?"  
description: "How to use Cellpadding and Cellspacing Attributes in HTML code.?"  
author: "Ailsa Singh"  
published: 2016-10-12  
updated: 2023-05-01  
canonical: https://www.mindstick.com/interview/23082/how-to-use-cellpadding-and-cellspacing-attributes-in-html-code  
category: "html"  
tags: ["html"]  
reading_time: 2 minutes  

---

# How to use Cellpadding and Cellspacing Attributes in HTML code.?

**Cellpadding and Cellspacing Attributes in HTML code.**

It is used to adjust the spaces of the table.

**CellSpacing :** It is used to define the width of the border

**CellPadding :** it is used to define the distance between the border and content within the cell

```
<!DOCTYPE html><html>                   <body><table border="1" cellpadding="50"
cellspacing="50"><tr><th>Name</th><th>Post</th></tr><tr><td>Abhishek</td><td>Software Developer</td></tr><tr><td>Pri</td><td>Programmer</td></tr></table></body></html>
```

## Answers

### Answer by Aryan Kumar

In HTML, **cellpadding** and **cellspacing** are attributes that can be used to control the amount of space between cells in an HTML table.

Here's how you can use these attributes in your HTML code:

1. **cellpadding**: This attribute is used to add padding (space) inside each cell of the table. You can set the value of **cellpadding** to control the amount of space between the cell content and the cell border.

Example:

```html
<table cellpadding="10">
 <tr>
   <td>Cell 1</td>
   <td>Cell 2</td>
 </tr>
 <tr>
   <td>Cell 3</td>
   <td>Cell 4</td>
 </tr>
</table>
```

1. **cellspacing**: This attribute is used to add space between cells in a table. You can set the value of **cellspacing** to control the amount of space between the cells.

Example:

```html
<table cellspacing="10">
 <tr>
   <td>Cell 1</td>
   <td>Cell 2</td>
 </tr>
 <tr>
   <td>Cell 3</td>
   <td>Cell 4</td>
 </tr>
</table>
```

Note that using **cellpadding** and **cellspacing** attributes is not recommended in modern HTML development, as it is better to use CSS to control the spacing and padding of table cells. However, these attributes can still be used for backward compatibility with older browsers or for specific use cases where CSS is not available or feasible.

\

### Answer by Ailsa Singh

**Cellpadding and Cellspacing Attributes in HTML code.**

It is used to adjust the spaces of the table.

**CellSpacing :** It is used to define the width of the border

**CellPadding :** it is used to define the distance between the border and content within the cell

```
<!DOCTYPE html><html>                   <body><table border="1" cellpadding="50"
cellspacing="50"><tr><th>Name</th><th>Post</th></tr><tr><td>Abhishek</td><td>Software Developer</td></tr><tr><td>Pri</td><td>Programmer</td></tr></table></body></html>
```


---

Original Source: https://www.mindstick.com/interview/23082/how-to-use-cellpadding-and-cellspacing-attributes-in-html-code

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
