Coloring Links with CSS: Mastering Stylish Hyperlinks

Andrew Jul 31, 2026

Enhancing the visual appeal and hierarchy of text on your webpage often involves manipulating the color and style of links. This can be achieved with CSS, providing a depth of control over the appearance of anchor tags. Let's delve into the art of coloring links with CSS.

🎨 CSS Colors & Backgrounds | Complete Beginner's Cheat Sheet
🎨 CSS Colors & Backgrounds | Complete Beginner's Cheat Sheet

Before we embark on the CSS journey, it's pivotal to understand the default behavior of links in HTML. Unvisited links appear in a specific color, usually blue, visited links in another, often purple, and active links in yet another, typically red. But what if you want to change these defaults to match your site's color scheme? CSS offers the solution.

the color code for all different types of computers and their names are shown in this chart
the color code for all different types of computers and their names are shown in this chart

Changing Link Colors

The :link, :visited, :hover, and :active pseudo-classes enable programmers to style links in different states:

the color scheme for this website is blue, green and white with an image of trees in
the color scheme for this website is blue, green and white with an image of trees in

  • :link - for unvisited links
  • :visited - for visited links
  • :hover - when the user hovers over the link (mouseover)
  • :active - when the link is being clicked (mousedown)

Styling Unvisited Links

Web development
Web development

To change the color of unvisited links, use the :link pseudo-class followed by the color property. For instance, to turn them green:

a:link { color: green; }

Styling Visited, Hover, and Active Link States

Css color mix in html divs tag
Css color mix in html divs tag

Similarly, you can style visited links, hovered links, and actively clicked links:

a:visited { color: purple; }
a:hover { color: yellow; }
a:active { color: red; }

Coloring Links with Background and Text

CSS bubble coloring button
CSS bubble coloring button

You're not limited to just changing the text color. You can modify the background color, font family, and font size as well. It lets you get creative, but remember, maintain accessibility and usability.

Changing the background color:

the different font styles and colors for each type of poster or print, including one that is
the different font styles and colors for each type of poster or print, including one that is
CSS Cheat Sheet for Beginners | Complete CSS properties & Syntax Guide
CSS Cheat Sheet for Beginners | Complete CSS properties & Syntax Guide
CSS accent-color | CSS tutorial
CSS accent-color | CSS tutorial
#CSS Animations Tips and Tricks
#CSS Animations Tips and Tricks
CSS Styling Explained for Beginners | CSS Cheat Sheet
CSS Styling Explained for Beginners | CSS Cheat Sheet
Simplify Your Color Palette With CSS Color-Mix()
Simplify Your Color Palette With CSS Color-Mix()
the words don't use purple are shown in white and red on a black background
the words don't use purple are shown in white and red on a black background
Rapid prototyping with CSS keyword colors
Rapid prototyping with CSS keyword colors
Mastering Background Color in CSS
Mastering Background Color in CSS

a:link { background-color: lightblue; }

Changing Font Family and Size

CSS allows you to change the font family and size:

a:link { font-family: Verdana; font-size: 20px; }

Inheriting Styles

You can also make the linked text inherit the style of the anchor. It's a handy feature if you want all the links to align with their surrounding text:

a:link { color: inherit; background-color: inherit; font-family: inherit; font-size: inherit; }