The HTML anchor element (a
) is used to create links. The text between the opening and closing anchor tag is the link description, and the URL set in the href
attribute is the address the browser visits when the link is clicked.
link
: A link that a user hasn’t clicked or visitedvisited
: A link that a user has clicked or visitedhover
: A link that the user hovers the mouse cursor over without clickingactive
: A link the user has begun to click but hasn’t yet released the mouse button
Property Name | Possible Values | Description | |
color |
name
|
Link color specified using names (color: blue; ), hexadecimal code (color: #0000FF; ), or RGB value (color: rgb(0,0,255); ). |
|
text-decoration |
none
|
Sets link to have an underline (or not). |
a:link{
color: rgb(6,69,173);
text-decoration: none;
}
a:visited {
color: rgb(11,0,128)
}
a:hover {
text-decoration: underline
}
a:active {
color: rgb(250,167,0)
}
Remember to include the colon between the a
selector and the link state.
Although explaining why is beyond the scope of this book, CSS specifications insist that you define the various link states in the order shown here — link, visited, hover, and then active. However, it is acceptable to not define a link state, as long as this order is preserved.
The various link states are known as pseudo-class selectors. Pseudo-class selectors add a keyword to CSS selectors and allow you to style a special state of the selected element.