In CSS, you can style links (<a> tags) to change their appearance based on different states such as normal, hovered, active, and visited.
Basic link states
1. Normal (a): The default state of the link.
a {
color: green; /* you can put any color value */
}
2. Visited (a:visited): When the link has been visited.
a:visited {
color: purple;
}
3. Hover (a:hover): When the mouse is over the link.
a:hover {
color: red;
}
4. Active (a:active): When the link is being clicked.
a:active {
color: yellow;
}
Text Decorations Property
text-decoration: none
a {
color: green; /* you can put any color value */
text-decoration: none;
}
a:visited {
color: purple;
text-decoration: none;
}
a:hover {
color: red;
text-decoration: none;
}
a:active {
color: yellow;
text-decoration: none;
}
text-decoration: underline
a {
color: green;
text-decoration: underline;
}
a:visited {
color: purple;
text-decoration: underline;
}
a:hover {
color: red;
text-decoration: underline;
}
a:active {
color: yellow;
text-decoration: underline;
}
Background color Property
a {
color: green;
background-color: LightBlue;
}
a:visited {
color: purple;
background-color: LightBlue;
}
a:hover {
color: red;
background-color: LightBlue;
}
a:active {
color: yellow;
background-color: LightBlue;
}
CSS Links – Interview Questions
Q 1: How to style links in CSS?
Ans: Using anchor (a) selector.
Q 2: What are link states?
Ans: :link, :visited, :hover, :active.
Q 3: How to remove underline from links?
Ans: text-decoration: none;
Q 4: Can links be animated?
Ans: Yes, using CSS transitions.
Q 5: Correct order of link states?
Ans: LVHA – Link, Visited, Hover, Active.
CSS Links – Objective Questions (MCQs)
Q1. Which pseudo-class represents an unvisited link?
Q2. Which pseudo-class represents a visited link?
Q3. Which pseudo-class applies when the mouse is over a link?
Q4. Which property removes underline from a link?
Q5. Which CSS order is correct for link states?