:active

  • Revision slug: CSS/:active
  • Revision title: :active
  • Revision id: 381337
  • Created:
  • Creator: teoli
  • Is current revision? No
  • Comment

Revision Content

{{ CSSRef() }}

Summary

The :active CSS pseudo-class matches when an element is being activated by the user. It allows the page to give a feedback that the activation has been detected by the browser. When interacting with a mouse, this is typically the time between the user presses the mouse button and releases it. The :active pseudo-class is also typically matched when using the keyboard tab key. It is frequently used on {{ HTMLElement("a") }} and {{ HTMLElement("button") }} HTML elements, but may not be limited to just those.

This style may be overridden by any other link-related pseudo-classes, that is {{ cssxref(":link") }}, {{ cssxref(":hover") }}, and {{ cssxref(":visited") }}, appearing in subsequent rules. In order to style appropriately links, you need to put the :active rule after the all others link-related rules, as defined by the LVHA-order: :link:visited:hover:active.

Note: on system with mice having several buttons, CSS 3 specifies that the :active pseudo-class must only apply to the primary button, typically the left-most button on mice for right-handed.

Example

HTML

<body>
    <h1>:active CSS selector example</h1>
    <p>The following link will turn lime during the time you click it and release the click: <a href="#">Mozilla Developer Network</a>.</p>
</body>

CSS

body { background-color: #ffffc9 }
a:link { color: blue } /* unvisited links */
a:visited { color: purple } /* visited links */
a:hover { font-weight: bold } /* user hovers */
a:active { color: lime } /* active links */

{{ EmbedLiveSample(':active_Live_Sample',600,140) }}

Specifications

Specification Status Comment
{{ SpecName('CSS4 Selectors', '#active-pseudo', ':active') }} {{ Spec2('CSS4 Selectors') }} No change.
{{ SpecName('CSS3 Selectors', '#useraction-pseudos', ':active') }} {{ Spec2('CSS3 Selectors') }} No change.
{{ SpecName('CSS2.1', 'selector.html#dynamic-pseudo-classes', ':active') }} {{ Spec2('CSS2.1') }} No change.
{{ SpecName('CSS1', '#anchor-pseudo-classes', ':active') }} {{ Spec2('CSS1') }} Initial definition.

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Support on the <a> element 1.0 {{ CompatGeckoDesktop("1.0") }} 4.0 5.0 1.0
Support on any element 1.0 {{ CompatGeckoDesktop("1.0") }} 8.0 7.0  
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Support on the <a> element 1.0 {{ CompatGeckoMobile("1.0") }} 6.0 6.0 1.0
Support on any element 1.0 {{ CompatGeckoMobile("1.0") }} {{ CompatUnknown() }}    

See also

  • Link-related pseudo-classes: {{ cssxref(":link") }}, {{ cssxref(":visited") }}, and {{ cssxref(":hover") }}.

Revision Source

<p>{{ CSSRef() }}</p>
<h2 id="Summary">Summary</h2>
<p>The <code>:active</code> CSS <a href="/en/CSS/Pseudo-classes" title="Pseudo-classes">pseudo-class</a> matches when an element is being activated by the user. It allows the page to give a feedback that the activation has been detected by the browser. When interacting with a mouse, this is typically the time between the user presses the mouse button and releases it. The <code>:active</code> pseudo-class is also typically matched when using the keyboard tab key. It is frequently used on {{ HTMLElement("a") }} and {{ HTMLElement("button") }} HTML&nbsp;elements, but may not be limited to just those.</p>
<p>This style may be overridden by any other link-related pseudo-classes, that is {{ cssxref(":link") }}, {{ cssxref(":hover") }}, and {{ cssxref(":visited") }}, appearing in subsequent rules. In order to style appropriately links, you need to put the <code>:active</code> rule after the all others link-related rules, as defined by the <em>LVHA-order</em>: <code>:link</code> — <code>:visited</code> — <code>:hover</code> — <code>:active</code>.</p>
<div class="note">
  <strong>Note:</strong> on system with mice having several buttons, CSS 3 specifies that the <code>:active</code> pseudo-class must only apply to the primary button, typically the left-most button on mice for right-handed.</div>
<h2 id=":active_Live_Sample" name=":active_Live_Sample">Example</h2>
<h3 id="HTML">HTML</h3>
<pre class="brush: html; highlight:[3]">
&lt;body&gt;
&nbsp;&nbsp;&nbsp; &lt;h1&gt;:active CSS selector example&lt;/h1&gt;
&nbsp;&nbsp;&nbsp; &lt;p&gt;The following link will turn lime during the time you click it and release the click: &lt;a href="#"&gt;Mozilla Developer Network&lt;/a&gt;.&lt;/p&gt;
&lt;/body&gt;</pre>
<h3 id="CSS">CSS</h3>
<pre class="brush: css; highlight:[5]">
body { background-color: #ffffc9 }
a:link { color: blue } /* unvisited links */
a:visited { color: purple } /* visited links */
a:hover { <span class="st">font-weight: bold</span> } /* user hovers */
a:active { color: lime } /* active links */</pre>
<p>{{ EmbedLiveSample(':active_Live_Sample',600,140) }}</p>
<h2 class="editable" 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('CSS4 Selectors', '#active-pseudo', ':active') }}</td>
      <td>{{ Spec2('CSS4 Selectors') }}</td>
      <td>No change.</td>
    </tr>
    <tr>
      <td>{{ SpecName('CSS3 Selectors', '#useraction-pseudos', ':active') }}</td>
      <td>{{ Spec2('CSS3 Selectors') }}</td>
      <td>No change.</td>
    </tr>
    <tr>
      <td>{{ SpecName('CSS2.1', 'selector.html#dynamic-pseudo-classes', ':active') }}</td>
      <td>{{ Spec2('CSS2.1') }}</td>
      <td>No change.</td>
    </tr>
    <tr>
      <td>{{ SpecName('CSS1', '#anchor-pseudo-classes', ':active') }}</td>
      <td>{{ Spec2('CSS1') }}</td>
      <td>Initial definition.</td>
    </tr>
  </tbody>
</table>
<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>Support on the <code>&lt;a&gt;</code> element</td>
        <td>1.0</td>
        <td>{{ CompatGeckoDesktop("1.0") }}</td>
        <td>4.0</td>
        <td>5.0</td>
        <td>1.0</td>
      </tr>
      <tr>
        <td>Support on any element</td>
        <td>1.0</td>
        <td>{{ CompatGeckoDesktop("1.0") }}</td>
        <td>8.0</td>
        <td>7.0</td>
        <td>&nbsp;</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>Support on the <code>&lt;a&gt;</code> element</td>
        <td>1.0</td>
        <td>{{ CompatGeckoMobile("1.0") }}</td>
        <td>6.0</td>
        <td>6.0</td>
        <td>1.0</td>
      </tr>
      <tr>
        <td>Support on any element</td>
        <td>1.0</td>
        <td>{{ CompatGeckoMobile("1.0") }}</td>
        <td>{{ CompatUnknown() }}</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
    </tbody>
  </table>
</div>
<h2 id="See_also">See also</h2>
<ul>
  <li>Link-related pseudo-classes: {{ cssxref(":link") }}, {{ cssxref(":visited") }}, and {{ cssxref(":hover") }}.</li>
</ul>
Revert to this revision