π Introduction
The empty-cells property in CSS controls whether borders and backgrounds are displayed on table cells that contain no content. This property applies only to table elements built with<table>, <tr>, and<td>. It is especially useful when designing clean, minimal, or grid-like table layouts. β¨
π― What Does empty-cells Do?
- Controls the visibility of borders on empty table cells
- Controls background visibility on empty cells
- Useful for compact and cleaner table UI
- Affects only table cells created by the table layout model
β¨ Syntax
Syntax
selector {
empty-cells: show | hide;
}Note
It has no effect when
border-collapse: collapse;.π§© Available Values
1. show (default)
Empty cells will still display borders and background.
show
empty-cells: show;2. hide
Empty cells will not show any borders or background β they appear visually removed.
hide
empty-cells: hide;π₯ Practical Examples
1. Default Behavior (show)
Default
table {
border: 1px solid #333;
border-collapse: separate; /* required */
empty-cells: show;
}2. Hiding Empty Cells
Hide Empty Cells
table {
border: 1px solid #333;
border-collapse: separate; /* required */
empty-cells: hide;
}3. Example Table Markup
HTML Example
<table>
<tr>
<td>1</td>
<td></td> <!-- Empty -->
<td>3</td>
</tr>
<tr>
<td></td> <!-- Empty -->
<td>5</td>
<td></td> <!-- Empty -->
</tr>
</table>4. Useful for Calendar UI
hide empty cells to create cleaner layouts for calendars or scheduling grids.
Calendar Styling
.calendar {
border-collapse: separate;
empty-cells: hide;
border-spacing: 5px;
}π Behavior Table
| Value | Border Visible? | Background Visible? | Use Case |
|---|---|---|---|
| show | Yes | Yes | Default table appearance |
| hide | No | No | Cleaner/minimal tables |
π§ Important Notes
- empty-cells only works when
border-collapse = separate. - Does not hide non-empty cells (even if they contain whitespace).
- Useful for aesthetic layouts like calendars and pricing tables.
- Use with
border-spacingfor better spacing control.
π Conclusion
The empty-cells property lets you enhance the appearance of table layouts by controlling how empty cells are rendered. Whether you're designing clean calendars or simple data tables, this property helps remove visual clutter and gives you more control over table design. π