bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/CSS/CSS Foundations
CSS•CSS Foundations

CSS Links

Flash cards

Review the key moves

1/4
Core idea

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.

1Quick choice

Which statement best captures the main point of this lesson?

2Fill blank

Complete the missing token from the example code.

___: hotpink;
3Order

Put the learning moves in the order that makes the concept easiest to apply.

CSS Links - Background Color
CSS Links - Text Decoration
Styling Links Depending on State

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

Formatted code
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

Formatted code
/* 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

Formatted code
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

Formatted code
a:link {
  background-color: yellow;
}
a:visited {
  background-color: cyan;
}
a:hover {
  background-color: lightgreen;
}
a:active {
  background-color: hotpink;
}

Live preview

Previous

CSS Icons - Google

Next

CSS Link Buttons