CSS border-spacing Property

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 4 Examples
Box Model & Borders

What You’ll Learn

The border-spacing property controls the gap between table cell borders. It is the CSS way to add breathing room inside HTML tables when borders stay separate.

01

Cell Gaps

Space between borders.

02

1 or 2 Values

Horizontal and vertical.

03

0 Default

No extra gap.

04

On <table>

Table element only.

05

Needs separate

Works with separate.

06

px / em / rem

Length units.

Definition and Usage

The border-spacing CSS property sets the distance between the borders of adjacent cells in a table. This gives you control over how much space appears between cells without changing the cell border width itself.

It is especially useful for card-like tables, comparison grids, and layouts where you want visible gaps between bordered cells. Pair it with cell borders on th and td for the best visual result.

💡
Beginner Tip

border-spacing only works when border-collapse is separate. If your table uses collapse, spacing is ignored — use padding or margins on cells instead for inner space.

📝 Syntax

The syntax for border-spacing accepts one or two length values on the <table> element.

syntax.css
table {
  border-spacing: <length> <length>?;
}

Basic Example

border-spacing.css
table {
  border-spacing: 10px 15px;
  border: 1px solid black;
}
td {
  border: 1px solid gray;
  padding: 10px;
}

The first length sets horizontal spacing. The optional second length sets vertical spacing. If only one value is given, it applies to both axes.

Syntax Rules

  • The initial value is 0 — no gap between cell borders.
  • Only applies to table and inline-table elements.
  • Requires border-collapse: separate (the default) to take effect.
  • Values must be non-negative lengths such as px, em, or rem.
  • Spacing is added between border boxes, not inside cell padding.

⚡ Quick Reference

QuestionAnswer
Initial value0
Applies totable and inline-table elements
InheritedYes
AnimatableNo
Common useSpaced table grids, card-style tables, comparison layouts

Default Value

The default value of border-spacing is 0, meaning there is no extra space between the borders of adjacent cells unless you set a length.

💎 Property Values

The border-spacing property accepts length values and global keywords.

ValueDescription
<length>A positive length such as 8px, 0.5em, or 1rem that sets spacing on both axes when used alone
<length> <length>First value is horizontal spacing; second value is vertical spacing between cells
initialSets the property to its default value (0)
inheritInherits the property value from its parent element

0

AB
CD

8px

AB
CD

16px

AB
CD

Horizontal vs Vertical Spacing

When you pass two values, the first controls horizontal gaps and the second controls vertical gaps between cell borders.

border-spacing: 12px 4px;

AB
CD

border-spacing: 4px 12px;

AB
CD

border-spacing vs border-collapse

PropertyWhat it controlsBest for
border-spacingGap distance between separate cell border boxesCard-like tables and visible gaps between cells
border-collapseWhether adjacent borders merge or stay separateChoosing between a tidy grid (collapse) and spaced cells (separate)
padding on cellsInner space inside each cell border boxContent breathing room without changing the gap between cells

👀 Live Preview

A table with 10px horizontal and 15px vertical border spacing:

Cell 1Cell 2
Cell 3Cell 4

Uses border-spacing: 10px 15px; with cell borders and table border.

Examples Gallery

Try border-spacing with two-value syntax, single-value spacing, zero vs spaced comparisons, and a card-style table.

📚 Basic Table Spacing

Set horizontal and vertical gaps between cell borders on an HTML table.

Example 1 — Horizontal and Vertical Spacing

Set border-spacing: 10px 15px; on a table, matching the reference tutorial.

border-spacing-two-value.html
<style>
  table {
    border-spacing: 10px 15px;
    border: 1px solid black;
  }
  td {
    border: 1px solid gray;
    padding: 10px;
  }
</style>

<table>
  <tr><td>Cell 1</td><td>Cell 2</td></tr>
  <tr><td>Cell 3</td><td>Cell 4</td></tr>
</table>
Try It Yourself

How It Works

10px adds horizontal space between columns and 15px adds vertical space between rows. Cell borders stay separate, so the gap is visible.

Example 2 — Single Value Spacing

Use one length to apply the same gap on both horizontal and vertical axes.

border-spacing-single.html
<style>
  table {
    border-collapse: separate;
    border-spacing: 12px;
    width: 100%;
    max-width: 18rem;
  }
  td {
    border: 1px solid #2563eb;
    padding: 8px;
    background: #eff6ff;
    text-align: center;
  }
</style>

