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?

0

3 Answers 3

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

Sign up to request clarification or add additional context in comments.

1 Comment

Update: added a demo that better illustrates stuff
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 )

1 Comment

border-collapse:separated is invalid. Should be separate (no 'd')
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} 

3 Comments

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.
here is the fiddle for the same jsfiddle.net/mVSaa - @Darkwater23
I agree to your point. Tried, tested and finally edited the fiddle. jsfiddle.net/mVSaa/1 - @Darkwater23

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.