XML technologies / CSS / CSS Cookbook / Typography for the web / Drop capitals at the start of a paragraph

(Excerpt from “CSS Kochbuch” by Christopher Schmitt)

Problem

A paragraph should begin with a drop capital. The term drop capitals refers to especially large letters at the start of a paragraph, several points larger than the remaining text or often several lines high.

Solution

Place the paragraph in a p element:

<p>Online, 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>

Now use the pseudo-element :first-letter to give the paragraph’s first letter a special style (see the following figure):

p:first-letter {
 font-size: 1.2em;
 background-color: black;
 color: white;
}

A simple drop capital

Figure: A simple drop capital.

Discussion

The CSS specification’s pseudo-element :first-letter provides an easy way to turn a paragraph’s first letter into a drop capital. :first-letter is now supported by most modern browsers, such as Internet Explorer 6 for Windows, Firefox, Safari and Opera. For other browsers, the following approach may help:

Enclose the first letter of the paragraph’s first sentence in a span element containing a class attribute:

<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>

You can now define a custom style for the first letter:

p .initcap {
 font-size: 1.2em;
 background-color: black;
 color: white;
}

See also

The CSS 2.1 specification for the :first-letter pseudo-element.

  

 

 

 

back to top