Back to CSS Notes
Topic #224

Styling Links

You will style links so they are readable, interactive, and accessible by controlling color, decoration, and state pseudo-classes.

What it is

Styling links means applying CSS to anchor elements and their states. A link is usually an <a> element with an href. CSS can change its appearance when it is unvisited, visited, hovered, focused, or active. The common mental model is: style the base link first, then add state rules for interaction.

Related terms include pseudo-classes such as :link, :visited, :hover, :focus, :focus-visible, and :active. Text decoration controls underlines, overlines, line-through, and thickness.

Why it matters

  • Users need to recognize links quickly.
  • Hover and focus feedback shows that an element is interactive.
  • Good contrast helps people with low vision or color blindness.
  • Consistent link styling supports navigation and forms.
  • Accessible focus styles are required for keyboard users.

Syntax or steps

  1. Select the link element with a or a class such as .nav-link.
  2. Set base properties such as color, text-decoration, and font-weight.
  3. Add state rules using pseudo-classes.
  4. Keep visited styling limited because browsers restrict some properties for privacy.
  5. Test with mouse, keyboard, and screen reader.

Example

/* Base link */
a {
  color: #185FA5;
  text-decoration: none;
  font-weight: 500;
}

/* Visited links */
a:visited {
  color: #5A3E85;
}

/* Hover feedback */
a:hover {
  color: #0B3D66;
  text-decoration: underline;
}

/* Keyboard focus */
a:focus-visible {
  outline: 2px solid #185FA5;
  outline-offset: 2px;
}

/* Active feedback */
a:active {
  color: #072A47;
}

Part-by-part explanation:

  • a styles every link. The base color is blue, and the underline is removed for a cleaner look.
  • a:visited changes the color of links the user has already visited.
  • a:hover adds an underline and darkens the color when the pointer is over the link.
  • a:focus-visible shows an outline only when the browser determines focus should be visible, usually for keyboard navigation.
  • a:active changes the color while the link is being clicked.

Common mistakes

  • Removing focus outlines with outline: none without replacing them. Fix: provide a visible :focus-visible style.
  • Using only color to show a link. Fix: keep underlines or add icons, bold text, or other visual cues.
  • Writing state rules in the wrong order. Fix: use the order :link, :visited, :hover, :focus, :active when needed.
  • Expecting :visited to change many properties. Fix: limit visited styling to safe properties such as color.

When to use it

Use link state pseudo-classes for normal navigation links. Use classes when you need different link styles in different areas, such as buttons, cards, or menus.

Approach Best for Example
Element selector Site-wide default links a { color: blue; }
Class selector Special link styles .button-link { ... }
Pseudo-class Interaction states a:hover { ... }

Practice

Guided exercise: Create a link that is dark blue, has no underline, becomes underlined on hover, and shows a visible focus outline.

a {
  color: #185FA5;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

a:focus-visible {
  outline: 2px solid #185FA5;
  outline-offset: 2px;
}

Challenge: Add a visited color and an active color without breaking keyboard focus. Hint: place :visited after the base rule and keep :focus-visible visible.

Quick check

Question: Which pseudo-class should you use to style a link when a keyboard user tabs to it?

Answer: Use :focus-visible for modern browsers, or :focus if you need broader support and are careful not to remove the outline.

Summary

Styling links is about combining a clear base appearance with state feedback. Use color, decoration, and focus styles together so links are easy to see, easy to use, and accessible to everyone.

Want to go beyond the notes?

Join Coding Now Tech Institute's CSS course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Styling Links – FAQs

Quick answers about learning Styling Links in CSS.

This free note from Coding Now Tech Institute explains Styling Links in CSS — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every CSS topic on Coding Now Tech Institute, including Styling Links, is 100% free with no signup required.
With focused practice, most students grasp Styling Links in 1–3 days from these notes; pairing it with Coding Now Tech Institute's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the Coding Now Tech Institute Community (/community) — expert instructors answer within 24 hours.
Call NowEnroll Now