In some cases, authors may want user agents to render content
that does not come from the document
tree. One familiar example of this is a numbered list; the author
does not want to list the numbers explicitly, he or she wants the
user agent to generate them automatically. Similarly, authors
may want the user agent to insert the word
"Figure" before the caption of a figure, or "Chapter 7" before the
seventh chapter title. For audio or braille in particular, user agents
should be able to insert these strings.

In CSS 2.1, content may be generated by two mechanisms:

The 'content'
property, in conjunction with the :before and :after pseudo-elements.

Authors specify the style and location of generated content with
the :before and :after pseudo-elements. As their names indicate, the
:before and :after pseudo-elements specify the location of content
before and after an element's document
tree content. The 'content'
property, in conjunction with these pseudo-elements, specifies what is
inserted.

Example(s):

For example, the following rule inserts the string "Note: "
before the content of
every P element whose "class" attribute has the value "note":

would cause a solid green border to be rendered around the entire
paragraph, including the initial string.

The :before and :after pseudo-elements inherit any inheritable properties
from the element in the document tree to which they are attached.

Example(s):

For example, the following rules insert an open quote mark before every
Q element. The color of the quote mark will be red, but the font will
be the same as the font of the rest of the Q element:

q:before {
content: open-quote;
color: red
}

In a :before or :after pseudo-element declaration, non-inherited
properties take their initial
values.

Example(s):

So, for example, because the initial value of the 'display' property is 'inline', the
quote in the previous example is inserted as an inline box (i.e.,
on the same line as the element's initial text content).
The next example explicitly sets the
'display' property to
'block', so that the inserted text becomes a block:

Counters may be specified
with two different functions: 'counter()' or 'counters()'.
The former has two forms:
'counter(name)' or 'counter(name,
style)'.
The generated text is the value of the named
counter at this point in the formatting structure; it
is formatted in the indicated
style ('decimal' by default).
The latter function also has two forms:
'counters(name, string)' or 'counters(name,
string, style)'. The generated text is the value of all
counters with the given name at this point in the formatting structure,
separated by the specified string. The counters are rendered
in the indicated style ('decimal' by default).
See the section on automatic counters and
numbering for more information.

This function returns as a string the value of attribute X
for the subject of the selector. The
string is not parsed by the CSS processor. If the subject of the selector
doesn't have an attribute X, an empty string is returned. The
case-sensitivity of attribute names depends on the document language.
Note. In CSS 2.1, it is not possible to refer to
attribute values for other elements than the subject of the selector.

The 'display' property
controls whether the content is placed in a block, inline, or marker
box.

Example(s):

The following rule causes the string "Chapter: " to be generated before each H1 element:

H1:before {
content: "Chapter: ";
display: inline;
}

Authors may include newlines in the generated content by writing
the "\A" escape sequence in one of the strings after the 'content' property. This inserted line
break is still subject to the 'white-space' property. See "Strings" and "Characters and case" for
more information on the "\A" escape sequence.

In CSS 2.1, authors may specify, in a style-sensitive and
context-dependent manner, how user agents should render quotation
marks. The 'quotes' property
specifies pairs of quotation marks for each level of embedded
quotation. The 'content'
property gives access to those quotation marks and causes them to be
inserted before and after a quotation.

Values for the 'open-quote' and 'close-quote' values of the
'content' property are taken
from this list of pairs of quotation marks (opening and
closing). The first (leftmost) pair represents the outermost level of
quotation, the second pair the first level of embedding, etc. The user
agent must apply the appropriate pair of quotation marks according to
the level of embedding.

Note.
While the quotation marks specified by 'quotes' in the previous examples are
conveniently located on computer keyboards, high quality typesetting
would require different ISO 10646 characters. The following
informative table lists some of the ISO 10646 quotation
mark characters:

Quotation marks are inserted in appropriate places in a document
with the 'open-quote'
and 'close-quote' values of the
'content' property. Each
occurrence of 'open-quote' or 'close-quote' is replaced by one of the
strings from the value of 'quotes', based on the depth of
nesting.

'Open-quote' refers to the first of a pair of quotes, 'close-quote'
refers to the second. Which pair of quotes is used depends on the
nesting level of quotes: the number of occurrences of 'open-quote' in
all generated text before the current occurrence, minus the number of
occurrences of 'close-quote'. If the depth is 0, the first pair is
used, if the depth is 1, the second pair is used, etc. If the depth is
greater than the number of pairs, the last pair is repeated. A
'close-quote' that would make the depth negative is in error and is
ignored (at rendering time): the depth stays at 0 and no quote mark is
rendered (although the rest of the 'content' property's value is still
inserted).

