πŸ“„ CSS Tutorial: empty-cells

πŸ“Œ 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

Works only when border-collapse is set to separate (default).
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

ValueBorder Visible?Background Visible?Use Case
showYesYesDefault table appearance
hideNoNoCleaner/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-spacing for better spacing control.
>>β€œSmall details matter β€” even empty table cells can affect the UI.” ✨

πŸŽ‰ 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. πŸš€