XML technologies / CSS / CSS Cookbook / Typography for the web / Larger, centered initial capitals

(Excerpt from “CSS Kochbuch” by Christopher Schmitt)

Problem

A large initial capital should be placed in the middle of the paragraph.

Solution

Wrap the first letter of the first sentence in the paragraph in an element span with an attribute class:

<p><span class="initcap">O</span>nline, activity of exchanging ideas is sped up. The distribution of messages from the selling of propaganda to the giving away of disinformation takes place at a blindingly fast pace thanks to the state of technology &hellip;</p>

In addition to styling the first letter using the tag span and the class selector, define further rules specifying the paragraph’s indentation (see the following figure):

p {
 text-indent: 37%;
 line-height: 1em;
}
p span.initcap {
 font-size: 6em;
 line-height: 0.7em;
 font-weight: bold;
}

A larger initial capital, centered

Figure: A larger initial capital, centered.

Discussion

This solution relies on the interaction of three CSS properties. The first property is text-indent, which moves the first line toward the middle of the paragraph. Here the value is 37%. This is slightly more than a third of the total width (see the following figure), but is not enough to truly “center” the initial capital.

The indented text

Figure: The indented text.

The next property that helps us with this task is font-size. Setting the font size to 6em makes the initial capital six times (or 600%) larger than the browser’s default font size (see the following figure).

Initial capital six times larger than the normal font size

Figure: An initial capital six times larger than the normal font size.

Because the font size is six times larger than the remaining text, the first line also has greater leading than the other lines. To correct this, set the line height for the element span to 0.6em.

Centering the initial capital works in this recipe provided that the character’s width equals 26% of the paragraph’s width. If your initial capital or paragraph has a different width than in this recipe, you may need to adjust the values in the CSS rules to center the initial capital.

See also

  

 

 

 

back to top