<table>
  <tr><td>A</td><td>B</td></tr>
  <tr><td>C</td><td>D</td></tr>
</table>
Try It Yourself

How It Works

When you provide one value, the browser uses it for both horizontal and vertical spacing between cell borders.

📏 Comparisons and Styled Tables

See how spacing changes the table look and build a card-style spaced grid.

Example 3 — Compare 0 vs 16px Spacing

See the difference between the default 0 spacing and a larger gap.

border-spacing-compare.css
.no-gap {
  border-collapse: separate;
  border-spacing: 0;
}
.with-gap {
  border-collapse: separate;
  border-spacing: 16px;
}
td {
  border: 1px solid #64748b;
  padding: 6px;
  text-align: center;
}
Try It Yourself

How It Works

At 0, cell borders touch where they meet. Increasing spacing pushes border boxes apart without changing border width.

Example 4 — Card-Style Spaced Table

Combine moderate spacing with rounded cell borders for a modern card grid look.

border-spacing-card.css
table {
  border-collapse: separate;
  border-spacing: 6px;
  width: 100%;
  max-width: 20rem;
}
td {
  border: 1px solid #e2e8f0;
  border-radius: 0.5rem;
  padding: 0.75rem;
  background: #fff;
  text-align: center;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}
Try It Yourself

How It Works

border-spacing: 6px; creates small gaps so rounded cell borders read as separate cards in a pricing-style grid.

🧠 How border-spacing Works

1

Keep borders separate

Use border-collapse: separate on the table so spacing can apply.

Table mode
2

Set spacing lengths

Choose one value for both axes or two values for horizontal and vertical gaps.

Length values
3

The browser adds gaps

Space appears between adjacent cell border boxes. Padding inside cells stays unchanged.

Cell gaps
=

Spaced table grid

Your table cells get visible gaps between borders for a cleaner, more open layout.

Universal Browser Support

The border-spacing property is supported in all major browsers, including Chrome, Firefox, Safari, Edge, Opera, and Internet Explorer. It is a reliable choice for HTML table styling.

Baseline · All browsers

Reliable table spacing on every platform

Chrome, Firefox, Safari, Edge, and Opera all support border-spacing consistently.

100% Universal support
Google Chrome69+ · Desktop & Mobile
Full support
Mozilla Firefox66+ · Desktop & Mobile
Full support
Apple Safari12.1+ · macOS & iOS
Full support
Microsoft Edge79+ · Chromium
Full support
Opera56+ · Modern versions
Full support
border-spacing property 100% supported

Bottom line: Use border-spacing freely in any project. It works consistently across all browsers.

Conclusion

The border-spacing property is a valuable tool for controlling gaps between table cell borders. Whether you want a tight grid or a card-like layout with visible space, adjusting spacing helps you match your design goals.

Experiment with single values like 8px or two-value pairs like 10px 15px to see how horizontal and vertical gaps change the table feel.

💡 Best Practices

✅ Do

  • Use border-collapse: separate when you need spacing between cells
  • Style cell borders on th and td so gaps are visible
  • Use two values when horizontal and vertical gaps should differ
  • Combine moderate spacing with rounded corners for card-style tables
  • Test table layout in multiple browsers for consistent spacing

❌ Don’t

  • Expect spacing to work when border-collapse is collapse
  • Use border-spacing on non-table elements like div grids
  • Confuse spacing with cell padding — they control different areas
  • Use negative values — spacing lengths must be zero or positive
  • Rely on very large spacing on dense data tables meant for scanning

Key Takeaways

Knowledge Unlocked

Five things to remember about border-spacing

Use these points when adding gaps to HTML tables.

5
Core concepts
⚙️02

0 Default

No extra gap.

Default
03

1 or 2 Values

Horizontal / vertical.

Syntax
📝04

Needs separate

Not for collapse.

Requirement
🔄05

Table Only

Not for div grids.

Scope

❓ Frequently Asked Questions

The border-spacing property sets the distance between the borders of adjacent table cells. It creates visible gaps in the table grid when borders are separate.
The initial value is 0, which means there is no extra space between adjacent cell borders.
border-spacing only applies when border-collapse is separate. If the table uses collapse, spacing is ignored.
Yes. Use two length values: the first controls horizontal spacing and the second controls vertical spacing. One value applies to both axes.
No. border-spacing only applies to table and inline-table elements. Use gap in Grid or Flexbox for non-table layouts.

Practice in the Live Editor

Open the HTML editor, try border-spacing, and preview table cell gaps instantly.

HTML Editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful