--- title: ':empty' slug: 'Web/CSS/:empty' tags: - CSS - Layout - Pseudo-class - Reference - Web translation_of: 'Web/CSS/:empty' ---
{{ CSSRef() }}

La pseudo-class CSS :empty representa qualsevol element que no tingui fills. Els fills poden ser nodes d'elements o text (inclosos els espais en blanc). Els comentaris o les instruccions de processament no afecten si un element es considera buit o no.

/* Selecciona qualsevol <div> que no contingui cap contingut */
div:empty {
  background: lime;
}

Sintaxi

{{csssyntax}}

Exemples

HTML

<div class="box"><!-- I will be lime. --></div>
<div class="box">I will be pink.</div>
<div class="box">
    <!-- I will be pink because of the whitespace around this comment. -->
</div>

CSS

.box {
  background: pink;
  height: 80px;
  width: 80px;
}

.box:empty {
  background: lime;
}

Resultat

{{EmbedLiveSample('Examples', 300, 80)}}

Especificacions

Especificació Estat Comentari
{{ SpecName('CSS4 Selectors', '#empty-pseudo', ':empty') }} {{ Spec2('CSS4 Selectors') }} Sense canvis
{{ SpecName('CSS3 Selectors', '#empty-pseudo', ':empty') }} {{ Spec2('CSS3 Selectors') }} Definició inicial

{{ CompatibilityTable() }}

Descripció Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
Suport bàsic 1.0 {{CompatVersionUnknown}} {{ CompatGeckoDesktop("1") }} 9.0 9.5 3.1
Descripció Android Edge Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Suport bàsic 2.1 {{CompatVersionUnknown}} {{ CompatGeckoMobile("1") }} 9.5 10.0 3.1