
CSS Topics
- CSS Intro
- CSS How To
- CSS Editors
- CSS Properties
- CSS Selectors
- .class
- .class1.class2
- .class1 .class2
- #id
- * (all)
- element
- element.class
- element,element
- element element
- element>element
- element+element
- element1~element2
- [attribute]
- [attribute=value]
- [attribute~=value]
- [attribute|=value]
- [attribute^=value]
- [attribute$=value]
- [attribute*=value]
- :active
- ::after
- ::before
- :checked
- :default
- :disabled
- :empty
- :enabled
- :first-child
- ::first-letter
- ::first-line
- :first-of-type
- :focus
- :fullscreen
- :has()
- :hover
- :in-range
- :indeterminate
- :invalid
- :lang()
- :last-child
- :last-of-type
- :link
- ::marker
- :not()
- :nth-child()
- :nth-last-child()
- :nth-last-of-type()
- :nth-of-type()
- :only-of-type
- :only-child
- :optional
- :out-of-range
- ::placeholder
- :read-only
- :read-write
- :required
- :root
- ::selection
- :target
- :valid
- :visited
- CSS Comments
- CSS Length
- CSS Image Sprites
- CSS Grid Layout
- CSS Grid Flexbox
- CSS @charset Rule
- CSS @font-face Rule
- CSS @import Rule
- CSS @keyframes Rule
- CSS @media Rule
CSS :link Selector
Photo Credit to CodeToFun
🙋 Introduction
The CSS :link selector is used to target unvisited links on a webpage. It allows you to style hyperlinks that have not been clicked yet, helping differentiate between visited and unvisited links.
This is useful for enhancing user experience by visually guiding users through available links on your site.
💡 Syntax
The signature of the :link Selector is as follows:
a:link {
/* CSS properties */
}The :link pseudo-class only applies to anchor (<a>) elements that have an href attribute and are in their unvisited state.
📝 Example
Here is a simple example of how to use the :link selector in CSS:
☠️ HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS :link Selector Example</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>Welcome to My Website</h1>
<p>
Visit the following links:
<a href="https://www.example.com">Example</a><br>
<a href="https://www.anotherexample.com">Another Example</a>
</p>
</body>
</html>🎨 CSS
/* Style for unvisited links */
a:link {
color: blue;
text-decoration: none;
font-weight: bold;
}
/* Style for visited links */
a:visited {
color: purple;
text-decoration: underline;
}In this example:
- Unvisited links (
:link) are displayed in blue, with no underline and bold text. - Once a link is clicked, the
:visitedstate changes its color to purple and underlines the text.
💬 Usage Tips
- Always pair the
:linkpseudo-class with the:visitedpseudo-class to ensure a clear distinction between visited and unvisited links. - It's common to style links using the following order to avoid conflicts:
- :link
- :visited
- :hover
- :active
This order ensures that styles are applied consistently and according to CSS cascading rules.
⚠️ Common Pitfalls
- The
:linkselector only applies to links that have anhrefattribute. If you omit thehrefor use a link without it, the:linkpseudo-class won't work. - If you apply the same styles to both
:linkand:visited, users might not notice a difference between clicked and unclicked links. Always provide a distinct style for:visitedlinks for better user experience.
🎉 Conclusion
The CSS :link selector is a handy tool for styling hyperlinks that have not been clicked. It allows for customization of unvisited links, enhancing the visual clarity and navigation of a webpage. By pairing it with other link-related pseudo-classes like :visited, you can create a consistent and engaging design for your website's links.
👨💻 Join our Community:
Author

For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.
Buy me a coffee to make codetofun.com free for everyone.
Buy me a Coffee












If you have any doubts regarding this article (CSS :link Selector), please comment here. I will help you immediately.