<a> tag is used to create hyperlinks.a:link, a:visited, a:hover, a:active (LVHA).First, create a simple HTML link, then style it with CSS:
/* Basic HTML link + CSS selector */
<a href="https://www.example.com">Visit Example</a>
a {
color: blue;
text-decoration: underline;
}
The selector a targets all links on the page. You can then use pseudo-classes like a:hover to style a link when the mouse hovers over it.
Links have four common interactive states that you can style using CSS pseudo-classes:
a:link – normal, unvisited link.a:visited – link that has already been opened.a:hover – when the user moves the mouse over the link.a:active – the moment the link is clicked.
/* Styling all four common link states */
a:link {
background-color: lightblue;
color: blue;
}
a:visited {
background-color: lightgreen;
color: darkgreen;
}
a:hover {
background-color: yellow;
color: orange;
}
a:active {
background-color: red;
color: white;
}
You can make a link look like a button by adding padding, background color, border-radius, and removing the underline. Hover and active states can give it a clickable, interactive feel.
/* Make a link look like a primary button */
.button-link:link,
.button-link:visited {
display: inline-block;
padding: 10px 18px;
background-color: #2563eb;
color: #ffffff;
text-decoration: none;
border-radius: 6px;
font-weight: 600;
}
.button-link:hover {
background-color: #1d4ed8;
transform: scale(1.03);
}
.button-link:active {
background-color: #1e40af;
transform: scale(0.98);
}
You can use your own color palette by setting different colors for each state. This helps match your website theme and improve visual hierarchy.
/* Custom color palette for link states */
a:link {
color: #007bff;
}
a:visited {
color: #5c5c5c;
}
a:hover {
color: #ff6347;
}
a:active {
color: #003366;
}
Hover and click on the links below to imagine how different states would look:
In a real project, the CSS you wrote for .button-link or a:hover would control the visual changes when users hover or click these links.
a:hover and a:active for better feedback.a:link, a:hover, and a:active.