Skip to content
Fix Code Error

Set cellpadding and cellspacing in CSS?

March 13, 2021 by Code Error
Posted By: kokos

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?

Solution

Basics

For controlling "cellpadding" in CSS, you can simply use padding on table cells. E.g. for 10px of "cellpadding":

td { 
    padding: 10px;
}

For "cellspacing", you can apply the border-spacing CSS property to your table. E.g. for 10px of "cellspacing":

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

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-collapse property, which merges the borders of adjoining table cells. If you’re trying to eliminate cellspacing (that is, cellspacing="0") then border-collapse:collapse should have the same effect: no space between table cells. This support is buggy, though, as it does not override an existing cellspacing HTML attribute on the table element.

In short: for non-Internet Explorer 5-7 browsers, border-spacing handles 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 use border-collapse:collapse.

table { 
    border-spacing: 0;
    border-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.

Answered By: Anonymous

Related Articles

  • How to properly do JSON API GET requests and assign…
  • Azure Sql : Unable to Replace HTML String
  • Navbar not filling width of page when reduced to mobile view
  • python 3.2 UnicodeEncodeError: 'charmap' codec can't…
  • Active tab issue on page load HTML
  • iron-collapse opened=false not collapsing when bound…
  • Bootstrap 3 collapse accordion: collapse all works…
  • Troubleshooting "Warning: session_start(): Cannot…
  • Polymer2.0- Multiple Iron collapse using class
  • How do I keep only the first map and when the game…
  • BootstrapVue collapses with open and close all buttons
  • How to parse JSON with XE2 dbxJSON
  • How to Insert cell reference in VBA code for…
  • Azure Availability Zone ARM Config
  • Having trouble with my nav bar/header, It used to…
  • Problems Installing CRA & NextJS from NPM…
  • How to create a value which can be repeatedly used…
  • The 'compilation' argument must be an instance of…
  • Multiple elements per v-for loop
  • Accessing nested JSON with Vue
  • how to collapse horizontal using iron-collapse in polymer
  • How to hide collapsible Bootstrap 4 navbar on click
  • Custom element child items
  • Vertical Align Center in Bootstrap 4
  • Event Snippet for Google only shows one event while…
  • Centering in CSS Grid
  • Search match multiple values in single field in…
  • Scripting Required for Polymer Submenu/Pages Navigation?
  • Avoid creating new session on each axios request laravel
  • CSS3's border-radius property and…
  • Bootstrap: Collapse other sections when one is expanded
  • mongodb group values by multiple fields
  • NullpointerException error while working with…
  • Why does this Azure Resource Manager Template fail…
  • Reset/remove CSS styles for element only
  • Calculate sum for group of dynamic table rows in jquery
  • Does bootstrap have builtin padding and margin classes?
  • Open only one accordion panel vue.js / bootstrap vue
  • flutter - add network images in a pdf while creating…
  • loop and eliminate unwanted lines with beautiful soup
  • Python scrape JS data
  • Polymer Multiple Iron-Collapse
  • CSS Input with width: 100% goes outside parent's bound
  • how to share state between multi slots and their…
  • Keeping the User logged in
  • Android Linear Layout Parameters
  • How do I do a drag and drop using jQuery to move…
  • Collapse 2nd navbar links to 1st navbar
  • Octave using 'for' statement to show two animations…
  • How to vertically center a container in Bootstrap?
  • Using Auto Layout in UITableView for dynamic cell…
  • Most effective way to parse JSON Objects
  • How do you specify table padding in CSS? ( table,…
  • Fix top buttons on scroll of list below
  • Does moment.js allow me to derive a timezone…
  • How to recover stashed uncommitted changes
  • How to use AND in IF Statement
  • How do I limit the number of digits from 6 to 4 in…
  • How to stretch the div to all the height of the page?
  • How do SO_REUSEADDR and SO_REUSEPORT differ?
  • html tables & inline styles
  • How to traverse the complex nested Json in C# and…
  • Azure CLI - az deployment group create -…
  • VBA get a list of files in folder and their tags (Keywords)
  • Listening to the Bootstrap collapse shown/hidden events?
  • How to show title in hover - css / jquery
  • Angular 12 - Generating browser application bundles…
  • Scrape a school's top247 college football recruits…
  • Python is not calling fucntions properly
  • ./components/Avatar.tsx Error: Cannot find module…
  • C# Get YouTube videoId from Json
  • Python JSON TypeError : list indices must be…
  • Error Stack Overflow when trying to hide buttons in…
  • Split JSON python string to pass to function
  • Why my "title" bloc doesn't go to bottom?
  • What is your most productive shortcut with Vim?
  • Error message "Forbidden You don't have permission…
  • how to make a conditional multilevel menu with vue.js?
  • Is it possible to apply CSS to half of a character?
  • Jquery fadeToggle Trouble
  • Need constraints for y position or height when…
  • Decreasing height of bootstrap 3.0 navbar
  • How to build correlation matrix plot using specified…
  • HTML table with 100% width, with vertical scroll…
  • Can't upload files with Apollo-client GraphQL in…
  • How to blur the background after click on the button…
  • Polymer - Component Layout
  • Siemens LOGO! PLC data in the wrong order
  • Polymer core-collapse inside of core-menu
  • custom text position on ipywidgets button
  • How can I use a javascript function to create…
  • How do I remove single children in a tree?
  • One to many relationship in two JSON arrays, lookup…
  • error NG6002: Appears in the NgModule.imports of…
  • How to use Servlets and Ajax?
  • Bootstrap 4 align navbar items to the right
  • Logging best practices
  • Continuous Integration vs. Continuous Delivery vs.…
  • Vue js bootstrap add animation while collapse
  • Posting array of objects to REST API with ReactJS

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

What does the “yield” keyword do?

Next Post:

How to remove local (untracked) files from the current Git working tree

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error