XML technologies / CSS / CSS Cookbook / Lists / Defining hanging indents for lists

(Excerpt from “CSS Kochbuch” by Christopher Schmitt)

Problem

The first line of a list item should start further left than the rest, creating a so-called hanging indent (see the following figure).

Hanging indents in a list

Figure: Hanging indents in a list.

Solution

Use the property text-indent with a negative value:

ul {
 width: 30%;
 padding: 0 0 0.75em 0;
 margin: 0;
 list-style: none;
}
li {
 text-indent: -1.75em;
 margin: 0.33em 0.5em 0.5em 1.5em;
}

Discussion

List markers—whether numbers, images or text—help draw attention to a list, but sometimes you want to omit these design elements and use hanging indents instead.

This solution indents the list by 3/4 em, producing a visible but unobtrusive hanging indent. Increasing the value text-indent or the list item’s font size makes the effect more prominent.

See also

The recipe Indenting entire paragraphs on defining paragraph indents, and the CSS 2.1 specification for the property text-indent.

  

 

 

 

back to top