SA-21/06, C-11, Asapur, Varanasi, UP support@kamaldnp.com +91 8318013442
CSS
1. CSS Tutorial for Beginners — Learn CSS from Scratch 2. CSS Syntax Explained — Selectors, Properties & Values 3. CSS Selectors Tutorial — Class, ID, Attribute & More 4. How to Add CSS to HTML — Inline, Internal, External 5. CSS Colors Tutorial — HEX, RGB, RGBA, HSL Explained 6. CSS Backgrounds Tutorial — Images, Size & Position 7. CSS Borders Tutorial — Style, Width, Radius & Shadow 8. CSS Margin Explained — Shorthand, Auto & Collapse 9. CSS Padding Explained — Shorthand & Margin Difference 10. CSS Height and Width — px, %, em, rem, vw, vh Units 11. CSS Box Model Explained — Content, Padding, Border 12. CSS Text Styling Tutorial — Color, Align & Spacing 13. CSS Fonts Tutorial — font-family, Sizes & Google Fonts 14. CSS Link Styling — Hover, Visited, Active & Buttons 15. CSS Lists Styling — Markers, Counters & Shorthand 16. CSS Tables Styling — Zebra Stripes & Hover Rows 17. CSS Display Property — Block, Inline, None Explained 18. CSS Position Explained — Relative, Absolute, Fixed 19. CSS Overflow Explained — Hidden, Scroll, Auto & More 20. CSS Float and Clear — Layouts & Clearfix Trick 21. CSS Pseudo-classes — Hover, Focus, nth-child & More 22. CSS Pseudo-elements — ::before, ::after & ::first-line 23. CSS Form Styling — Inputs, Labels & Buttons Tutorial 24. CSS Navigation Bar Tutorial — Dropdown Menu Included 25. CSS Website Layout Tutorial — Header, Sidebar, Footer 26. CSS Flexbox Tutorial — Complete Guide with Examples 27. CSS Grid Tutorial — Columns, Rows & Layouts Guide 28. CSS Responsive Design — Media Queries Tutorial 29. CSS Transitions & Animations — No JavaScript Needed 30. CSS Variables Tutorial — :root, var() & Theming 31. CSS Transforms Explained — Rotate, Scale, Translate 32. CSS Filters Tutorial — Blur, Grayscale, Sepia & More 33. CSS Text Effects — Shadows, Wrapping & Overflow 34. CSS Keyframes Tutorial — Bouncing Ball Animation 35. CSS Grid Template Areas — Layout in Words, Not Numbers
Final Test — Certificate ₹10
Try this code live
Lesson 14 of 35

CSS Link Styling — Hover, Visited, Active & Buttons

3 min read · Free · No login needed

A link is not one thing — it is four. A link you have never clicked looks one way, a link you have visited looks another, and a link changes again while your mouse is over it and while you are pressing it. CSS gives each of these moments its own selector, called a pseudo-class.

Diagram — see how it fits together
Diagram: CSS Links

The four link states

  • a:link — a normal, unvisited link.
  • a:visited — a link the visitor has already opened.
  • a:hover — the mouse is over the link.
  • a:active — the link is being clicked right now.

The order matters: always write them link, visited, hover, active. A handy way to remember it is "LoVe HAte" — Link, Visited, Hover, Active. If hover comes before visited, the visited colour wins and the hover effect never shows.

Styling links

Links start blue and underlined. Change them with the same properties you already know: color, text-decoration, background-color and font-weight. Removing the underline is common — text-decoration: none; — but then the link needs another clue, like a colour or a hover background, or visitors will not know it is clickable.

Syntax — links in action

a:link {
  color: #2563eb;
  text-decoration: none;
}
a:visited {
  color: #7c3aed;
}
a:hover {
  color: #ea580c;
  text-decoration: underline;
}
a:active {
  color: #dc2626;
}

Link buttons

A link can look like a button: give it padding, a background colour and rounded corners. The trick is display: inline-block; — without it, top and bottom padding on a link does not push anything around.

.btn:link, .btn:visited {
  display: inline-block;
  background: #16a34a;
  color: white;
  padding: 10px 20px;
  border-radius: 6px;
  text-decoration: none;
}
.btn:hover {
  background: #15803d;
}
Note: Browsers limit what :visited can change, for privacy — only colour-related properties like color and background-color work. A visited link cannot change its padding or font size.
Tip: Always style :hover and :focus together. Keyboard users never hover — they tab to a link, and :focus is their version of hover.

Common mistakes

  • Writing the four states in the wrong order — hover must come after link and visited, or it will not show.
  • Removing the underline from links without adding another clue — visitors cannot tell what is clickable.
  • Forgetting display: inline-block; on a link button — the padding then paints but does not push other elements away.
  • Styling only a and wondering why visited links look different — the browser's default visited colour (purple) still applies.

Remember

  • Four states, in this order: link, visited, hover, active — "LoVe HAte".
  • :hover is for the mouse; :focus is for the keyboard. Style both.
  • text-decoration: none; removes the underline.
  • A link button needs display: inline-block; for its padding to work.
  • :visited can only change colours, for privacy.

