Universal selectors

  • Revision slug: CSS/Universal_selectors
  • Revision title: Universal selectors
  • Revision id: 6517
  • Created:
  • Creator: FredB
  • Is current revision? No
  • Comment 154 words added, 3 words removed

Revision Content

{{ CSSRef() }}

Summary

An Asterisk (*) is the universal selector for CSS. It matches a single element of any type. Omitting the Asterisk with simple selectors has the same effect. For instance, *.warning and .warning are considered equal.

In CSS 3 Asterisk (*) may be used in combination with namespace

  • ns|* - matches all elements in namespace ns
  • *|* - matches all elements
  • |* - matches all elements without any declared namespace

Examples

*[lang=en]{color:green;}
*.warning {color:red;}
*#maincontent {border: 1px solid blue;}

...where...

<p class="warning">
  <span lang="en-us">A green span</span> in a red paragraph.
</p>
<p id="maincontent" lang="en-gb">
  <span class="warning">A red span</span> in a green paragraph.
</p>

...should look like

A green span in a red paragraph.

A red span in a green paragraph (with a border.)

Note : Authors are discouraged from using the universal selector as it is the most expensive CSS selector in terms of Webpage Performance.
Specifications
Specification Status Comment
CSS Selectors Level 3 {{ Spec2('CSS3 Selectors') }}  
CSS 2.1 {{ Spec2('CSS2.1') }}  

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{ CompatVersionUnknown() }} {{ CompatGeckoDesktop("1") }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }}
Combination with namespace support {{ CompatVersionUnknown() }} {{ CompatGeckoDesktop("1") }} {{ CompatVersionUnknown() }} 8 1.3
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatGeckoMobile("1") }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }}
Combination with namespace support {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }}

Browser compatibility

Browser Lowest Version
Internet Explorer ?
Firefox 1
Netscape ?
Opera ?
Safari ?

See also

{{ languages( { "fr": "fr/CSS/Sélecteurs_universels" }) }}

Revision Source

<p>{{ CSSRef() }}</p>
<div>Summary</div>
<p>An Asterisk (*) is the universal selector for CSS. It matches a single element of any type. Omitting the Asterisk with simple selectors has the same effect. For instance, *.warning and .warning are considered equal.</p>
<p>In CSS 3 Asterisk (*) may be used in combination with namespace</p>
<ul> <li>ns|* - matches all elements in namespace ns</li> <li>*|* - matches all elements</li> <li>|* - matches all elements without any declared namespace</li>
</ul>
<h2 name="Examples">Examples</h2>
<pre class="brush: css">*[lang=en]{color:green;}
*.warning {color:red;}
*#maincontent {border: 1px solid blue;}
</pre>
<p>...where...</p>
<pre class="brush: html">&lt;p class="warning"&gt;
  &lt;span lang="en-us"&gt;A green span&lt;/span&gt; in a red paragraph.
&lt;/p&gt;
&lt;p id="maincontent" lang="en-gb"&gt;
  &lt;span class="warning"&gt;A red span&lt;/span&gt; in a green paragraph.
&lt;/p&gt;
</pre>
<p>...should look like</p>
<p><span style="color: rgb(0, 255, 0);">A green span</span><span style="color: rgb(255, 0, 0);"> in a red paragraph.</span></p>
<p style="border: 1px solid blue;"><span style="color: rgb(255, 0, 0);">A red span</span><span style="color: rgb(0, 255, 0);"> in a green paragraph (with a border.)</span></p>
<div class="note">Note : Authors are discouraged from using the universal selector as it is the <a class="external" href="http://www.stevesouders.com/blog/2009/06/18/simplifying-css-selectors/" title="http://www.stevesouders.com/blog/2009/06/18/simplifying-css-selectors/">most expensive CSS selector</a> in terms of Webpage Performance.</div>
<div>Specifications</div>
<table class="standard-table"> <thead> <tr style="background-color: rgb(255, 204, 255);"> <th scope="col">Specification</th> <th scope="col">Status</th> <th scope="col">Comment</th> </tr> </thead> <tbody> <tr> <td><a class="external" href="http://www.w3.org/TR/css3-selectors/#universal-selector" title="http://www.w3.org/TR/css3-selectors/#universal-selector">CSS Selectors Level 3</a></td> <td>{{ Spec2('CSS3 Selectors') }}</td> <td> </td> </tr> <tr> <td><a class="external" href="http://www.w3.org/TR/CSS21/selector.html#universal-selector" title="http://www.w3.org/TR/CSS21/selector.html#universal-selector">CSS 2.1</a></td> <td>{{ Spec2('CSS2.1') }}</td> <td> </td> </tr> </tbody>
</table>
<h2 name="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>{{ CompatVersionUnknown() }}</td> <td>{{ CompatGeckoDesktop("1") }}</td> <td>{{ CompatVersionUnknown() }}</td> <td>{{ CompatVersionUnknown() }}</td> <td>{{ CompatVersionUnknown() }}</td> </tr> <tr> <td>Combination with namespace support</td> <td>{{ CompatVersionUnknown() }}</td> <td>{{ CompatGeckoDesktop("1") }}</td> <td>{{ CompatVersionUnknown() }}</td> <td>8</td> <td>1.3</td> </tr> </tbody> </table>
</div>
<div id="compat-mobile"> <table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Android</th> <th>Chrome for 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>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatGeckoMobile("1") }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> </tr> <tr> <td>Combination with namespace support</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> </tr> </tbody> </table>
</div>
<h3 name="Browser_compatibility">Browser compatibility</h3>
<table class="standard-table"> <tbody> <tr> <th>Browser</th> <th>Lowest Version</th> </tr> <tr> <td>Internet Explorer</td> <td>?</td> </tr> <tr> <td>Firefox</td> <td>1</td> </tr> <tr> <td>Netscape</td> <td>?</td> </tr> <tr> <td>Opera</td> <td>?</td> </tr> <tr> <td>Safari</td> <td>?</td> </tr> </tbody>
</table>
<h2>See also</h2>
<p>{{ languages( { "fr": "fr/CSS/Sélecteurs_universels" }) }}</p>
Revert to this revision