- HTML Links — Different Colors
- HTML Link Colors
- Example
- Link Buttons
- Example
- HTML Link Tags
- How to Change Link Colors with CSS
- Inline method
- Example of changing a link color with the inline method:
- Result
- Internal method
- Example of changing the link color with the internal method:
- Example of using different link states:
- How to change the colors of the hyperlink underline and anchor text
- Example of changing a hyperlink underline and anchor text color:
- Example of styling links with the mentioned methods:
- Example of changing the link color with the «inherit» value of the color property:
- Example of styling links with the CSS text-decoration-color property:
- External method
- CSS Links
- Styling Links
- Example
- Example
- Text Decoration
- Example
- Background Color
- Example
- Link Buttons
- Example
- More Examples
- Example
- Example
- Example
- COLOR PICKER
- Report Error
- Thank You For Helping Us!
- How to Change the HTML Link Color?
- Different Types of Hyperlinks in HTML
- How to Change Link Color in HTML ?
- Example 1: Using HTML Style Attribute
- Example 2: Using HTML Body Tag
- Example 3: Using CSS
- See Also
- Conclusion
HTML Links — Different Colors
An HTML link is displayed in a different color depending on whether it has been visited, is unvisited, or is active.
HTML Link Colors
By default, a link will appear like this (in all browsers):
- An unvisited link is underlined and blue
- A visited link is underlined and purple
- An active link is underlined and red
You can change the link state colors, by using CSS:
Example
Here, an unvisited link will be green with no underline. A visited link will be pink with no underline. An active link will be yellow and underlined. In addition, when mousing over a link (a:hover) it will become red and underlined:
a:visited color: pink;
background-color: transparent;
text-decoration: none;
>
a:hover color: red;
background-color: transparent;
text-decoration: underline;
>
a:active color: yellow;
background-color: transparent;
text-decoration: underline;
>
Link Buttons
A link can also be styled as a button, by using CSS:
Example
To learn more about CSS, go to our CSS Tutorial.
HTML Link Tags
For a complete list of all available HTML tags, visit our HTML Tag Reference.
How to Change Link Colors with CSS
There are three ways of changing the link color: inline, internal and external.
Inline method
Add the style attribute directly to the hyperlink code and specify the color property through the style attribute, then give a color value to it.
Example of changing a link color with the inline method:
html> html> head> title>Title of the document title> head> body> p>Visit our a href="https://www.w3docs.com/" style="color: #8ebf42">website a>. p> body> html>
Result
Internal method
Example of changing the link color with the internal method:
html> html> head> title>Title of the document title> style> a < color: #8ebf42; > style> head> body> p>Visit our a href="https://www.w3docs.com/">website a>. p> body> html>
There are 4 link states that links can be styled depending on what state they are in:
- a:link — a normal, unvisited link,
- a:visited — a link the user has visited,
- a:hover — a link when a user mouses over it,
- a:active — the moment a link is clicked.
When setting the style for several link states, follow these rules:
Example of using different link states:
html> html> head> title>Title of the document title> style> /* unvisited link */ a:link < color: #ccc; > /* visited link */ a:visited < color: #095484; > /* mouse over link */ a:hover < color: #8ebf42; > /* selected link */ a:active < color: #800000; > style> head> body> p>Visit our a href="https://www.w3docs.com/">website a>. p> body> html>
How to change the colors of the hyperlink underline and anchor text
To change the underline color, first of all, you need to remove it with the «none» value of the text-decoration property and set the «none» value, then add the border-bottom property with the width (in this case, used as a hyperlink underline width) and border-style (solid, dotted, or dashed) properties. For the anchor text color, use the color property.
Example of changing a hyperlink underline and anchor text color:
html> html> head> title>Title of the document title> style> a < text-decoration: none; > a:link < color: #000; border-bottom: 1px solid #ff0000; > a:visited < color: #e600e6; border-bottom: 1px solid #b3b3b3; > a:hover < color: #2d8653; border-bottom: 1px solid #000099; > style> head> body> p>Visit our a href="https://www.w3docs.com/">website a>. p> body> html>
Example of styling links with the mentioned methods:
html> html> head> title>Title of the document title> style> a.one:link < color: #ccc; > a.one:visited < color: #095484; > a.one:hover < color: #8ebf42; > a.two:link < color: #ccc; > a.two:visited < color: #095484; > a.two:hover < font-size: 150%; > a.three:link < color: #ccc; > a.three:visited < color: #095484; > a.three:hover < background: #8ebf42; > a.four:link < color: #ccc; > a.four:visited < color: #095484; > a.four:hover < font-family: monospace; > a.five:link < color: #095484; text-decoration: none; > a.five:visited < color: #095484; text-decoration: none; > a.five:hover < text-decoration: overline underline; > style> head> body> p>Mouse over the links and watch how they will be changed: p> p> a class="one" href="#">This link changes color a> p> p> a class="two" href="#">This link changes font-size a> p> p> a class="three" href="#">This link changes background-color a> p> p> a class="four" href="#">This link changes font-family a> p> p> a class="five" href="#">This link changes text-decoration a> p> body> html>
Now, we’ll demonstrate another example, where we use the color property with its «inherit» value. This will make the element take the color of its parent.
Example of changing the link color with the «inherit» value of the color property:
html> html> head> title>Title of the document title> style> p < color: green; > p a < color: inherit; > style> head> body> h1>Example h1> a href="https://www.w3docs.com/">W3docs.com a> p>Visit our a href="https://www.w3docs.com/">W3docs.com a> website. p> body> html>
Example of styling links with the CSS text-decoration-color property:
html> html> head> title>Title of the document title> style> a < text-decoration-color: grey; > a:link < color: #777777; > a:hover < color: #2d8653; > style> head> body> p>Visit our a href="https://www.w3docs.com/">website a>. p> body> html>
External method
Using external stylesheets you can take control of all the hyperlinks of your site. With external stylesheets, many attractive hyperlink effects can be created to develop the look of your website.
With the external method, you’ll link your web pages to an external .css file that can be created by any text editor in your device. This is a more efficient method, especially when you need to style a large website. You can change your whole site at once by editing one .css file.
CSS Links
With CSS, links can be styled in many different ways.
Styling Links
Links can be styled with any CSS property (e.g. color , font-family , background , etc.).
Example
In addition, links can be styled differently depending on what state they are in.
The four links states are:
- a:link — a normal, unvisited link
- a:visited — a link the user has visited
- a:hover — a link when the user mouses over it
- a:active — a link the moment it is clicked
Example
/* unvisited link */
a:link color: red;
>
/* visited link */
a:visited color: green;
>
/* mouse over link */
a:hover color: hotpink;
>
/* selected link */
a:active color: blue;
>
When setting the style for several link states, there are some order rules:
Text Decoration
The text-decoration property is mostly used to remove underlines from links:
Example
a:visited text-decoration: none;
>
a:hover text-decoration: underline;
>
a:active text-decoration: underline;
>
Background Color
The background-color property can be used to specify a background color for links:
Example
a:link <
background-color: yellow;
>
a:visited background-color: cyan;
>
a:hover background-color: lightgreen;
>
a:active background-color: hotpink;
>
Link Buttons
This example demonstrates a more advanced example where we combine several CSS properties to display links as boxes/buttons:
Example
a:link, a:visited <
background-color: #f44336;
color: white;
padding: 14px 25px;
text-align: center;
text-decoration: none;
display: inline-block;
>
a:hover, a:active background-color: red;
>
More Examples
Example
This example demonstrates how to add other styles to hyperlinks:
Example
Another example of how to create link boxes/buttons:
a:link, a:visited <
background-color: white;
color: black;
border: 2px solid green;
padding: 10px 20px;
text-align: center;
text-decoration: none;
display: inline-block;
>
a:hover, a:active background-color: green;
color: white;
>
Example
This example demonstrates the different types of cursors (can be useful for links):
COLOR PICKER
Report Error
If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:
Thank You For Helping Us!
Your message has been sent to W3Schools.
Top Tutorials
Top References
Top Examples
Get Certified
W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.
How to Change the HTML Link Color?
HTML Links are connections that help to switch between two resources over the web. HTML links or hyperlinks allow users to navigate from one location to another. Besides, links bookmark a portion of the page, navigate to internal parts of the website, download files, etc.
The HTML links have default colors assigned that can be altered using HTML and CSS. However, in this case, it is advised to prefer CSS over HTML, as the primary purpose of CSS is styling the webpage.
Different Types of Hyperlinks in HTML
The different types of HTML links are :
The links have different HTML link colors assigned to them that indicate their state of interactiveness. A hyperlink is underlined by default.
The different hyperlink states are as follows :
- Unvisited link :
A blue hyperlink implies that the linked destination, has not been viewed by the user. - Visited link :
A purple hyperlink indicates that the user has already seen the linked page. - Active Link :
In this state color of the link turns red on being clicked. This indicates that releasing the mouse button will lead the user to the linked location. - Hover link :
The state when the mouse pointer is hovering over a link has the same color as in the Active and Visited links.
Note :
Though the link states have default HTML link colors, the users can change the colors as per requirements.
How to Change Link Color in HTML ?
Example 1: Using HTML Style Attribute
The following steps will guide you to modify the color for a link using HTML.
Note :
The default color for a link state can be changed using HTML tags and attributes. The style attribute can override any style set using HTML tag or an external style sheet.
Note :
The following CSS code is used only for styling purposes.
Output
Example 2: Using HTML Body Tag
The following attributes of the HTML tags help in defining the link colors according to their state.
- LINK sets the default color of an unvisited link.
- VLINK sets the color for a visited link.
- ALINK sets the color that should appear when a link is in an active state (when the link is clicked).
Note :
HTML5 does not support the link attribute in the body tag.
The following steps will guide you to set the color to the hyperlink states using HTML tag.
- Step — 1
In the initial step, set the HTML values for the link, alink, and vlink attributes in the body tag. - Step — 2
Next, add an anchor tag with the destination link. - Step — 3
Rerun the file to see if changes take place.
Example 3: Using CSS
The following example sets new colors to the hyperlink states using CSS.
- Step — 1
In the initial step, set the HTML link color for the anchor tag, which implies all the states have the mentioned color. - Step — 2
Next, set the desired HTML link color values for the active, visited, and hover states. - Step — 3
Rerun the file to see if changes take place.
Note: Since no additional change is made to the unvisited state, the color remains at the initially set value.
See Also
Conclusion
- HTML links connect two resources over the web.
- The default appearance of the different types of links are :
- Unvisited link — Blue
- Visited link — Purple
- Active link — Red