Want to share your CSS expertise with others? Apply to the MDN Fellowship by April 1! http://mzl.la/MDNFellowship

mozilla

Revision 41275 of :empty

  • Revision slug: CSS/:empty
  • Revision title: :empty
  • Revision id: 41275
  • Created:
  • Creator: brianloveswords
  • Is current revision? No
  • Comment 3 words removed

Revision Content

{{ CSSRef() }}

Summary

The :empty pseudo-class represents any element that has no children at all. Only element nodes and text (including whitespace) are considered. Comments or processing instructions do not affect whether an element is considered empty or not.

Syntax

<element>:empty { style properties }

Examples

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

.box:empty {
  background: lime;
}
<div class="box"><!-- I will be lime --></div>
<div class="box">I will be red</div>

Specifications

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1.0 {{ CompatGeckoDesktop("1") }} 9.0 9.5 3.1
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support 2.1 {{ CompatGeckoMobile("1") }} 9.5 10.0 3.1

Revision Source

<p>{{ CSSRef() }}</p>
<h2 id="Summary" name="Summary">Summary</h2>
<p>The<code> :empty </code><a href="/en/CSS/Pseudo-classes" title="Pseudo-classes">pseudo-class</a> represents any element that has no children at all. Only element nodes and text (including whitespace) are considered. Comments or processing instructions do not affect whether an element is considered empty or not.</p>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre class="eval">&lt;element&gt;:empty { <em>style properties</em> }
</pre>
<h2 id="Examples" name="Examples">Examples</h2>
<pre class="brush: css">.box {
  background: red;
  height: 200px;
  width: 200px;
}

.box:empty {
  background: lime;
}
</pre>
<pre class="brush: html">&lt;div class="box"&gt;&lt;!-- I will be lime --&gt;&lt;/div&gt;
&lt;div class="box"&gt;I will be red&lt;/div&gt;
</pre>
<h2 id="Specifications" name="Specifications">Specifications</h2>
<ul> <li><a class="external" href="http://www.w3.org/TR/css3-selectors/#empty-pseudo" title="http://www.w3.org/TR/css3-selectors/#empty-pseudo">CSS3 Selectors #empty-pseudo</a></li>
</ul>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<p>{{ CompatibilityTable() }}</p>
<div id="compat-desktop"> <table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Chrome</th> <th>Firefox (Gecko)</th> <th>Internet Explorer</th> <th>Opera</th> <th>Safari</th> </tr> <tr> <td>Basic support</td> <td>1.0</td> <td>{{ CompatGeckoDesktop("1") }}</td> <td>9.0</td> <td>9.5</td> <td>3.1</td> </tr> </tbody> </table>
</div>
<div id="compat-mobile"> <table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Android</th> <th>Firefox Mobile (Gecko)</th> <th>IE Mobile</th> <th>Opera Mobile</th> <th>Safari Mobile</th> </tr> <tr> <td>Basic support</td> <td>2.1</td> <td>{{ CompatGeckoMobile("1") }}</td> <td>9.5</td> <td>10.0</td> <td>3.1</td> </tr> </tbody> </table>
</div>
Revert to this revision