-
Hajipur, Bihar, 844101
Links (<a>
tags) can be styled using CSS to improve their appearance in different states — like normal, hovered, visited, active, or focused.
Pseudo-class | Description |
---|---|
:link |
Unvisited link |
:visited |
Visited link |
:hover |
When mouse hovers over the link |
:active |
When link is being clicked |
:focus |
When the link is selected/focused via tab |
Important: Use this order for best practice:
:link
→:visited
→:hover
→:active
a {
color: blue;
text-decoration: none;
}
a:link {
color: green;
}
a:visited {
color: purple;
}
a:hover {
color: red;
text-decoration: underline;
}
a:active {
color: orange;
}
a {
text-decoration: none;
}
To add it back on hover:
a:hover {
text-decoration: underline;
}
a:hover {
background-color: yellow;
color: black;
}
a.button {
background-color: #007BFF;
color: white;
padding: 10px 20px;
text-decoration: none;
border-radius: 5px;
}
a.button:hover {
background-color: #0056b3;
}
Q1. Style unvisited links as green.
Q2. Set visited link color to purple.
Q3. Change link color to red on hover.
Q4. Remove underline from all links.
Q5. Add underline only on hover.
Q6. Set active link color to orange.
Q7. Style a link with background and padding like a button.
Q8. Make a link change color and background on hover.
Q9. Apply bold font to hovered links.
Q10. Make focused links show a dotted border.
Q1: Which pseudo-class targets unvisited links?
Q2: Which pseudo-class is used for hover effect?
Q3: What is the correct order to style link states?
Q4: Which property removes link underline?
Q5: What happens on a:active state?
Q6: Which property changes link color?
Q7: What does a:visited style?
Q8: How can you style a link like a button?
Q9: Which pseudo-class applies when tab key selects a link?
Q10: What will this do? a:hover { color: red; }