XML technologies / CSS / CSS Cookbook / Links and navigation / Removing standard link underlines and adding other decorations

(Excerpt from “CSS Kochbuch” by Christopher Schmitt)

Problem

Links are underlined by default. You want to remove these underlines, as shown in the following figure.

Links without underlines

Figure: Links without underlines.

Solution

Use the property text-decoration together with the pseudo-class based selector for visited and unvisited links:

a:link, a:visited {
 text-decoration: none;
}

Discussion

The pseudo-classes :link and :visited let you style links in a document. The pseudo-class :link selects unvisited links, while :visited represents visited links. The property text-decoration accepts five values (see the following table).

Table: Available values for text-decoration.

Values for text-decoration

Result

underline

Draws a line below the text (underline).

overline

Draws a line above the text (overline).

blink

Makes text blink.

line-through

Strikes through text.

none

Applies no additional text decoration.

The property text-decoration is often used to improve page presentation. Rather than underlining every link, designers often set text-decoration to the value none and also change the link’s background or text color, or both:

a:link, a:visited {
 text-decoration: none;
 background-color: red;
 color: white;
}

To accommodate visitors who may be colorblind and unable to identify links by color alone, some designers also make link text bold:

a:link, a:visited {
 font-weight: bold;
 text-decoration: none;
 color: red;
}

The value line-through can also indicate a visited link, displayed like a checked-off agenda item (see the following figure):

a:link {
 font-weight: bold;
 text-decoration: none;
 color: red;
}
a:visited {
 font-weight: bold;
 text-decoration: line-through;
 color: black;
}

Links displayed with strikethrough

Figure: Links displayed with strikethrough.

See also

The CSS 2.1 specification on the property text-decoration and Jakob Neilsen’s “Design Guidelines for Visualizing Links”.

  

 

 

 

back to top