Quick Tip: How to apply Cellpadding and Cellspacing in CSS

Share

In HTML, we have seen the table styles cellpadding and cellspacing can be set as

. But how would this be accomplished using cascading style sheet?

The way of doing this is very simple and can be achieved as for “cellpadding” , we can simply use padding on table cells. E.g. for 15px of “cellpadding”:

td { 
    padding: 15px;
}


For "cellspacing", we can apply the border-spacing property to the table. E.g. for 15px of "cellspacing":

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

Handling IE <= 7

These CSS properties will work in almost all major browsers except for Internet Explorer basic up till Internet Explorer 7. You can use border-collapse:collapse. Only if we want 0 cellspacing and our table doesn’t have it defined already.

table { 
    border-spacing: 0;
    border-collapse: collapse;
}
  • May 2, 2014
8 Best Free Stock Video Websites for Tiktok, Reels, and Shorts Top 5 PHP Frameworks: Fast and Secure