CSS empty-cells Property

Beginner
⏱️ 4 min read
📚 Updated: Jun 2026
🎯 4 Examples
Tables

What You’ll Learn

The empty-cells property lets you control whether empty table cells show their borders and background. It is a small but useful tool for cleaner HTML table layouts when some cells have no data.

01

Empty cells

Show or hide them.

02

Syntax

show and hide.

03

Default show

Borders stay visible.

04

Table only

Works on table cells.

05

border-collapse

Needs separate mode.

06

Cleaner grids

Sparse data tables.

Introduction

The empty-cells property in CSS is used to control the rendering of table cells that do not contain any content. This property can be particularly useful when you want to ensure that empty cells are either shown or hidden, maintaining the visual consistency of your table layouts.

Definition and Usage

Apply empty-cells to a table element (or a cell, though setting it on the table is most common). When set to hide, cells with no content lose their visible borders and background, which can make sparse tables look cleaner while keeping the same HTML structure.

💡
Beginner Tip

empty-cells only works when the table uses border-collapse: separate. If your table uses border-collapse: collapse, this property will not change how empty cells look.

📝 Syntax

The syntax for the empty-cells property is simple and can be applied to table elements.

syntax.css
element {
  empty-cells: value;
}

Basic Example

empty-cells-hide.css
table {
  border-collapse: separate;
  empty-cells: hide;
}
empty-cells: show; empty-cells: hide;

Default Value

The default value of the empty-cells property is show, meaning that empty cells are displayed with their borders and background.

Syntax Rules

  • Apply it to table elements or individual td / th cells.
  • Requires border-collapse: separate on the table to take effect.
  • A cell is empty only when it has no content — whitespace alone does not count as empty.
  • The property is inherited by table cells from the table element.
  • Hidden empty cells still occupy space in the table grid; only their borders and background disappear.

⚡ Quick Reference

QuestionAnswer
Initial valueshow
Applies toTable cell elements (td, th)
InheritedYes
AnimatableNo
Required companionborder-collapse: separate

💎 Property Values

The empty-cells property accepts two keyword values:

ValueDescription
showThis value ensures that empty cells are displayed with their borders and background.
hideThis value hides the borders and background of empty cells, making them invisible.

When to Use show vs hide

ScenarioRecommended value
Data tables where every cell should look uniformshow (default)
Sparse grids, calendars, or timetables with gapshide
Tables using border-collapse: collapseNeither value has effect — change collapse mode first
Cells with only   or spacesNot empty — hide will not apply

👀 Live Preview

Compare empty-cells: show and empty-cells: hide on the same table pattern:

empty-cells: show
13
5
empty-cells: hide
13
5

Examples Gallery

In this example, we’ll demonstrate the effect of the empty-cells property on a table with some empty cells — plus a schedule layout, border-collapse setup, and a styled data table.

📋 Basic Empty Cell Control

Start with the reference example — two tables with the same data but different empty-cells values.

Example 1 — Show vs Hide Comparison

See how show keeps empty cell borders visible while hide removes them.

empty-cells-show-hide.html
<style>
  table {
    border-collapse: separate;
    width: 100%;
  }
  td {
    border: 1px solid black;
    width: 50px;
    height: 50px;
  }
  .show-empty { empty-cells: show; }
  .hide-empty { empty-cells: hide; }
</style>

<h2>empty-cells: show</h2>
<table class="show-empty">
  <tr><td>1</td><td></td><td>3</td></tr>
  <tr><td></td><td>5</td><td></td></tr>
</table>

<h2>empty-cells: hide</h2>
<table class="hide-empty">
  <tr><td>1</td><td></td><td>3</td></tr>
  <tr><td></td><td>5</td><td></td></tr>
</table>
Try It Yourself

How It Works

Both tables have the same HTML. The only difference is empty-cells: hide, which removes borders and backgrounds from cells with no content.

Example 2 — Weekly Schedule Grid

Hide empty cells in a sparse timetable so only booked slots show visible boxes.

empty-cells-schedule.css
.schedule {
  border-collapse: separate;
  border-spacing: 4px;
  empty-cells: hide;
}

.schedule td {
  border: 1px solid #cbd5e1;
  padding: 0.5rem;
  background: #eff6ff;
}
Try It Yourself

How It Works

Empty time slots stay in the table structure but look invisible, so users focus on cells that actually contain class names.

⚙ Table Setup & Styling

Understand the border-collapse requirement and apply empty-cells to styled data tables.

