---
title: "Set cellpadding and cellspacing in CSS?"  
description: "Set cellpadding and cellspacing in CSS?"  
author: "Revati S Misra"  
published: 2023-04-24  
updated: 2023-04-25  
canonical: https://www.mindstick.com/forum/157986/set-cellpadding-and-cellspacing-in-css  
category: "css-css3"  
tags: ["html", "html table", "css"]  
reading_time: 2 minutes  

---

# Set cellpadding and cellspacing in CSS?

Set [cellpadding and cellspacing](https://www.mindstick.com/interview/23082/how-to-use-cellpadding-and-cellspacing-attributes-in-html-code) in [CSS](https://www.mindstick.com/forum/514/background-gradient-ie7-css-problem)?

## Replies

### Reply by Aryan Kumar

In HTML, `cellpadding` and `cellspacing` are attributes that are used to control the spacing between table cells. However, they are not CSS properties and cannot be set using CSS.

Instead, you can use CSS to control the spacing between table cells by setting the `border-spacing` or `border-collapse` properties on the table element. Here's an example:

```css
table {
 border-spacing: 10px; /* Set the spacing between cells */
 border-collapse: separate; /* Make sure the borders between cells are visible */
}
```

In this example, we're setting the `border-spacing` property to `10px`, which will create a 10-pixel gap between adjacent cells in the table. We're also setting the `border-collapse` property to `separate`, which ensures that the borders between cells are visible.

Note that `border-spacing` is a shorthand property for setting both the horizontal and vertical spacing between cells. If you need to set different horizontal and vertical spacing, you can use the `border-spacing` property with two values, like this:

```css
table {
 border-spacing: 10px 5px; /* Set 10 pixels horizontal spacing and 5 pixels vertical spacing */
 border-collapse: separate;
}
```

Again, note that `cellpadding` and `cellspacing` are not CSS properties and cannot be set directly with CSS.


---

Original Source: https://www.mindstick.com/forum/157986/set-cellpadding-and-cellspacing-in-css

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
