Flash cards
Review the key moves
What is the main idea behind CSS Links?
Lesson checks
Practice each idea before moving on
Short Mimo-style checks built from this lesson's code, terms, and sequence.
Which statement best captures the main point of this lesson?
Complete the missing token from the example code.
___: hotpink;Put the learning moves in the order that makes the concept easiest to apply.
CSS Styling 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;
}Live preview
Styling Links Depending on State
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;
}Live preview
CSS Links - Text Decoration
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;
}Live preview
CSS Links - Background Color
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;
}Live preview