36

Can someone tell me how to change table cellpadding and cellspacing like you can do it in html with:

<table cellspacing="0" cellpadding="0"> 

But how is it done with css?

Timo
  • 4,246
  • 6
  • 29
  • 42
Sudipa Sengupta
  • 405
  • 1
  • 4
  • 4

3 Answers3

43

Use padding on the cells and border-spacing on the table. The former will give you cellpadding while the latter will give you cellspacing.

table { border-spacing: 5px; } /* cellspacing */

th, td { padding: 5px; } /* cellpadding */

jsFiddle Demo

kapa
  • 77,694
  • 21
  • 158
  • 175
14

The padding inside a table-divider (TD) is a padding property applied to the cell itself.

CSS

td, th {padding:0}

The spacing in-between the table-dividers is a space between cell borders of the TABLE. To make it effective, you have to specify if your table cells borders will 'collapse' or be 'separated'.

CSS

table, td, th {border-collapse:separate}
table {border-spacing:6px}

Try this : https://www.google.ca/search?num=100&newwindow=1&q=css+table+cellspacing+cellpadding+site%3Astackoverflow.com ( 27 100 results )

Milche Patern
  • 19,632
  • 6
  • 35
  • 52
5

Here is the solution.

The HTML:

<table cellspacing="0" cellpadding="0">
    <tr>
        <td>
            123
        </td>
    </tr>
</table>

The CSS:

table { 
      border-spacing:0; 
      border-collapse:collapse;   
    }

Hope this helps.

EDIT

td, th {padding:0}
Nitesh
  • 15,425
  • 4
  • 48
  • 60
  • Cell spacing and padding are attributes of the cells inside the table. I would think that setting the margin and padding on the td would be more accurate. – Doug Dawson May 07 '13 at 12:41
  • here is the fiddle for the same http://jsfiddle.net/mVSaa/ - @Darkwater23 – Nitesh May 07 '13 at 12:44
  • I agree to your point. Tried, tested and finally edited the fiddle. http://jsfiddle.net/mVSaa/1/ - @Darkwater23 – Nitesh May 07 '13 at 12:58