How can I change the color of a link?

By default the color of a link is defined by the value of the LINK attribute in in the BODY tag. If this attribute is not supplied, a default color, set in the browser is used.
But sometimes you need a color for a link, different from the rest of the links on that page. For example when the link is in a colored table.

Because only one color can be set in the BODY tag, temporarily changing the color for links must be done in another way. You can do this with style sheets. This is the preferred method There are basically two ways to apply style sheet information to a HTML element. It can be specified inline, in the STYLE attribute of the tag:

Source
<A href="somepage.html" style="color: #00a000">Visit Somepage</A>
 
Result
Visit Somepage

Including the color inside the tag works ok if you only have one link that needs a different color. But if you have more links, then it is easier to create a separate class in a style sheet in the HEAD of the page, and refer to this class when needed.
Here's an example:

Source
<HEAD>
<STYLE type="text/css">
a.greenlink:link {color: #00a000;}
</STYLE>>
</HEAD>

<A href="somepage.html" class="greenlink">Visit Somepage</A>
 
Result
Visit Somepage

Back to the FAQ main page
Statistics

  Copyright © 1996 - 1999 Rob Schlüter,   schluter@knoware.nl   (last updated 1999/03/01)