1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
---
title: ':link'
slug: 'Web/CSS/:link'
tags:
- CSS
- Layout
- Pseudo-class
- Reference
- Selector
- Web
translation_of: 'Web/CSS/:link'
---
<div>{{ CSSRef }}</div>
<p>The <strong><code>:link</code></strong> <a href="/en-US/docs/Web/CSS">CSS</a> <a href="/en-US/docs/Web/CSS/Pseudo-classes">pseudo-class</a> represents an element that has not yet been visited. It matches every unvisited {{HTMLElement("a")}}, {{HTMLElement("area")}}, or {{HTMLElement("link")}} element that has an <code>href</code> attribute.</p>
<pre class="brush: css no-line-numbers notranslate">/* Selects any <a> that has not been visited yet */
a:link {
color: red;
}</pre>
<p>Styles defined by the <code>:link</code> pseudo-class will be overridden by any subsequent link-related pseudo-class ({{cssxref(":active")}}, {{cssxref(":hover")}}, or {{cssxref(":visited")}}) that has at least equal specificity. To style links appropriately, put the <code>:link</code> rule before all other 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">
<p><strong>Note:</strong> Use {{cssxref(":any-link")}} to select an element independent of whether it has been visited or not.</p>
</div>
<h2 id="Syntax">Syntax</h2>
<pre class="syntaxbox notranslate">{{csssyntax}}</pre>
<h2 id="Examples">Examples</h2>
<p>By default, most browsers apply a special {{cssxref("color")}} value to visited links. Thus, the links in this example will probably have special font colors only before you visit them. (After that, you'll need to clear your browser history to see them again.) However, the {{cssxref("background-color")}} values are likely to remain, as most browsers do not set that property on visited links by default.</p>
<h3 id="HTML">HTML</h3>
<pre class="brush: html notranslate"><a href="#ordinary-target">This is an ordinary link.</a><br>
<a href="">You've already visited this link.</a><br>
<a>Placeholder link (won't get styled)</a>
</pre>
<h3 id="CSS">CSS</h3>
<pre class="brush: css notranslate">a:link {
background-color: gold;
color: green;
}
</pre>
<h3 id="Result">Result</h3>
<p>{{EmbedLiveSample("Examples")}}</p>
<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>{{ SpecName('HTML WHATWG', 'scripting.html#selector-link', ':link') }}</td>
<td>{{ Spec2('HTML WHATWG') }}</td>
<td></td>
</tr>
<tr>
<td>{{ SpecName('CSS4 Selectors', '#link', ':link') }}</td>
<td>{{ Spec2('CSS4 Selectors') }}</td>
<td>No change.</td>
</tr>
<tr>
<td>{{ SpecName('CSS3 Selectors', '#link', ':link') }}</td>
<td>{{ Spec2('CSS3 Selectors') }}</td>
<td>No change.</td>
</tr>
<tr>
<td>{{ SpecName('CSS2.1', 'selector.html#link-pseudo-classes', ':link') }}</td>
<td>{{ Spec2('CSS2.1') }}</td>
<td>Lift the restriction to only apply it for {{ HTMLElement("a") }} element.</td>
</tr>
<tr>
<td>{{ SpecName('CSS1', '#anchor-pseudo-classes', ':link') }}</td>
<td>{{ Spec2('CSS1') }}</td>
<td>Initial definition.</td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility" name="Browser_compatibility">Browser compatibility</h2>
<div>
<p>{{Compat("css.selectors.link")}}</p>
</div>
<h2 id="See_also">See also</h2>
<ul>
<li>Link-related pseudo-classes: {{ cssxref(":visited") }}, {{ cssxref(":hover") }}, {{ cssxref(":active") }}</li>
</ul>
|