:visited

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

Revision Content

{{ CSSRef() }}

Summary

The :visited CSS pseudo-class lets you select only links that have been visited. This style may be overridden by any other link-related pseudo-classes, that is {{ cssxref(":link") }}, {{ cssxref(":hover") }}, and {{ cssxref(":active") }}, appearing in subsequent rules. In order to style appropriately links, you need to put the :visited rule after the :link rule but before the other ones, defined in the LVHA-order: :link:visited:hover:active.

Note: For privacy reasons, browsers strictly limit the styles you can apply using an element selected by this pseudo-class: only {{ cssxref("color") }}, {{ cssxref("background-color") }}, {{ cssxref("border-color") }}, {{ cssxref("border-bottom-color") }}, {{ cssxref("border-left-color") }}, {{ cssxref("border-right-color") }}, {{ cssxref("border-top-color") }}, {{ cssxref("outline-color") }}, {{ cssxref("column-rule-color") }}, fill and stroke. Note also that the alpha component will be ignored: the alpha component of the not-visited rule is used instead (except when the opacity is 0, in that case the whole color is ignored, and the one of the not-visited rule is used.

Though the color can be changed, the method getComputedStyle will lie and always give back the value of the non-visited color.

For more information on the limitations and the motivation for them, see {{ Cssxref("Privacy and the :visited selector") }}.

Examples

a:visited { color: #4b2f89; }
a:visited { background-color: white } 

Specifications

Specification Status Comment
{{ SpecName('CSS3 Selectors', '#link', ':visited') }} {{ Spec2('CSS3 Selectors') }} No change.
{{ SpecName('CSS2.1', 'selector.html#link-pseudo-classes', ':visited') }} {{ Spec2('CSS2.1') }} Lift the restriction to only apply it for {{ HTMLElement("a") }} element. Let users restricts its behavior for privacy reasons.
{{ SpecName('CSS1', '#anchor-pseudo-classes', ':visited') }} {{ Spec2('CSS1') }} Initial definition.

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 1.0 {{ CompatGeckoDesktop("1.0") }} 3.5 3.5 1.0
Restrictions in CSS properties allowed in a statement using :visited 6 {{CompatGeckoDesktop("2.0") }} 8 (or earlier) {{ CompatUnknown() }} 5.0
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support {{ CompatUnknown() }} {{ CompatGeckoMobile("1.0") }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }}

See also

  • {{ Cssxref("Privacy and the :visited selector") }}
  • {{ Cssxref(":link") }}

Revision Source

<p>{{ CSSRef() }}</p>
<h2 id="Summary">Summary</h2>
<p>The <code>:visited</code> CSS <a href="/en/CSS/Pseudo-classes" title="Pseudo-classes">pseudo-class</a> lets you select only links that have been visited. This style may be overridden by any other link-related pseudo-classes, that is {{ cssxref(":link") }}, {{ cssxref(":hover") }}, and {{ cssxref(":active") }}, appearing in subsequent rules. In order to style appropriately links, you need to put the <code>:visited</code> rule after the <code>:link</code> rule but before the other ones, defined in the <em>LVHA-order</em>: <code>:link</code> — <code>:visited</code> — <code>:hover</code> — <code>:active</code>.</p>
<div class="note style-wrap">
  <p><strong>Note: </strong>For privacy reasons, browsers strictly limit the styles you can apply using an element selected by this pseudo-class: only {{ cssxref("color") }}, {{ cssxref("background-color") }}, {{ cssxref("border-color") }}, {{ cssxref("border-bottom-color") }}, {{ cssxref("border-left-color") }}, {{ cssxref("border-right-color") }}, {{ cssxref("border-top-color") }}, {{ cssxref("outline-color") }}, {{ cssxref("column-rule-color") }}, <code>fill</code> and <code>stroke</code>. Note also that the alpha component will be ignored: the alpha component of the not-visited rule is used instead (except when the opacity is <code>0</code>, in that case the whole color is ignored, and the one of the not-visited rule is used.</p>
  <p>Though the color can be changed, the method <code>getComputedStyle</code> will lie and always give back the value of the non-visited color.</p>
  <p>For more information on the limitations and the motivation for them, see {{ Cssxref("Privacy and the :visited selector") }}.</p>
</div>
<h2 id="Examples">Examples</h2>
<pre class="brush: css">
a:visited { color: #4b2f89; }
a:visited { background-color:&nbsp;white } </pre>
<h2 id="Specifications">Specifications</h2>
<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>{{ SpecName('CSS3 Selectors', '#link', ':visited') }}</td>
      <td>{{ Spec2('CSS3 Selectors') }}</td>
      <td>No change.</td>
    </tr>
    <tr>
      <td>{{ SpecName('CSS2.1', 'selector.html#link-pseudo-classes', ':visited') }}</td>
      <td>{{ Spec2('CSS2.1') }}</td>
      <td>Lift the restriction to only apply it for {{ HTMLElement("a") }} element. Let users restricts its behavior for privacy reasons.</td>
    </tr>
    <tr>
      <td>{{ SpecName('CSS1', '#anchor-pseudo-classes', ':visited') }}</td>
      <td>{{ Spec2('CSS1') }}</td>
      <td>Initial definition.</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 (WebKit)</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>1.0</td>
        <td>{{ CompatGeckoDesktop("1.0") }}</td>
        <td>3.5</td>
        <td>3.5</td>
        <td>1.0</td>
      </tr>
      <tr>
        <td>Restrictions in CSS properties allowed in a statement using <code>:visited</code></td>
        <td>6</td>
        <td>{{CompatGeckoDesktop("2.0") }}</td>
        <td>8 (or earlier)</td>
        <td>{{ CompatUnknown() }}</td>
        <td>5.0</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 Phone</th>
        <th>Opera Mobile</th>
        <th>Safari Mobile</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>{{ CompatUnknown() }}</td>
        <td>{{ CompatGeckoMobile("1.0") }}</td>
        <td>{{ CompatUnknown() }}</td>
        <td>{{ CompatUnknown() }}</td>
        <td>{{ CompatUnknown() }}</td>
      </tr>
    </tbody>
  </table>
</div>
<h2 id="See_also">See also</h2>
<ul>
  <li>{{ Cssxref("Privacy and the :visited selector") }}</li>
  <li>{{ Cssxref(":link") }}</li>
</ul>
Revert to this revision