How to Change the Color of Link on Hover using CSS ? Last Updated : 20 Mar, 2024 Comments Improve Suggest changes Like Article Like Report Changing the color of a link on hover can provide visual feedback to users, indicating that the link is interactive. It improves the user experience by helping users understand that the link is clickable. These are the following approaches: Table of Content Using CSS pseudo-classUsing CSS VariablesUsing Inline CSSUsing CSS pseudo-classCSS provides the: hover pseudo-class which allows us to specify styles that should apply when the mouse is over an element, such as a link (<a> tag). Syntax:selector:hover { /* styles to apply on hover */}Example: The below code uses: hover pseudo-class to change the Color of the Link on Hovers. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Change Link Color on Hover</title> <link rel="stylesheet" href="styles.css"> </head> <body> <div class="container"> <h1>GeeksForGeeks</h1> <h2>Changing Link color on Hovers using pseudo-class</h2> <a href="#">Machine Learning</a><br> <a href="#">Data Science</a><br> <a href="#">Blockchain</a> </div> </body> </html> CSS /* styles.css */ .container { text-align: center; } h1 { color: green; } a { color: blue; text-decoration: none; } a:hover { color: green; text-decoration: underline; } Output: Using CSS VariablesIn this approach, we're using CSS variables to define the default color of the link and the color it should change to on hover. Example: The below example uses CSS variables to define a link of color. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="styles.css"> </head> <body> <div class="container"> <h1>GeeksForGeeks</h1> <h3>Changing link color Using CSS Variables</h3> <a href="#" class="custom-link">Hover over me</a> </div> </body> </html> CSS .container { text-align: center; } h1 { color: green; } :root { --default-color: blue; --hover-color: red; } .custom-link { color: var(--default-color); text-decoration: none; } .custom-link:hover { color: var(--hover-color); } Output: Using Inline CSSThis approach uses inline CSS and HTML event attributes to change the color of a link on hover. Example: The below example shows how we can add inline CSS to change the link color on hover. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Link Color Change on Hover</title> </head> <body> <div class="container" style="text-align: center;"> <h1 style="color: green;">GeeksForGeeks</h1> <h3>Changing link color Using inline CSS</h3> <a href="#" onmouseover="this.style.color='green'" onmouseout="this.style.color='blue'" style="color: blue;">Visit GeeksForGeeks </a> </div> </body> </html> Output: Comment More infoAdvertise with us Next Article How to Change the Color of Link on Hover using CSS ? G ghuleyogesh Follow Improve Article Tags : Web Technologies CSS CSS-Questions Similar Reads How to Change the Border Color on Hover in CSS ? Border color in CSS defines the color of an elementâs border. You can change the border color on hover using the :hover pseudo-class, allowing you to modify the borderâs appearance when a user hovers over the element. Using CSS hover Pseudo ClassThe hover pseudo-class in CSS is a powerful tool that 1 min read How to Change the Item Color of List on Hover ? In CSS, we can customize the interaction with the list element by changing the color of the list item on hover. We can also apply the different colors to each item using the :hover pseudo class in CSS. Approach: Using the :hover Pseudo-classIn this approach, we are using the :hover pseudo-class in C 2 min read How to Change the Color of Bullets using CSS? Changing the color of bullets using CSS means styling the bullet points in a list (<ul> or <ol>) to have a different color than the text. This can be done using pseudo-elements or setting the color property on the list item, enhancing design consistency.1. Adding An Extra MarkupBy adding 2 min read How to change the underline color in CSS? In this article, we are going to learn how to change the underline color in CSS, To change the underline color in CSS, use the text-decoration-color property. Set it to the desired color value. Styling is implemented in HTML text to make it catchy and attractive. The text can be made italic, underli 1 min read How To Change Color Of SVG On Hover? SVG stands for Scalable Vector Graphics which is an XML form approach to create graphical elements using the code format of XML, that is, Extensive Markup Language. We can use CSS elements to add colors to svg, or change its properties and even add pseudo-class effects to it. In this article, we wil 7 min read How to Change Image Opacity on Hover using CSS ? Changing the opacity of an image on hover can add a more elegant and interactive effect to your website. This simple yet effective technique can be implemented using CSS. When a user hovers over an image, it gradually becomes more transparent, pointing out the interaction and creating an attractive 2 min read How to change the color of selected text using CSS ? The colour of selected text can be easily changed by using the CSS | ::selection Selector. In the below code, we have used CSS ::selection on <h1> and <p> element and set its colour as yellow with green background. Below example implements the above approach: Example: html <!DOCTYPE h 1 min read How to Change Cursor Color using CSS? Changing the cursor color using CSS is an easy way to make your website look nicer. While you can't change the mouse cursor itself, you can change the color of the text cursor (the blinking line) in input fields. This helps make the text areas stand out and match your website's style.Approach to cha 3 min read How to change the color of horizontal line (<hr> element) using CSS ? The HTML <hr> tag is used to insert a horizontal rule or a thematic break in an HTML page to divide or separate document sections. The color of the <hr> tag can be set by using the background-color property in CSS.Example 1: In this example, the CSS within the <style> section custo 1 min read How To Change The Cursor On Hovering In CSS? Changing the cursor style when a user hovers over a particular element is a common user experience enhancement in web development. The default cursor is usually a pointer (arrow) but CSS allows us to change the cursor to various shapes such as a hand (for links), text selection, or even custom icons 2 min read Like