Pseudo-classes

  • Revision slug: Web/CSS/Pseudo-classes
  • Revision title: Pseudo-classes
  • Revision id: 449539
  • 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('Fullscreen') }} {{ Spec2('Fullscreen') }}  
{{ SpecName('HTML WHATWG') }} {{ Spec2('HTML WHATWG') }}  
{{SpecName('CSS4 Selectors')}} {{Spec2('CSS4 Selectors')}}  
{{ SpecName('HTML5 W3C') }} {{ Spec2('HTML5 W3C') }} Defined the semantic meaning, in the HTML context, of :link, :visited, :active, :enabled, :disabled, :checked, and :indeterminate.
Defined :default, :valid, :invalid, :in-range, :out-of-range, :required, :optional, :read-only, :read-write, and :dir().
{{ SpecName('CSS3 Basic UI') }} {{ Spec2('CSS3 Basic UI') }} Defined :default, :valid, :invalid, :in-range, :out-of-range, :required, :optional, :read-only, and :read-write, but without the associated semantic meaning.
{{SpecName('CSS3 Selectors')}} {{Spec2('CSS3 Selectors')}} Defined :target, :root, :nth-child(), :nth-last-of-child(), :nth-of-type(), :nth-last-of-type(), :last-child, :first-of-type, :last-of-type, :only-child, :only-of-type, :empty, and :not().
Defined the syntax of :enabled, :disabled, :checked, and :indeterminate, but without the associated semantic meaning.
No significant change for pseudo-classes defined in {{SpecName('CSS2.1')}}.
{{SpecName('CSS2.1')}} {{Spec2('CSS2.1')}} Defined :lang(), :fist-child, :hover, and :focus.
No significant change for pseudo-classes defined in {{SpecName('CSS1')}}.
{{SpecName('CSS1')}} {{Spec2('CSS1')}} Defined :link, :visited, and :active, but without the associated semantic meaning.

 

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('Fullscreen') }}</td>
      <td>{{ Spec2('Fullscreen') }}</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>{{ SpecName('HTML WHATWG') }}</td>
      <td>{{ Spec2('HTML WHATWG') }}</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>{{SpecName('CSS4 Selectors')}}</td>
      <td>{{Spec2('CSS4 Selectors')}}</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>{{ SpecName('HTML5 W3C') }}</td>
      <td>{{ Spec2('HTML5 W3C') }}</td>
      <td>Defined the semantic meaning, in the HTML context, of <code>:link</code>, <code>:visited</code>, <code>:active</code>, <code>:enabled</code>, <code>:disabled</code>, <code>:checked</code>, and <code>:indeterminate</code>.<br />
        Defined <code>:default</code>, <code>:valid</code>, <code>:invalid</code>, <code>:in-range</code>, <code>:out-of-range</code>, <code>:required</code>, <code>:optional</code>, <code>:read-only</code>, <code>:read-write</code>, and <code>:dir()</code>.</td>
    </tr>
    <tr>
      <td>{{ SpecName('CSS3 Basic UI') }}</td>
      <td>{{ Spec2('CSS3 Basic UI') }}</td>
      <td>Defined <code>:default</code>, <code>:valid</code>, <code>:invalid</code>, <code>:in-range</code>, <code>:out-of-range</code>, <code>:required</code>, <code>:optional</code>, <code>:read-only</code>, and <code>:read-write</code>, but without the associated semantic meaning.</td>
    </tr>
    <tr>
      <td>{{SpecName('CSS3 Selectors')}}</td>
      <td>{{Spec2('CSS3 Selectors')}}</td>
      <td>Defined <code>:target</code>, <code>:root</code>, <code>:nth-child()</code>, <code>:nth-last-of-child()</code>, <code>:nth-of-type()</code>, <code>:nth-last-of-type()</code>, <code>:last-child</code>, <code>:first-of-type</code>, <code>:last-of-type</code>, <code>:only-child</code>, <code>:only-of-type</code>, <code>:empty</code>, and <code>:not()</code>.<br />
        Defined the syntax of <code>:enabled</code>, <code>:disabled</code>, <code>:checked</code>, and <code>:indeterminate</code>, but without the associated semantic meaning.<br />
        No significant change for pseudo-classes defined in {{SpecName('CSS2.1')}}.</td>
    </tr>
    <tr>
      <td>{{SpecName('CSS2.1')}}</td>
      <td>{{Spec2('CSS2.1')}}</td>
      <td>Defined <code>:lang()</code>, <code>:fist-child</code>, <code>:hover</code>, and <code>:focus</code>.<br />
        No significant change for pseudo-classes defined in {{SpecName('CSS1')}}.</td>
    </tr>
    <tr>
      <td>{{SpecName('CSS1')}}</td>
      <td>{{Spec2('CSS1')}}</td>
      <td>Defined <code>:link</code>, <code>:visited</code>, and <code>:active</code>, but without the associated semantic meaning.</td>
    </tr>
  </tbody>
</table>
<p>&nbsp;</p>
Revert to this revision