Pseudo-classes

  • Revision slug: Web/CSS/Pseudo-classes
  • Revision title: Pseudo-classes
  • Revision id: 449505
  • Created:
  • Creator: teoli
  • Is current revision? No
  • Comment

Revision Content

{{ CSSRef() }}

A CSS pseudo-class is a keyword added to selectors that specifies a special state of the element to be selected. For example {{ Cssxref(":hover") }} will apply a style when the user hovers over the element specified by the selector.

Pseudo-classes, together with pseudo-elements, let you apply a style to an element not only in relation to the content of the document tree, but also in relation to external factors like the history of the navigator ({{ cssxref(":visited") }}, for example), the status of its content (like {{ cssxref(":checked") }} on some form elements), or the position of the mouse (like {{ cssxref(":hover") }} which lets you know if the mouse is over an element or not).

Syntax

selector:pseudo-class {
  property: value;
} 

Index of standard pseudo-classes

  • {{ Cssxref(":active") }}
  • {{ Cssxref(":checked") }}
  • {{ Cssxref(":default") }}
  • {{ Cssxref(":dir", ":dir()")}}
  • {{ Cssxref(":disabled") }}
  • {{ Cssxref(":empty") }}
  • {{ Cssxref(":enabled") }}
  • {{ Cssxref(":first") }}
  • {{ Cssxref(":first-child") }}
  • {{ Cssxref(":first-of-type") }}
  • {{ Cssxref(":fullscreen") }}
  • {{ Cssxref(":focus") }}
  • {{ Cssxref(":hover") }}
  • {{ Cssxref(":indeterminate") }}
  • {{ Cssxref(":in-range") }}
  • {{ Cssxref(":invalid") }}
  • {{ Cssxref(":lang", ":lang()") }}
  • {{ Cssxref(":last-child") }}
  • {{ Cssxref(":last-of-type") }}
  • {{ Cssxref(":left") }}
  • {{ Cssxref(":link") }}
  • {{ Cssxref(":not", ":not()") }}
  • {{ Cssxref(":nth-child", ":nth-child()") }}
  • {{ Cssxref(":nth-last-child", ":nth-last-child()") }}
  • {{ Cssxref(":nth-last-of-type", ":nth-last-of-type()") }}
  • {{ Cssxref(":nth-of-type", ":nth-of-type()") }}
  • {{ Cssxref(":only-child") }}
  • {{ Cssxref(":only-of-type") }}
  • {{ Cssxref(":optional") }}
  • {{ Cssxref(":out-of-range") }}
  • {{ Cssxref(":read-only") }}
  • {{ Cssxref(":read-write") }}
  • {{ Cssxref(":required") }}
  • {{ Cssxref(":right") }}
  • {{ Cssxref(":root") }}
  • {{ Cssxref(":scope") }}
  • {{ Cssxref(":target") }}
  • {{ Cssxref(":valid") }}
  • {{ Cssxref(":visited") }}

Specifications

Specification Status Comment
{{ SpecName('HTML WHATWG') }} {{ Spec2('HTML WHATWG') }}  
{{ SpecName('HTML5 W3C') }} {{ Spec2('HTML5 W3C') }}  
{{SpecName('CSS4 Selectors')}} {{Spec2('CSS4 Selectors')}}  
{{SpecName('CSS3 Selectors')}} {{Spec2('CSS3 Selectors')}}  
{{ SpecName('CSS3 UI') }} {{ Spec2('CSS3 UI') }}  
{{SpecName('CSS2.1')}} {{Spec2('CSS2.1')}}  
{{SpecName('CSS1')}} {{Spec2('CSS1')}}  

 

Revision Source

