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:

<A href="somepage.html" style="color: #00a000">Visit Somepage</A>
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:

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

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

Back to the FAQ main page

  Copyright © 1996 - 2000 Rob Schlüter,   (last updated 1999/03/01)