CSS empty-cells Property

The empty-cells property controls whether the borders and backgrounds of empty table cells are displayed.

It applies to table cells using the separated border model, where neighboring cells have individual borders. The property accepts two values, show and hide, and is useful for controlling the appearance of tables containing missing or intentionally blank data.

empty-cells Syntax

The empty-cells property accepts one of two keywords.

Basic Syntax

selector {
  empty-cells: show;
}

Keyword Values

table {
  empty-cells: show;
}
table {
  empty-cells: hide;
}

Individual Table Cells

td {
  empty-cells: hide;
}

CSS-Wide Keywords

table {
  empty-cells: inherit;
}
table {
  empty-cells: initial;
}
table {
  empty-cells: unset;
}
table {
  empty-cells: revert;
}
table {
  empty-cells: revert-layer;
}

The initial value is show, which displays the borders and backgrounds of empty cells.

Property Values

The empty-cells property provides two values for controlling empty table cell appearance.

Value Description
show Displays the borders and backgrounds of empty table cells.
hide Suppresses the borders and backgrounds of empty table cells.

CSS-Wide Values

Value Description
inherit Uses the computed value inherited from the parent element.
initial Restores the initial value, show.
unset Uses the inherited value because the property is inherited.
revert Reverts the property according to the CSS cascade origins.
revert-layer Reverts the property according to the CSS cascade layers.

Property Characteristics

Characteristic Value
Initial value show
Inherited Yes
Applies to Table-cell elements
Computed value As specified
Animation type Discrete
Percentages Not applicable

Although the property is inherited and can be declared on a table, its visual effect applies to individual table cells in the separated border model.

How It Works

When a table uses separate borders, each cell can display its own border and background. The empty-cells property determines whether these decorations appear when a cell has no visible content.

Step 1: Create a Table

<table>
  <tr>
    <td>HTML</td>
    <td></td>
  </tr>
  <tr>
    <td>CSS</td>
    <td>Complete</td>
  </tr>
</table>

Step 2: Use Separate Borders

table {
  border-collapse: separate;
  border-spacing: 5px;
}
td {
  border: 1px solid #666666;
  padding: 10px;
  background-color: #e8f1f8;
}

Step 3: Hide Empty Cell Decorations

table {
  empty-cells: hide;
}

The empty cell no longer displays its own border or background. However, the cell continues to participate in the table's layout.

Step 4: Restore Empty Cell Decorations

table {
  empty-cells: show;
}

The empty cell displays its border and background again.

Important Distinction

The property does not remove empty cells from the table structure. It only controls whether their borders and backgrounds are painted.

show

The show value displays the borders and backgrounds of empty table cells.

Basic Example

table {
  empty-cells: show;
}

Complete Example

<table class="show-empty">
  <tr>
    <td>HTML</td>
    <td></td>
  </tr>
  <tr>
    <td>CSS</td>
    <td>Complete</td>
  </tr>
</table>
.show-empty {
  border-collapse: separate;
  border-spacing: 5px;
  empty-cells: show;
}
.show-empty td {
  border: 1px solid #336699;
  background-color: #e8f1f8;
  padding: 12px;
  min-width: 80px;
}

How It Works

Every table cell displays its assigned border and background, including cells without content.

Practical Uses

This value is useful for tables where a consistent grid appearance is important, such as schedules, comparison tables, and structured data layouts.

Important Consideration

The show value is the initial value, so it normally does not need to be declared unless overriding an inherited hide value.

hide

The hide value suppresses the borders and backgrounds of empty table cells.

Basic Example

table {
  empty-cells: hide;
}

Complete Example

<table class="hide-empty">
  <tr>
    <td>HTML</td>
    <td></td>
  </tr>
  <tr>
    <td>CSS</td>
    <td>Complete</td>
  </tr>
</table>
.hide-empty {
  border-collapse: separate;
  border-spacing: 5px;
  empty-cells: hide;
}
.hide-empty td {
  border: 1px solid #336699;
  background-color: #e8f1f8;
  padding: 12px;
  min-width: 80px;
}

How It Works

The browser suppresses the empty cell's border and background. The cell remains part of the table layout and continues to occupy its assigned space.

Practical Uses

This value is useful when empty cells should visually blend into the surrounding table rather than appearing as bordered boxes.

Important Consideration

