XML technologies / CSS / CSS Cookbook / Typography for the web / Adding shadows to text

(Excerpt from “CSS Kochbuch” by Christopher Schmitt)

Problem

You want to add a shadow to heading text, as shown in the following figure.

HTML text with a drop shadow

Figure: HTML text with a drop shadow.

Solution

Use the property text-shadow to set the shadow’s colour and position.

h1 {
 font-size: 2.5em;
 font-family: Myriad, Helvetica, Arial, sans-serif;
 width: 66.6%;
 text-shadow: grey .15em .15em .15em;
 margin: 0 0 0.1em 0;
}

Discussion

The first value of the property text-shadow sets the shadow colour. Two values follow for the shadow’s offset from the HTML text. The first length specifies the offset on the x axis, and the second on the y axis. The fourth value of text-shadow sets the shadow’s blur radius. Higher values make the shadow blurrier.

The property text-shadow has not been part of the specification since CSS 2.1. Safari is the only known browser supporting it.

See also

More information on the property text-shadow is available in the CSS 2.0 specification.

  

 

 

 

back to top