XML technologies / CSS / CSS Cookbook / Typography for the web / Indenting the first line of a paragraph

(Excerpt from “CSS Kochbuch” by Christopher Schmitt)

Problem

You want to indent the first line of each paragraph, turning the paragraphs in the next figure into those in the figure after it.

Default paragraph display

Figure: Default paragraph display.

The first line of each paragraph has been indented

Figure: The first line of each paragraph has been indented.

Solution

Use the property text-indent to create the indentation:

p {
 text-indent: 2.5em;
 margin: 0 0 0.5em 0;
 padding: 0;
}

Discussion

The property text-indent accepts absolute and relative length units as well as percentages. Percentages refer to the parent element’s width, rather than the entire page width. Thus, for a 200-pixel-wide paragraph, a 35% indentation means an offset of 70 pixels.

See also

The CSS 2.1 specification for more information on the property text-indent.

  

 

 

 

back to top