Example 3 — border-collapse: separate

Always pair empty-cells with border-collapse: separate for the property to work.

empty-cells-border-collapse.css
table {
  border-collapse: separate; /* required */
  border-spacing: 0;
  empty-cells: hide;
}
Try It Yourself

How It Works

When borders are collapsed into shared lines between cells, the browser cannot hide individual empty cell borders. Use separate mode instead.

Example 4 — Styled Data Table

Combine empty-cells: hide with modern table styling for a cleaner dashboard grid.

empty-cells-styled.css
.data-grid {
  border-collapse: separate;
  border-spacing: 0.5rem;
  empty-cells: hide;
  width: 100%;
}

.data-grid td {
  border: 1px solid #e2e8f0;
  border-radius: 0.4rem;
  padding: 0.75rem;
  background: #fff;
}
Try It Yourself

How It Works

Rounded, spaced cells with hidden empty slots create a dashboard-style grid without removing td elements from the markup.

♿ Accessibility

  • Hidden cells are still in the DOM — screen readers may still encounter empty td elements; use proper table headers and captions.
  • Use th for column and row labels so data relationships stay clear even when some cells are visually hidden.
  • Do not hide meaningful empty states if “no data” is important information for users.
  • Prefer semantic tables for tabular data rather than layout-only grids built with tables.
  • Consider aria-label on complex tables when visual empty-cell hiding might confuse the structure.

🧠 How empty-cells Works

1

Browser builds the table grid

Rows and columns are laid out from your table, tr, and td markup.

Structure
2

Empty cells are detected

Cells with no content qualify for empty-cells when border-collapse: separate is active.

Detection
3

show or hide is applied

show draws borders and background. hide removes them while the cell keeps its grid position.

Rendering
=

Cleaner table presentation

Sparse tables look less cluttered without changing the underlying HTML grid.

🖥 Browser Compatibility

The empty-cells property is supported in all modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. It is also supported in older versions of Internet Explorer. However, it is always a good practice to test your website across different browsers to ensure compatibility.

Baseline · Universal support

empty-cells everywhere

empty-cells has excellent cross-browser support. Both show and hide work in all modern browsers and legacy Internet Explorer.

99% Universal support
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions
Full support
Opera All modern versions
Full support
empty-cells property 99% supported

Bottom line: empty-cells is safe to use in all browsers. Remember to set border-collapse: separate for the property to take effect.

🎉 Conclusion

The empty-cells property is a useful tool for web developers looking to control the display of empty table cells. By choosing whether to show or hide these cells, you can maintain the desired visual structure of your tables.

Experiment with this property to see how it can enhance the presentation of your tabular data. For beginners, remember the two key values — show (default) and hide — and always pair hide with border-collapse: separate.

💡 Best Practices

✅ Do

  • Set border-collapse: separate when using empty-cells: hide
  • Use hide for sparse grids like calendars and timetables
  • Keep table headers (th) for accessible data tables
  • Test with real empty cells, not cells containing spaces
  • Combine with border-spacing for spaced card-style tables

❌ Don’t

  • Expect hide to work with border-collapse: collapse
  • Put &nbsp; in cells you want treated as empty
  • Use tables for page layout when CSS Grid or Flexbox is clearer
  • Hide empty cells if “no value” is meaningful data for users
  • Forget that hidden cells still take up grid space

Key Takeaways

Knowledge Unlocked

Five things to remember about empty-cells

Use these points when styling HTML tables.

5
Core concepts
👁 02

show

Default visible.

Default
🚫 03

hide

No border or bg.

Common
04

separate

Required mode.

Setup
📅 05

Sparse grids

Schedules, calendars.

Use case

❓ Frequently Asked Questions

The empty-cells property controls whether empty table cells display their borders and background. With show, empty cells remain visible. With hide, they become invisible while still occupying their grid space in the table.
The initial value is show, meaning empty cells are displayed with their borders and background by default.
empty-cells only takes effect when border-collapse is set to separate on the table. If border-collapse is collapse, the property has no visible effect.
A cell is empty when it has no content at all. A cell that contains only whitespace, a non-breaking space, or an image is not considered empty.
Use empty-cells when your table structure needs placeholder cells for alignment, such as schedules or grids. If cells are not needed structurally, removing them from the HTML is often cleaner.

Practice in the Live Editor

Open the HTML editor, add empty-cells: hide to a table, and compare it with the default show behavior.

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