:empty

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

* Some parts of this feature may have varying levels of support.

Описание

Псевдокласс :empty находит любой элемент, у которого нет потомков. Учитываются элементы и текст (включая пробелы). Комментарии не повлияют на то, что элемент будет рассматриваться как не пустой.

Синтаксис

<element>:empty { /* стили */ }

Примеры

css
.box {
  background: red;
  height: 200px;
  width: 200px;
}

.box:empty {
  background: lime;
}
html
<div class="box"><!-- Я буду лаймовым --></div>
<div class="box">Я буду красным</div>
<div class="box">
  <!-- Я буду красным, так как перед комментарием стоят пробелы -->
</div>

Спецификации

Specification
Selectors Level 4
# the-empty-pseudo

Совместимость с браузерами

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
:empty
Matches elements with whitespace

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
See implementation notes.