Hiding the cell's border and background does not hide the table's own background or remove the row or column.

What Counts as an Empty Cell?

The empty-cells property applies to cells that contain no content considered visible by the table formatting rules.

Completely Empty Cell

<td></td>

This is an empty table cell.

Whitespace-Only Cell

<td>   </td>

Ordinary collapsible whitespace does not normally make a table cell non-empty.

Cell with Text

<td>HTML</td>

This cell is not empty because it contains text.

Cell with a Nonbreaking Space

<td>&nbsp;</td>

A nonbreaking space creates text content that generally prevents the cell from being treated as empty.

Cell with an Image

<td>
  <img src="icon.png" alt="Status icon">
</td>

The cell contains an image and is not empty.

Cell with Hidden Content

<td>
  <span style="display: none;">Hidden text</span>
</td>

Content that generates no boxes does not normally prevent the cell from being treated as empty. Other CSS properties, including visibility, may affect whether the cell qualifies as empty.

Important Consideration

Do not insert nonbreaking spaces simply to force empty cells to display their borders. Use empty-cells: show when the goal is to display empty cell decorations.

empty-cells and border-collapse

The empty-cells property only affects tables using the separated border model.

Separated Borders

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

The browser can hide the borders and backgrounds of empty cells.

Collapsed Borders

table {
  border-collapse: collapse;
  empty-cells: hide;
}

The empty-cells property has no effect when the collapsed border model is used.

Comparison

Border Model Effect of empty-cells
separate Controls the display of empty cell borders and backgrounds.
collapse Has no effect.

Why the Difference Matters

In the separated border model, each cell has its own border. In the collapsed border model, adjacent borders are combined according to border conflict resolution rules.

Recommended Approach

Use border-collapse: separate when you need empty-cells to control empty cell decorations.

empty-cells and border-spacing

The border-spacing property controls the distance between table cell borders when the separated border model is used.

Basic Example

table {
  border-collapse: separate;
  border-spacing: 8px;
  empty-cells: hide;
}

How It Works

Empty cells retain their layout positions even when their borders and backgrounds are hidden. The spacing between cells remains part of the table layout.

Horizontal and Vertical Spacing

table {
  border-collapse: separate;
  border-spacing: 10px 5px;
  empty-cells: hide;
}

The first length sets horizontal spacing, and the second sets vertical spacing.

Important Consideration

The empty-cells property does not change the value of border-spacing. It only affects the visibility of decorations on empty cells.

Inheritance

The empty-cells property is inherited, so it can be declared on a table and applied to its descendant cells.

Apply to an Entire Table

table {
  empty-cells: hide;
}

Override Individual Cells

table {
  empty-cells: hide;
}
td.always-visible {
  empty-cells: show;
}

Apply to Specific Tables

.data-table {
  empty-cells: show;
}
.decorative-table {
  empty-cells: hide;
}

Important Consideration

Although empty-cells is inherited, the property only affects table-cell boxes. Applying it to an ordinary block element does not hide that element's border or background.

empty-cells vs. visibility

The empty-cells and visibility properties can both affect the appearance of table cells, but they serve different purposes.

empty-cells: hide

td {
  empty-cells: hide;
}

Suppresses borders and backgrounds only when a cell qualifies as empty.

visibility: hidden

td {
  visibility: hidden;
}

Hides the cell's rendered content and decorations regardless of whether the cell contains data, while generally preserving its layout space.

Comparison

Behavior empty-cells: hide visibility: hidden
Affects non-empty cells No Yes
Requires separated borders Yes No
Preserves cell layout space Yes Generally yes
Hides cell content No Yes

Recommended Approach

Use empty-cells: hide when only the borders and backgrounds of empty cells should disappear. Use visibility: hidden when an entire cell's rendered contents and decorations need to be hidden.

empty-cells Example

This example compares two tables containing the same data. The first uses empty-cells: show, while the second uses empty-cells: hide.

Both tables use the separated border model so the difference is visible.

HTML Example

