border-spacing
Quick Summary for border-spacing
The border-spacing CSS property sets the distance between the borders of adjacent <table> cells. This property applies only when border-collapse is separate.
Code Usage for border-spacing

<pre class="brush: css notranslate"><code><span class="token comment">/ &lt;length&gt; /</span> <span class="token property">border-spacing</span><span class="token punctuation">:</span> 2px<span class="token punctuation">;</span> <span class="token comment">/ horizontal &lt;length&gt; | vertical &lt;length&gt; /</span> <span class="token property">border-spacing</span><span class="token punctuation">:</span> 1cm 2em<span class="token punctuation">;</span> <span class="token comment">/ Global values /</span> <span class="token property">border-spacing</span><span class="token punctuation">:</span> inherit<span class="token punctuation">;</span> <span class="token property">border-spacing</span><span class="token punctuation">:</span> initial<span class="token punctuation">;</span> <span class="token property">border-spacing</span><span class="token punctuation">:</span> revert<span class="token punctuation">;</span> <span class="token property">border-spacing</span><span class="token punctuation">:</span> unset<span class="token punctuation">;</span> </code></pre>

More Details for border-spacing

border-spacing

The border-spacing CSS property sets the distance between the borders of adjacent <table> cells. This property applies only when border-collapse is separate.

The border-spacing value is also used along the outside edge of the table, where the distance between the table's border and the cells in the first/last column or row is the sum of the relevant (horizontal or vertical) border-spacing and the relevant (top, right, bottom, or left) padding on the table.

Note: The border-spacing property is equivalent to the deprecated cellspacing <table> attribute, except that it has an optional second value that can be used to set different horizontal and vertical spacing.

Syntax

/* <length> */ border-spacing: 2px;  /* horizontal <length> | vertical <length> */ border-spacing: 1cm 2em;  /* Global values */ border-spacing: inherit; border-spacing: initial; border-spacing: revert; border-spacing: unset; 

The border-spacing property may be specified as either one or two values.

When one <length> value is specified, it defines both the horizontal and vertical spacings between cells. When two <length> values are specified, the first value defines the horizontal spacing between cells (i.e., the space between cells in adjacent columns), and the second value defines the vertical spacing between cells (i.e., the space between cells in adjacent rows).

Values

<length>

The size of the spacing as a fixed value.

Formal definition

Initial value0
Applies totable and inline-table elements
Inheritedyes
Computed valuetwo absolute lengths
Animation typediscrete

Formal syntax

<length> <length>?

Examples

Spacing and padding table cells

This example applies a spacing of .5em vertically and 1em horizontally between a table's cells. Note how, along its outside edges, the table's padding values are added to its border-spacing values.

HTML
<table>   <tr>     <td>1</td><td>2</td><td>3</td>   </tr>   <tr>     <td>4</td><td>5</td><td>6</td>   </tr>   <tr>     <td>7</td><td>8</td><td>9</td>   </tr> </table> 
CSS
table {   border-spacing: 1em .5em;   padding: 0 2em 1em 0;   border: 1px solid orange; }  td {   width: 1.5em;   height: 1.5em;   background: #d2d2d2;   text-align: center;   vertical-align: middle; } 
Result

Specifications

Specification
Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification # separated-borders

See also

border-collapse, border-style The border-spacing property alters the appearance of the <table> HTML element.

Last modified: Aug 12, 2021, by MDN contributors

Select your preferred language English (US)DeutschEspañolFrançais日本語한국어Polski中文 (简体) Change language

No Items Found.

Add Comment
Type in a Nick Name here
 
Other Categories in CSS
css
Search CSS
Search CSS by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

You could also follow me on twitter. I have a couple of youtube channels if you want to see some video related content. RuneScape 3, Minecraft and also a coding channel here Web Dev.

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕

❤️👩‍💻🎮

🪦 2000 - 16 Oct 2022 - Boots
Random Quote
For a long time it had seemed to me that life was about to begin - real life. But there was always some obstacle in the way, something to be gotten through first, some unfinished business, time still to be served, or a debt to be paid. Then life would begin. At last it dawned on me that these obstacles were my life.
Alfred D. Souza
Latest News
## 🚀 AI Giants Hit Bullseye: Anthropic & OpenAI Achieve Product-Market Fit Anthropic and OpenAI have reached a significant milestone, finding product-market fit with their AI technologies, which means their products effectively meet the needs of their customers, driving growth and adoption. This achievement showcases the practical value of their innovations, enabling businesses and individuals to leverage AI for enhanced productivity and efficiency. With this alignment of product and market needs, these companies are poised to transform industries and shape the future of technology.