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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Basics
For controlling "cellpadding" in CSS, you can simply use
paddingon table cells. E.g. for 10px of "cellpadding":For "cellspacing", you can apply the
border-spacingCSS property to your table. E.g. for 10px of "cellspacing":This property will even allow separate horizontal and vertical spacing, something you couldn’t do with old-school "cellspacing".
Issues in IE ≤ 7
This will work in almost all popular browsers except for Internet Explorer up through Internet Explorer 7, where you’re almost out of luck. I say "almost" because these browsers still support the
border-collapseproperty, which merges the borders of adjoining table cells. If you’re trying to eliminate cellspacing (that is,cellspacing="0") thenborder-collapse:collapseshould have the same effect: no space between table cells. This support is buggy, though, as it does not override an existingcellspacingHTML attribute on the table element.In short: for non-Internet Explorer 5-7 browsers,
border-spacinghandles you. For Internet Explorer, if your situation is just right (you want 0 cellspacing and your table doesn’t have it defined already), you can useborder-collapse:collapse.Note: For a great overview of CSS properties that one can apply to tables and for which browsers, see this fantastic Quirksmode page.