HTML Link Colors 🎯

beginner
16 min

HTML Link Colors 🎯

Welcome to our comprehensive guide on HTML Link Colors! In this tutorial, we'll explore everything you need to know about link colors in HTML, from the basics to advanced techniques. Let's dive right in! 🚀

Understanding Link Colors 📝

HTML links come in three distinct states:

  1. Unvisited: The link has not been clicked yet.
  2. Visited: The link has been clicked and taken to the linked page.
  3. Hover: The link is being hovered over by the mouse cursor.

Each of these states can have a different color, and we'll show you how to customize them! 💡

Default Link Colors 📝

Before we get started, let's take a look at the default link colors in HTML:

  • Unvisited: Blue (#0000FF)
  • Visited: Purple (#800080)
  • Hover: Dark Blue (#0000CC)

Now, let's learn how to change these colors! 🎨

Changing Link Colors 💡

To change link colors, we'll use HTML's built-in <a> tag along with CSS (Cascading Style Sheets). Here's a simple example:

html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>HTML Link Colors</title> <style> a { color: red; /* Unvisited, Visited, and Hover links will be red */ } a:hover { color: green; /* Only the Hover links will be green */ } </style> </head> <body> <a href="https://www.google.com">Google</a> </body> </html>

In this example, we set the color of all links to red and also specified a separate color for the hover state. ✅

Customizing Individual Link States 💡

If you want to customize the colors for each link state individually, you can use the following CSS selectors:

  • a:link for unvisited links
  • a:visited for visited links
  • a:hover for hover links

Here's an example:

html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>HTML Link Colors</title> <style> a:link { color: red; } /* Unvisited links will be red */ a:visited { color: purple; } /* Visited links will be purple */ a:hover { color: green; } /* Hover links will be green */ </style> </head> <body> <a href="https://www.google.com">Google</a> </body> </html>

In this example, we've customized the colors for each link state. ✅

Quiz 💡

Quick Quiz
Question 1 of 1

What is the default color for visited links in HTML?

Styling Links in Real Projects 💡

In real-world projects, you might want to maintain a consistent color scheme. For that, consider using a CSS variable (CSS custom property) to store a specific color. Here's an example:

html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>HTML Link Colors</title> <style> :root { --main-color: red; } a { color: var(--main-color); } </style> </head> <body> <a href="https://www.google.com">Google</a> </body> </html>

In this example, we defined a CSS variable named --main-color and used it to color all links. ✅

That's it for our HTML Link Colors tutorial! We hope you've enjoyed learning and can now customize link colors in your own projects. Happy coding! 🎉