Note. The quoting depth is independent of the nesting
of the source document or the formatting structure.

Some typographic styles require open quotation marks to be repeated
before every paragraph of a quote spanning several paragraphs, but
only the last paragraph ends with a closing quotation mark. In CSS,
this can be achieved by inserting "phantom" closing quotes. The
keyword 'no-close-quote' decrements
the quoting level, but does not insert a quotation mark.

Example(s):

The following style sheet puts opening quotation marks on every
paragraph in a BLOCKQUOTE, and inserts a single closing quote at the
end:

Automatic numbering in CSS2 is controlled with two properties,
'counter-increment'
and 'counter-reset'. The
counters defined by these properties are used with the counter() and
counters() functions of the the 'content' property.

The 'counter-increment' property
accepts one or more names of counters (identifiers), each one
optionally followed by an integer. The integer indicates by how much the
counter is incremented for every occurrence of the element. The
default increment is 1. Zero and negative integers are allowed.

The 'counter-reset'
property also contains a list of one or more names of counters, each
one optionally followed by an integer. The integer gives the value that
the counter is set to on each occurrence of the element. The default
is 0.

Counters are "self-nesting", in the sense that re-using a counter
in a child element automatically creates a new instance of the
counter. This is important for situations like lists in HTML, where
elements can be nested inside themselves to arbitrary depth. It would
be impossible to define uniquely named counters for each level.

Example(s):

Thus, the following suffices to number nested list items. The
result is very similar to that of setting 'display:list-item' and
'list-style: inside' on the LI element:

The self-nesting is based on the principle that every element that
has a 'counter-reset' for
a counter X, creates a fresh counter X, the scope of which is the element, its
following siblings, and all the descendants of the element and its
following siblings.

In the example above, an OL will create a counter, and all children
of the OL will refer to that counter.

If we denote by item[n] the
nth instance of the "item"
counter, and by "(" and ")" the beginning and end of a
scope, then the following HTML fragment will use the indicated
counters. (We assume the style sheet as given in the example above).

CSS 2.1 offers basic visual formatting of lists. An element with
'display: list-item' generates a principal box for the element's
content and an optional marker box as a visual indication that the
element is a list item.

The list
properties describe basic visual formatting of lists:
they allow style sheets to specify the marker type (image, glyph, or
number), and the marker position with respect to the principal box
(outside it or within it before content). They do not allow authors to
specify distinct style (colors, fonts, alignment, etc.) for the list
marker or adjust its position with respect to the principal box, these
may be derived from the principal box.

This property specifies appearance of the list item marker if
'list-style-image' has
the value 'none' or if the image pointed to by the URI cannot be
displayed. The value 'none' specifies no marker, otherwise there are
three types of marker: glyphs, numbering systems, and alphabetic
systems.

Glyphs are specified with
disc,
circle, and
square. Their exact
rendering depends on the user agent.

This specification does not define how alphabetic systems wrap at
the end of the alphabet. For instance, after 26 list items,
'lower-latin' rendering is undefined. Therefore, for long lists, we
recommend that authors specify true numbers.

For example, the following HTML document:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<HTML>
<HEAD>
<TITLE>Lowercase latin numbering</TITLE>
<STYLE type="text/css">
ol { list-style-type: lower-roman }
</STYLE>
</HEAD>
<BODY>
<OL>
<LI> This is the first item.
<LI> This is the second item.
<LI> This is the third item.
</OL>
</BODY>
</HTML>

might produce something like this:

i This is the first item.
ii This is the second item.
iii This is the third item.

The list marker alignment (here, right justified) depends on the user agent.

Although authors may specify 'list-style' information directly
on list item elements (e.g., "li" in HTML), they should do so with
care. The following rules look similar, but the first declares a descendant selector
and the second a (more specific) child
selector.

The desired rendering would have level 1 list items with
'lower-alpha' labels and level 2 items with 'disc' labels. However,
the cascading order will
cause the first style rule (which includes specific class information)
to mask the second. The following rules solve the problem by employing
a child
selector instead:

ol.alpha > li { list-style: lower-alpha }
ul li { list-style: disc }

Another solution would be to specify 'list-style' information only on
the list type elements:

ol.alpha { list-style: lower-alpha }
ul { list-style: disc }

Inheritance will transfer the 'list-style' values from OL and
UL elements to LI elements. This is the recommended way to
specify list style information.

Example(s):

A URI value may be combined with any other value, as in:

ul { list-style: url("http://png.com/ellipse.png") disc }

In the example above, the 'disc' will be used when the image is
unavailable.