Universal selectors

  • Revision slug: CSS/Universal_selectors
  • Revision title: Universal selectors
  • Revision id: 289369
  • Created:
  • Creator: teoli
  • Is current revision? No
  • Comment

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, the 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() }}

See also

Revision Source

<p>{{ CSSRef() }}</p>
<h2 id="Summary">Summary</h2>
<p>An Asterisk (<code>*</code>) 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, <code>*.warning</code> and <code>.warning</code> are considered equal.</p>
<p>In CSS 3, the asterisk (<code>*</code>) may be used in combination with namespace</p>
<ul>
  <li><code>ns|*</code> - matches all elements in namespace ns</li>
  <li><code>*|*</code> - matches all elements</li>
  <li><code>|*</code> - matches all elements without any declared namespace</li>
</ul>
<h2 id="Examples" 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>
<h2 id="Specifications">Specifications</h2>
<table class="standard-table">
  <thead>
    <tr>
      <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 id="Browser_compatibility" 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>
<h2 id="See_also">See also</h2>
Revert to this revision