Example explained

  • a:link { color: #2563eb; text-decoration: none; } — unvisited links are blue with no underline, so the menu looks clean.
  • a:visited { color: #7c3aed; } — a page you have already opened turns purple, so you can see where you have been.
  • a:hover { color: #ea580c; text-decoration: underline; } — when the mouse rests on a link, it turns orange and the underline comes back, telling you it is clickable.
  • .btn:link, .btn:visited { display: inline-block; background: #16a34a; } — the "Join Now" link gets a green button look, and inline-block makes its padding work properly.
  • .btn:hover { background: #15803d; } — the button turns a darker green on hover, like a real button being pressed.

Example

Example
<!DOCTYPE html>
<html>
<head>
<title>Links - Course Menu</title>
<style>
a:link { color: #2563eb; text-decoration: none; }
a:visited { color: #7c3aed; }
a:hover { color: #ea580c; text-decoration: underline; }
a:active { color: #dc2626; }
.btn:link, .btn:visited { display: inline-block; background: #16a34a; color: white; padding: 10px 20px; border-radius: 6px; text-decoration: none; }
.btn:hover { background: #15803d; }
</style>
</head>
<body>

<h1>Our Courses</h1>
<p><a href="#">HTML Course</a> | <a href="#">CSS Course</a> | <a href="#">JavaScript Course</a></p>
<p><a class="btn" href="#">Join Now</a></p>

</body>
</html>

Output

Output — how it looks in the browser
Output of CSS Link Styling — Hover, Visited, Active & Buttons

Try it yourself — live editor

Change the code below and press Run to see the result instantly. No file to save, no login needed.

Result

Frequently asked questions

The questions learners ask most about this lesson — read the question, then open it to see the answer.

1. What are the four link states in order?

link, visited, hover, active — remembered as LoVe HAte. Writing them in the wrong order breaks hover.

2. What is the difference between :hover and :focus?

:hover is for the mouse; :focus is for the keyboard. Style both so keyboard users can see where they are.

3. Why does a link button need display: inline-block?

So its padding works properly. Without it, the padding paints but does not push other elements away.

Why learn this yourself — and not just ask AI?

AI can write code for you, but it cannot think for you. When you learn HTML yourself, your brain builds the real skill: you understand why a page looks the way it does, you can fix it when it breaks, and you can answer it in an exam or an interview without help. That is the skill that gets you a job — not a copied answer.

Get certified — just ₹10

Finish all 35 lessons, pass the test (80%), pay ₹10 and get your certificate.

Take the test

Prefer watching? Video courses teach the same topics step by step.

Go further with a full course

Free tutorials teach you the basics. Our paid courses add live projects, mentorship and a certificate.

Android & iOS App Development using Flutter 2026
₹5,000
View
WordPress Website Development Course (10 Days)
₹399
View
Website Design & Development Workshop 2026
₹299
View
Browse all courses
CSS — Lessons
1. CSS Tutorial for Beginners — Learn CSS from Scratch 2. CSS Syntax Explained — Selectors, Properties & Values 3. CSS Selectors Tutorial — Class, ID, Attribute & More 4. How to Add CSS to HTML — Inline, Internal, External 5. CSS Colors Tutorial — HEX, RGB, RGBA, HSL Explained 6. CSS Backgrounds Tutorial — Images, Size & Position 7. CSS Borders Tutorial — Style, Width, Radius & Shadow 8. CSS Margin Explained — Shorthand, Auto & Collapse 9. CSS Padding Explained — Shorthand & Margin Difference 10. CSS Height and Width — px, %, em, rem, vw, vh Units 11. CSS Box Model Explained — Content, Padding, Border 12. CSS Text Styling Tutorial — Color, Align & Spacing 13. CSS Fonts Tutorial — font-family, Sizes & Google Fonts 14. CSS Link Styling — Hover, Visited, Active & Buttons 15. CSS Lists Styling — Markers, Counters & Shorthand 16. CSS Tables Styling — Zebra Stripes & Hover Rows 17. CSS Display Property — Block, Inline, None Explained 18. CSS Position Explained — Relative, Absolute, Fixed 19. CSS Overflow Explained — Hidden, Scroll, Auto & More 20. CSS Float and Clear — Layouts & Clearfix Trick 21. CSS Pseudo-classes — Hover, Focus, nth-child & More 22. CSS Pseudo-elements — ::before, ::after & ::first-line 23. CSS Form Styling — Inputs, Labels & Buttons Tutorial 24. CSS Navigation Bar Tutorial — Dropdown Menu Included 25. CSS Website Layout Tutorial — Header, Sidebar, Footer 26. CSS Flexbox Tutorial — Complete Guide with Examples 27. CSS Grid Tutorial — Columns, Rows & Layouts Guide 28. CSS Responsive Design — Media Queries Tutorial 29. CSS Transitions & Animations — No JavaScript Needed 30. CSS Variables Tutorial — :root, var() & Theming 31. CSS Transforms Explained — Rotate, Scale, Translate 32. CSS Filters Tutorial — Blur, Grayscale, Sepia & More 33. CSS Text Effects — Shadows, Wrapping & Overflow 34. CSS Keyframes Tutorial — Bouncing Ball Animation 35. CSS Grid Template Areas — Layout in Words, Not Numbers
Final Test — Certificate ₹10

🤖 KAMALDNP AI Assistant

Ask about courses, website & more

Hi! I'm KAMALDNP AI Assistant. Ask me about our courses, website features, or anything else! 😊
Please wait 5s...
🤖 KAMALDNP Assistant ✕

Request human callback:

🔐 Login Required
✕

Please log in to download. You will stay on this page after logging in!

New here? Register now →