<div class="empty-cells-demo">
  <div>
    <h3>empty-cells: show</h3>
    <table class="show-cells">
      <tr>
        <th>Item</th>
        <th>Status</th>
        <th>Notes</th>
      </tr>
      <tr>
        <td>HTML</td>
        <td>Done</td>
        <td></td>
      </tr>
      <tr>
        <td>CSS</td>
        <td></td>
        <td>Review</td>
      </tr>
    </table>
  </div>
  <div>
    <h3>empty-cells: hide</h3>
    <table class="hide-cells">
      <tr>
        <th>Item</th>
        <th>Status</th>
        <th>Notes</th>
      </tr>
      <tr>
        <td>HTML</td>
        <td>Done</td>
        <td></td>
      </tr>
      <tr>
        <td>CSS</td>
        <td></td>
        <td>Review</td>
      </tr>
    </table>
  </div>
</div>

CSS Example

.empty-cells-demo {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
}
.empty-cells-demo h3 {
  margin-bottom: 10px;
  font-size: 1rem;
}
.empty-cells-demo table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 4px;
}
.empty-cells-demo th,
.empty-cells-demo td {
  border: 1px solid #336699;
  padding: 8px;
  background-color: #e8f1f8;
  text-align: left;
}
.empty-cells-demo th {
  background-color: #336699;
  color: #ffffff;
}
.empty-cells-demo .show-cells {
  empty-cells: show;
}
.empty-cells-demo .hide-cells {
  empty-cells: hide;
}
Browser Result

empty-cells: show

Item Status Notes
HTML Done
CSS Review

empty-cells: hide

Item Status Notes
HTML Done
CSS Review

In the first table, empty cells retain their borders and backgrounds. In the second table, empty cells have no visible border or background, but their positions remain part of the table layout.

This demonstrates that empty-cells changes the appearance of empty cells without removing them from the table structure.

Accessibility

The empty-cells property affects visual presentation, but it does not remove cells from the document or change their semantic relationships.

Use Semantic Table Markup

Use <table>, <tr>, <th>, and <td> elements for tabular data.

Identify Missing Data

When a blank cell represents missing or unavailable information, consider providing a meaningful label rather than relying on an empty visual space.

Do Not Depend on Borders Alone

Visitors should be able to understand the table's relationships even when some cell borders are hidden.

Maintain Readability

Ensure that remaining cell borders, backgrounds, and text provide sufficient visual separation.

Preserve Table Structure

Do not remove table cells solely to achieve a visual effect. Missing cells can disrupt the relationships between rows and columns.

Responsive Tables

When tables are displayed on smaller screens, ensure that hidden empty cell decorations do not make the data difficult to interpret.

Important Considerations

Keep the following points in mind when using empty-cells:

  • Purpose: Controls the display of borders and backgrounds on empty table cells.
  • Initial value: show.
  • Inheritance: The property is inherited.
  • Applies to: Table-cell elements.
  • show: Displays borders and backgrounds on empty cells.
  • hide: Suppresses borders and backgrounds on empty cells.
  • Border model: Only affects tables using border-collapse: separate.
  • Collapsed borders: Has no effect when border-collapse: collapse is used.
  • Layout: Empty cells continue to occupy their assigned positions.
  • Spacing: Does not change the border-spacing value.
  • Whitespace: Ordinary collapsible whitespace does not normally make a cell non-empty.
  • Nonbreaking spaces: A nonbreaking space generally prevents a cell from being treated as empty.
  • Table backgrounds: Hiding a cell's background does not hide backgrounds applied to the table or its other structural boxes.
  • Animation: Changes between show and hide are discrete.
  • Accessibility: The property does not remove cells from the semantic table structure.

Use empty-cells: show for a consistent table grid and empty-cells: hide when blank cells should visually blend into the surrounding table.

Browser Support

The CSS empty-cells property is Widely available and supported by modern browsers, including Chrome, Edge, Firefox, and Safari.

Both show and hide have longstanding support. The property only affects table cells using the separated border model.

Supported Example

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

Feature Detection

@supports (empty-cells: hide) {
  table {
    border-collapse: separate;
    empty-cells: hide;
  }
}

Compatibility Considerations

Most compatibility issues arise from using border-collapse: collapse or from differences in how a cell's content affects whether it is considered empty.

For current compatibility information, visit Can I Use? .

Specifications

The empty-cells property is defined in CSS 2.2, within the section covering table formatting and visual layout.

CSS 2.2: Empty Cells

Related table formatting behavior is also described in CSS Table Module Level 3.

CSS Table Module Level 3

These specifications describe empty cell rendering, separated and collapsed borders, and the table formatting model.