XML technologies / CSS / CSS Cookbook / Typography for the web / Adjusting letter and word spacing

(Excerpt from “CSS Kochbuch” by Christopher Schmitt)

Problem

Adjust the horizontal spacing of letters and words ( tracking) in HTML text (see the following figure).

Default letter and word spacing in HTML text

Figure: Default letter and word spacing in HTML text.

Solution

Adjust letter spacing with the property letter-spacing (see the next figure):

h2 {
 font: bold italic 2em "Helvetica Nue", serif;
 margin: 0;
 padding: 0;
 letter-spacing: -0.1em;
}

Reduced letter spacing in the heading

Figure: Reduced letter spacing in the heading.

Adjust spacing between words in a line with the property word-spacing (see the next figure):

h2 {
 font: bold italic 2em "Helvetica Nue", serif;
 margin: 0;
 padding: 0;
 word-spacing: 0.33em;
}

Increased word spacing in the heading

Figure: Increased word spacing in the heading.

Discussion

Web typography is one of CSS’s greatest strengths. Designers once needed a frightening arsenal of nested elements b and single-pixel GIFs to make text attractive. CSS makes adjusting letter and word spacing in paragraphs straightforward.

Adjusting tracking for aesthetic reasons has a long graphic-design tradition. Two terms describe spacing changes in text: kerning (reducing spacing, also called kerning ) and spacing out (increasing spacing, also called letterspacing ). In practice, kerning is the most common.

The term kerning describes reducing the space between two letters for readability, for example between a capital T and the following lowercase i. Reducing tracking across several text blocks is also called tracking.

Relative rather than absolute lengths are generally considered best practice for letter-spacing and word-spacing because users can change browser font sizes. A fixed five-point gap may look good at 12 pixels, but remains five points even when text is greatly enlarged. At 72 pixels, five pixels of kerning is barely noticeable. With relative units such as em, kerning is calculated relative to the actual font size. A value of 1.5em therefore scales with the rest of the text.

The same applies to other text effects: keep text readable. If communicating with customers matters, subtle effects work better. Illegible text can annoy many people you want to reach.

The properties letter-spacing and word-spacing are supported by all modern browsers.

See also

  

 

 

 

back to top