How to set cellpadding and cellspacing in CSS?

Sometimes, we want to set cellpadding and cellspacing in CSS.

In this article, we’ll look at how to set cellpadding and cellspacing in CSS.

How to set cellpadding and cellspacing in CSS?

To set cellpadding and cellspacing in CSS, we set the padding and border properties.

For instance, we write

td {
  padding: 10px;
}

table {
  border-spacing: 10px;
  border-collapse: separate;
}

to add cell spacing with the border-spacing property.

border-collapse: separate; is required to apply border-spacing

And we add cell padding with the padding property for td’s.

Conclusion

To set cellpadding and cellspacing in CSS, we set the padding and border properties.