Alex Rivera | Logout

Set cellpadding and cellspacing in CSS?

Asked 2008-12-04T08:45:47.323
3726

In an HTML table, the cellpadding and cellspacing can be set like this:

<table cellspacing="1" cellpadding="1">

How can the same be accomplished using CSS?

Edit
Report

3 Answers

75

For those who want a non-zero cellspacing value, the following CSS worked for me, but I'm only able to test it in Firefox.

See the Quirksmode link posted elsewhere for compatibility details. It seems it may not work with older Internet Explorer versions.

table {
    border-collapse: separate;
    border-spacing: 2px;
}
answered 2011-08-20T03:32:59.350
58

The simple solution to this problem is:

table
{
    border: 1px solid #000000;
    border-collapse: collapse;
    border-spacing: 0px;
}
table td
{
    padding: 8px 8px;
}
answered 2011-12-08T16:04:01.137
21

TBH. For all the fannying around with CSS you might as well just use cellpadding="0" cellspacing="0" since they are not deprecated...

Anyone else suggesting margins on <td>'s obviously has not tried this.

answered 2010-02-26T11:25:10.620

Your Answer