🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to CSS Notes
Topic #57

CSS Links


HTML links can be styled with many CSS properties, like color, text-decoration, background-color, font-size, font-weight, font-family, etc.).

Example

a {

  color: hotpink;

  background-color: yellow;

  font-weight: bold;

}

In addition, links can be styled differently depending on what state they are in.

The four link states are:

  • :link - a normal, unvisited link
  • :visited - a link the user has visited
  • :hover - a link when the user mouses over it
  • :active - a link the moment it is clicked

When setting the style for link states, there are some order rules:

  • :hover must come after :link and :visited
  • :active must come after :hover

Example

/* unvisited link */
a:link {
  color: red;
}

/* visited
link */
a:visited {
  color: green;
}

/* mouse over link */

a:hover {
  color: hotpink;
}

/* selected link */
a:active {

color: blue;
}

The text-decoration property is mostly used to remove underlines from links:

Example

a:link {
  text-decoration: none;
}

a:visited {
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

a:active {
  text-decoration: underline;
}

The background-color property can be used to specify a background color for links:

Example

a:link {
  background-color: yellow;
}

a:visited {
  background-color: cyan;
}

a:hover {
  background-color: lightgreen;
}

a:active {
  background-color: hotpink;
}

More Examples

Example

  a.one:link {color:red;}
a.one:visited {color:blue;}
a.one:hover
  {color:orange;}

a.two:link {color:red;}
a.two:visited {color:blue;}

  a.two:hover {font-size:150%;}

a.three:link {color:red;}

  a.three:visited {color:blue;}
a.three:hover {background:lightgreen;}

a.four:link {color:red;}
a.four:visited {color:blue;}
a.four:hover
  {font-family:monospace;}

a.five:link {color:red;text-decoration:none;}

  a.five:visited {color:blue;text-decoration:none;}
a.five:hover
  {text-decoration:underline;}

Example

  <span style="cursor: auto">auto</span><br>
<span style="cursor:
  crosshair">crosshair</span><br>
<span style="cursor:
  default">default</span><br>
<span style="cursor: e-resize">e-resize</span><br>

  <span style="cursor: help">help</span><br>
<span style="cursor:
  move">move</span><br>
<span style="cursor: n-resize">n-resize</span><br>

  <span style="cursor: ne-resize">ne-resize</span><br>
<span style="cursor:
  nw-resize">nw-resize</span><br>
<span style="cursor:
  pointer">pointer</span><br>
<span style="cursor: progress">progress</span><br>

  <span style="cursor: s-resize">s-resize</span><br>
<span style="cursor:
  se-resize">se-resize</span><br>
<span style="cursor: sw-resize">sw-resize</span><br>

  <span style="cursor: text">text</span><br>
<span style="cursor:
  w-resize">w-resize</span><br>
<span style="cursor: wait">wait</span>

Want to go beyond the notes?

Join CodingNow 2.0's CSS course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

CSS Links – FAQs

Quick answers about learning CSS Links in CSS.

This free note from CodingNow 2.0 explains CSS Links in CSS — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every CSS topic on CodingNow 2.0, including CSS Links, is 100% free with no signup required.
With focused practice, most students grasp CSS Links in 1–3 days from these notes; pairing it with CodingNow 2.0'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 CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now