CSS links
Different links can have different styles.
Link styles
The style of a link can use any CSS property (such as color, font, background, etc.).
Links can have different styles depending on their state.
These four link states are:
- a:link - normal, unvisited link
- a:visited - link the user has visited
- a:hover - when the user's mouse is over the link
- a:active - the moment the link is clicked
Example
a
:link
{
color:
#000000
;
}
/*
Unvisited link
*/
a
:visited
{
color:
#00FF00
;
}
/*
Visited link
*/
a
:hover
{
color:
#FF00FF
;
}
/*
Mouse over link
*/
a
:active
{
color:
#0000FF
;
}
/*
Mouse click
*/
Try it »
When setting styles for several link states, there are also some ordering rules:
- a:hover must come after a:link and a:visited
- a:active must come after a:hover
Common link styles
Based on the example of link color changes above, see what state it is in.
Let's move on to link styles in some other common ways:
Text decoration
The text-decoration property is mainly used to remove the underline from links:
Example
a
:link
{
text-decoration:
none
;
}
a
:visited
{
text-decoration:
none
;
}
a
:hover
{
text-decoration:
underline
;
}
a
:active
{
text-decoration:
underline
;
}
Try it »
Background Color
The background color property specifies the link's background color:
Example
a
:link
{
background-color:
#B2FF99
;
}
a
:visited
{
background-color:
#FFFF85
;
}
a
:hover
{
background-color:
#FF704D
;
}
a
:active
{
background-color:
#FF704D
;
}
Try it »
More examples
Add different styles to hyperlinks
This example demonstrates how to add other styles to hyperlinks.
Advanced - Create a link box
This example demonstrates a more advanced case where we combine several CSS properties to display as a box.