CSS Reference ยท Pseudo-classes
The :any-link pseudo-class
Reference for the CSS :any-link pseudo-class: match every hyperlink with an href, visited or not, with syntax, examples, usage notes and browser support.
The :any-link pseudo-class matches every hyperlink that has an href, whether or not it has been visited. It is shorthand for :is(:link, :visited).
Use it for styles that should apply to links as a group, like a pointer cursor or an underline, without touching <a> elements that are only placeholders.
:any-link { text-decoration-thickness: 2px; }
Try it
Syntax
:any-link { /* declarations */ }
No arguments; specificity (0,1,0), equal to a single :link or :visited.
Syntax and arguments
| Part | Description |
|---|---|
:any-link |
Matches a and area elements that have an href, in either visited or unvisited state. |
| No arguments | The pseudo-class is not functional. |
| Equivalent | :is(:link, :visited) |
Usage notes
- Shared styles first. Put common link styling on
:any-link, then override colours in:linkand:visited. - Compared with
a[href]. The attribute selector has the same effect for HTML anchors but is a different mechanism;:any-linkalso expresses intent and works for other link-capable elements in other languages. - It keeps privacy rules. Since it includes visited links, only colour properties may differ between states;
:any-linkitself does not add any new freedom. - Hover and focus. Chain other states onto it, for example
:any-link:hoveror:any-link:focus-visible. - Does not match placeholders. An
<a>withouthref, used for example as a JavaScript hook, is ignored.
Browser support
Supported in all current browsers and Baseline widely available. Very old browsers used a prefixed form.
Related
:linkโ unvisited links:visitedโ visited links:focus-visibleโ keyboard focus indicator- Lesson: Pseudo-classes