<p>{{ CSSRef() }}</p>
<p>A CSS <strong><em><dfn>pseudo-class</dfn></em></strong> is a keyword added to selectors that specifies a special state of the element to be selected. For example {{ Cssxref(":hover") }} will apply a style when the user hovers over the element specified by the selector.</p>
<p>Pseudo-classes, together with pseudo-elements, let you apply a style to an element not only in relation to the content of the document tree, but also in relation to external factors like the history of the navigator ({{ cssxref(":visited") }}, for example), the status of its content (like {{ cssxref(":checked") }} on some form elements), or the position of the mouse (like {{ cssxref(":hover") }} which lets you know if the mouse is over an element or not).</p>
<h2 id="Syntax">Syntax</h2>
<pre class="syntaxbox">
selector:pseudo-class {
  property: value;
} 
</pre>
<h2 id="Index_of_standard_pseudo-classes">Index of standard pseudo-classes</h2>
<div class="index">
  <ul>
    <li>{{ Cssxref(":active") }}</li>
    <li>{{ Cssxref(":checked") }}</li>
    <li>{{ Cssxref(":default") }}</li>
    <li>{{ Cssxref(":dir", ":dir()")}}</li>
    <li>{{ Cssxref(":disabled") }}</li>
    <li>{{ Cssxref(":empty") }}</li>
    <li>{{ Cssxref(":enabled") }}</li>
    <li>{{ Cssxref(":first") }}</li>
    <li>{{ Cssxref(":first-child") }}</li>
    <li>{{ Cssxref(":first-of-type") }}</li>
    <li>{{ Cssxref(":fullscreen") }}</li>
    <li>{{ Cssxref(":focus") }}</li>
    <li>{{ Cssxref(":hover") }}</li>
    <li>{{ Cssxref(":indeterminate") }}</li>
    <li>{{ Cssxref(":in-range") }}</li>
    <li>{{ Cssxref(":invalid") }}</li>
    <li>{{ Cssxref(":lang", ":lang()") }}</li>
    <li>{{ Cssxref(":last-child") }}</li>
    <li>{{ Cssxref(":last-of-type") }}</li>
    <li>{{ Cssxref(":left") }}</li>
    <li>{{ Cssxref(":link") }}</li>
    <li>{{ Cssxref(":not", ":not()") }}</li>
    <li>{{ Cssxref(":nth-child", ":nth-child()") }}</li>
    <li>{{ Cssxref(":nth-last-child", ":nth-last-child()") }}</li>
    <li>{{ Cssxref(":nth-last-of-type", ":nth-last-of-type()") }}</li>
    <li>{{ Cssxref(":nth-of-type", ":nth-of-type()") }}</li>
    <li>{{ Cssxref(":only-child") }}</li>
    <li>{{ Cssxref(":only-of-type") }}</li>
    <li>{{ Cssxref(":optional") }}</li>
    <li>{{ Cssxref(":out-of-range") }}</li>
    <li>{{ Cssxref(":read-only") }}</li>
    <li>{{ Cssxref(":read-write") }}</li>
    <li>{{ Cssxref(":required") }}</li>
    <li>{{ Cssxref(":right") }}</li>
    <li>{{ Cssxref(":root") }}</li>
    <li>{{ Cssxref(":scope") }}</li>
    <li>{{ Cssxref(":target") }}</li>
    <li>{{ Cssxref(":valid") }}</li>
    <li>{{ Cssxref(":visited") }}</li>
  </ul>
</div>
<h2 id="Specifications"><span>Specifications</span></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>{{ SpecName('HTML WHATWG') }}</td>
      <td>{{ Spec2('HTML WHATWG') }}</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>{{ SpecName('HTML5 W3C') }}</td>
      <td>{{ Spec2('HTML5 W3C') }}</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>{{SpecName('CSS4 Selectors')}}</td>
      <td>{{Spec2('CSS4 Selectors')}}</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>{{SpecName('CSS3 Selectors')}}</td>
      <td>{{Spec2('CSS3 Selectors')}}</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>{{ SpecName('CSS3 UI') }}</td>
      <td>{{ Spec2('CSS3 UI') }}</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>{{SpecName('CSS2.1')}}</td>
      <td>{{Spec2('CSS2.1')}}</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>{{SpecName('CSS1')}}</td>
      <td>{{Spec2('CSS1')}}</td>
      <td>&nbsp;</td>
    </tr>
  </tbody>
</table>
<p>&nbsp;</p>
Revert to this revision