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).
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;
}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;
}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
The CSS 2.1 specification on
letter-spacingand onword-spacing,more information on tracking and kerning at about.com: Kerning and Tracking and
information in German about typography at Typografie.info.
Copyright of the German edition © 2007 by O’Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from “CSS Kochbuch” is subject to the same conditions as the bound edition: the work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
O’Reilly Verlag GmbH & Co. KG, Balthasarstr. 81, 50670 Köln