CSS / Reference / empty-cells: Show or Hide Empty Table Cells
CSS empty-cells decides whether an empty table cell paints its border and background when the table uses border-collapse: separate. Use show to paint them and hide to suppress them. Both values preserve the cells and their data in the HTML.
Set empty-cell borders and backgrounds
The initial value is show. The property is inherited, so set it on the table and override it with empty-cells: show on an individual cell when needed.
With border-collapse: collapse, shared edges are merged and empty-cells has no visual effect. A row with another populated cell still occupies space as it does in the example. A wholly empty row can behave differently.
.demo { border-collapse: separate; empty-cells: hide; }
W3C rules for painting empty cells
Compare show and hide on identical tables
Save the complete example as empty-cells-example.html in UTF-8 and open it in a browser. The markup and colors match in both tables. Only empty-cells differs.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Comparing empty table cells</title>
<style>
body { margin: 1rem; font: 1rem/1.5 system-ui, sans-serif; }
.samples { display: flex; flex-wrap: wrap; gap: 1rem; }
.demo {
border-collapse: separate;
border-spacing: 4px;
background: #dbeafe;
}
.demo.show { empty-cells: show; }
.demo.hide { empty-cells: hide; }
.demo th, .demo td {
border: 1px solid #334155;
background: #fef3c7;
padding: .5rem;
}
.demo td { min-width: 3.5rem; }
.demo caption { text-align: start; }
</style>
</head>
<body>
<h1>Comparing empty table cells</h1>
<div class="samples">
<table class="demo show">
<caption>empty-cells: show</caption>
<thead><tr><th scope="col">Item</th><th scope="col">Quantity</th></tr></thead>
<tbody>
<tr><th scope="row">Part A</th><td class="blank"></td></tr>
<tr><th scope="row">Part B</th><td>18</td></tr>
</tbody>
</table>
<table class="demo hide">
<caption>empty-cells: hide</caption>
<thead><tr><th scope="col">Item</th><th scope="col">Quantity</th></tr></thead>
<tbody>
<tr><th scope="row">Part A</th><td class="blank"></td></tr>
<tr><th scope="row">Part B</th><td>18</td></tr>
</tbody>
</table>
</div>
</body>
</html>
The first table paints a yellow background and a border on the blank quantity cell. The same slot in the second table shows the blue table background because the cell’s own background and border are suppressed. Both rows and columns remain.
Try whitespace and the collapsed-border model
- Add one ordinary space to the empty cell in the second table. With default whitespace handling, it collapses away and the cell still counts as empty.
- Replace that space with
. A nonbreaking space survives collapsing, so the yellow background and border appear. Remove it to restore the empty cell. - Change
border-collapsetocollapsefor both tables. Both empty cells paint their backgrounds. Restoreseparateafter comparing.
Diagnose an empty cell that still paints
Inspect the table’s computed border-collapse and the cell’s computed empty-cells. Check for nonbreaking spaces, inline children, and generated content that can give the cell something to render.
The table’s own background can show through a hidden cell. Set the outer border and cell spacing separately. When readers need to know why a value is missing, provide an explicit value such as “Not applicable.”
See CSS table borders and sizing for related layout choices.




