CSS Lists and Counters Module Level 3

Shortname: css-lists
Level: 3
Group: CSSWG
Status: ED
Work Status: Exploring
ED: http://dev.w3.org/csswg/css3-lists/
TR: http://www.w3.org/TR/css3-lists/
Editor: Tab Atkins, Google, http://xanthir.com/contact/
Former Editor: Ian Hickson, Google, ian@hixie.ch
Former Editor: Tantek Çelı̇k, Formerly of Microsoft, tantekc@microsoft.com
Previous Version: http://www.w3.org/TR/2011/WD-css3-lists-20110524/
!Issue Tracking: Bugzilla
!Contributors: Simon Montagu, AOL-TW/Netscape, smontagu@netscape.com
!Contributors: Daniel Yacob, yacob@geez.org
!Contributors: Christopher Hoess, choess@stwing.upenn.edu
!Contributors: Daniel Glazman, AOL-TW/Netscape, glazman@netscape.com
Abstract: This draft contains the features of CSS level 3 relating to list styling. It includes and extends the functionality of CSS level 2 [[!CSS21]]. The main extensions compared to level 2 are a pseudo-element representing the list marker, and a method for authors to define their own list-styles.

Introduction

This is an early-stage working draft. None of its contents should be considered suitable for implementation at this point. Please cross-check against CSS 2.1 before implementing anything in this specification. This specification defines the ''::marker'' pseudo-element, the ''list-item'' and ''inline-list-item'' 'display' values that generate markers, and several properties controlling the placement and styling of markers. It also defines counters, which are special numerical objects often used to generate the default contents of markers.

For instance, the following example illustrates how markers may be used to add parentheses around each numbered list item:
			<style>
			li::marker { content: "(" counter(list-item, lower-roman) ")"; }
			li { display: list-item; }
			</style>
			<ol>
				<li>This is the first item.</li>
				<li>This is the second item.</li>
				<li>This is the third item.</li>
			</ol>
		
It should produce something like this:
			  (i) This is the first item.
			 (ii) This is the second item.
			(iii) This is the third item.
		
Note: Note that this example is far more verbose than is usually needed in HTML, as the UA default style sheet takes care of most of the necessary styling.
With descendant selectors and child selectors, it's possible to specify different marker types depending on the depth of embedded lists.

A future release of this module will probably include ways to render tree lists.

Declaring a List Item

A list item is any element with its 'display' property set to ''list-item'' or ''inline-list-item''. List items generate ''::marker'' pseudo-elements; no other elements do. Additionally, list items automatically increment the special ''list-item'' counter. Unless the 'counter-increment' property manually specifies a different increment for the ''list-item'' counter, it must be incremented by 1 on every list item, at the same time that counters are normally incremented. (This has no effect on the values of the 'counter-*' properties.)
	Name: display
	New values: inline-list-item
	
The inline-list-item display value makes the element a list item, with the effects described above. Additionally, the ''outside'' value of 'list-style-position' computes to ''inside'' on this element. Otherwise, this display value is treated identically to ''display/inline''. Note: This display value is silly, and only necessary because we haven't yet defined 'display' to be split into subproperties. When that happens, "being a list item" will just be a property value that can apply to block, inline, and other elements.

Default Marker Contents: The 'list-style-image' and 'list-style-type' properties

The contents of a ''::marker'' pseudo-element can be generated automatically, rather than being specified explicitly with 'content'. The 'list-style-image' and 'list-style-type' properties control how these contents are generated.
	Name: list-style-image
	Value: <> | none
	Initial: none
	Applies to: list items
	Inherited: yes
	Percentages: n/a
	Media: visual
	Computed value: computed value fo the <>, or ''list-style-image/none''
	
The 'list-style-image' property specifies an image that will be used as the list marker's default contents. The values are defined as follows:
<image>
If the <image> is not an invalid image, the image is the default contents of the list item's marker. Otherwise, the default contents are given by 'list-style-type' instead.
none
The default contents of the of the list item's marker are given by 'list-style-type' instead.
The following example sets the marker at the beginning of each list item to be the image "ellipse.png".
li { list-style-image: url("http://www.example.com/ellipse.png") }
	Name: list-style-type
	Value: <> | <> | none
	Initial: disc
	Applies to: list items
	Inherited: yes
	Percentages: n/a
	Media: visual
	Computed value: specified value
	
When the value of 'list-style-image' is ''list-style-image/none'' or an invalid image, the 'list-style-type' property is used to construct the default contents of a list item's marker; otherwise, 'list-style-type' is ignored. The values are defined as follows:
<counter-style>
The list item's marker's default contents are that counter style. [[CSS-COUNTER-STYLES-3]]
<string>
The <> is used as the list item's marker's default contents.
none
The list item's marker's default contents are ''list-style-type/none''.

The following examples illustrate how to set markers to various values:

			ul { list-style-type: "★"; }
			/* Sets the marker to a "star" character */

			p.note {
				display: list-item;
				list-style-type: "Note: ";
				list-style-position: inside;
			}
			/* Gives note paragraphs a marker consisting of the string "Note: " */

			ol { list-style-type: upper-roman; }
			/* Sets all ordered lists to use the upper-roman counter-style
			   (defined in the Counter Styles specification [[CSS-COUNTER-STYLES]]) */

			ul { list-style-type: symbols(repeating '○' '●'); }
			/* Sets all unordered list items to alternate between empty and
			   filled circles for their markers. */

			ul { list-style-type: none; }
			/* Suppresses the marker entirely, unless list-style-image is specified
			   with a valid image, or the marker's contents are set explicitly via
			   the 'content' property. */
		

Marker Position: The 'list-style-position' property

	Name: list-style-position
	Value: inside | outside
	Initial: outside
	Applies to: list items
	Inherited: yes
	Percentages: n/a
	Media: visual
	Computed value: specified value (but see prose)
	
This property helps control the position of the ''::marker'' pseudo-element in the list item. The values are defined as follows:
inside
The ''::marker'' pseudo-element is an inline element placed immediately before where the ''::before'' pseudo-element would be placed in the list item.
outside
As ''inside'', plus the 'position' property on the marker computes to ''marker''. Additionally, the base directionality of the marker (used as an input to the bidi resolution algorithm) must be taken from the marker's marker positioning reference element. If the list item is ''display: inline-list-item'', this value computes to ''inside''.
Note: Note that a marker is only generated if the used value of the 'content' property for the ''::marker'' pseudo-element is not ''content/none''.
For example:
			<style>
				ul.compact { list-style: inside; }
				ul         { list-style: outside; }
			</style>
			<ul class=compact>
				<li>first "inside" list item comes first</li>
				<li>second "inside" list item comes first</li>
			</ul>
			<hr>
			<ul>
				<li>first "outside" list item comes first</li>
				<li>second "outside" list item comes first</li>
			</ul>
		
The above example may be formatted as:
			  * first "inside" list
			  item comes first
			  * second "inside" list
			  item comes second

			========================

			* first "outside" list
			  item comes first
			* second "outside" list
			  item comes second

The 'list-style' shorthand property

	Name: list-style
	Value: <<'list-style-type'>> || <<'list-style-position'>> || <<'list-style-image'>>
	Initial: see individual properties
	Applies to: list items
	Inherited: see individual properties
	Percentages: see individual properties
	Media: visual
	Computed value: see individual properties
	
The 'list-style' property is a shorthand notation for setting the three properties 'list-style-type', 'list-style-image', and 'list-style-position' at the same place in the style sheet.
For example:
			UL { list-style: upper-roman inside }  /* Any UL */
			UL UL { list-style: circle outside } /* Any UL child of a UL */
		
Using a value of none in the shorthand is potentially ambiguous, as none is a valid value for both 'list-style-image' and 'list-style-type'. To resolve this ambiguity, a value of none in the shorthand must be applied to whichever of the two properties aren't otherwise set by the shorthand.
			list-style: none disc;
			/* Sets the image to "none" and the type to "disc". */

			list-style: none url(bullet.png);
			/* Sets the image to "url(bullet.png)" and the type to "none". */

			list-style: none;
			/* Sets both image and type to "none". */

			list-style: none disc url(bullet.png);
			/* Syntax error */
		
Although authors may specify 'list-style' information directly on list item elements (e.g., li in HTML), they should do so with care. Consider the following rules:
			ol.alpha li { list-style: lower-alpha; }
			ul li       { list-style: disc; }
		
The above won't work as expected. If you nest a ul into an ol class=alpha, the first rule's specificity will make the ul’s list items use the lower-alpha style.
			ol.alpha > li { list-style: lower-alpha; }
			ul > li       { list-style: disc; }
		
These work as intended.
			ol.alpha { list-style: lower-alpha; }
			ul       { list-style: disc; }
		
These are even better, since inheritance will transfer the 'list-style' value to the list items.

Markers: The ''::marker'' pseudo-element

This specification defines a new type of pseudo-element, the ::marker pseudo-element, which is generated by list items to represent the item's marker (the bullet or number identifying each item). Like ''::before'' and ''::after'', the ''::marker'' pseudo-element can be styled with the full range of CSS properties and values, exactly like a real element. Markers are placed at the beginning of their originating element's content, before the ''::before'' pseudo-element (if it exists). ''::marker'' pseudo-elements are inline by default, though certain values for 'list-style-position' on the list item can make the marker box positioned, which can have an effect on the computed value of display. The ''::marker'' pseudo-element is only created on list items. On any other element, the ''::marker'' pseudo-element's 'content' property must compute to ''content/none'', which suppresses its creation.
In the following example, the content is centered within a marker box of a fixed width. This document:
			<style>
			li::marker {
				content: "(" counter(counter) ")";
				width: 6em;
				text-align: center;
			}
			li {
				display: list-item;
				counter-increment: counter;
			}
			</style>
			<ol>
				<li>This is the first item.</li>
				<li>This is the second item.</li>
				<li>This is the third item.</li>
			</ol>
		
should render something like this:

		    (1)    This is the
		           first item.
		    (2)    This is the
		           second item.
		    (3)    This is the
		           third item.
		
In this example, markers are used to number paragraphs that are designated as "notes":
			<style>
			p { margin-left: 12 em; }
			p.note {
				display: list-item;
				counter-increment: note-counter;
			}
			p.note::marker {
				content: "Note " counter(note-counter) ":";
				text-align: left;
				width: 10em;
			}
			</style>
			<p>This is the first paragraph in this document.</p>
			<p class="note">This is a very short document.</p>
			<p>This is the end.</p>
		
It should render something like this:

		            This is the first paragraph
		            in this document.

		  Note 1:   This is a very short
		            document.

		            This is the end.
		
By using the ''::marker'' pseudo-element, a list's markers can be positioned much more flexibly, and even be styled independently from the text of the list item itself:
			<style>
			p { margin-left: 8em } /* Make space for counters */
			li { list-style-type: lower-roman; }
			li::marker { margin: 0 3em 0 0; color: blue; font-weight:bold; }
			</style>
			<p>This is a long preceding paragraph ...</p>
			<ol>
				<li>This is the first item.</li>
				<li>This is the second item.</li>
				<li>This is the third item.</li>
			</ol>
			<p>This is a long following paragraph ...</p>
		
The preceding document should render something like this:

		        This is a long preceding
		        paragraph ...

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

		        This is a long following
		        paragraph ...
		
Previously the only way to style a marker was through inheritance; one had to put the desired marker styling on the list item, and then revert that on a wrapper element around the list item's actual contents. Non-inherited properties like 'margin' couldn't be adjusted at all on the marker.

Generating the value of the 'content' property

The ''::marker'' pseudo-element's 'content' property is set according to its default contents, which are defined by the 'list-style-image' and 'list-style-type' properties:
an <>
The computed value of the 'content' property is the computed value of the <>, followed by a string containing a single space (U+0020 SPACE).
a <>
The computed value of the 'content' property is the <string>.
a <>
The computed value of the 'content' property is <> counter(list-item, <>) <>, where <counter-prefix> and <counter-suffix> are the values of the ''@counter-style/prefix'' and ''@counter-style/suffix'' descriptors for the counter style.
''list-style-type/none''
The computed value of the 'content' property is ''content/none''.
If the computed value of 'content' was an <>, and it ends up resolving to an invalid image, the used value of the 'content' property is as above, but with the default contents determined solely by 'list-style-type'.
Given the following style sheet:
			li { display: list-item; list-style-type: decimal /* initial value */; }
			li::marker { content: normal /* initial value */; }
		
And the following document fragment:
<li>List Item</li>
The computed value of the 'content' property on the ''::marker'' pseudo-element of the li is:
counter(list-item, decimal) "."

Positioning Markers

This section is not ready for implementation. It is an unreviewed rough draft that hasn't even been properly checked for Web-compatibility. Feel free to send feedback, but DON'T USE THIS PART OF THE SPEC. This section introduces a new positioning scheme, designed to model the way in which ''list-style-position:outside'' list markers were traditionally positioned in CSS 2.1. Outside list markers now have their positioning defined in terms of this new value. The new positioning scheme defined in this section can be used on all elements, not just ''::marker'' pseudo-elements. For example, this can be used to position explicit elements serving as markers in a legal document, so that the list item has a marker whose value is guaranteed to be correct regardless of whether the CSS is applied (often a requirement in legal documents), but which is positioned like a native CSS marker.

The ''marker'' value for 'position'

	Name: position
	New values: marker
	Computed value: see prose, otherwise same as normal
	
The marker value for 'position' depends on the element it is set on having a list item ancestor. If the specified value of 'position' is ''position/marker'' and the element does not have a list item ancestor, 'position' must compute to ''position/relative'' on the element. An element with ''position:marker'' counts as absolutely positioned. To calculate the marker's position, we must first define a few terms:
ancestor list item
The ancestor list item is the marker's nearest list item ancestor element.
marker positioning reference element
If the ancestor list item has ''marker-side:list-item'', the marker positioning reference element is the ancestor list item. Otherwise, if the ancestor list item has ''marker-side:list-container'' and has a parent element, the marker positioning reference element is the ancestor list item's parent. Otherwise, the marker positioning reference element is the ancestor list item.
list item positioning edge
The border edge of the ancestor list item corresponding to the "start" or "head" edge of the marker positioning reference element, whichever is in the ancestor list item's inline axis.
marker positioning edge
The outer edge of the marker that's on the opposite side from the list item positioning edge. For example, if the list item positioning edge ended up being the left border edge of the ancestor list item, the marker positioning edge would be the right margin edge of the marker.
The marker's position in the ancestor list item’s block axis is calculated according to the normal flow. The marker's position in the ancestor list item's inline axis must be set such that the marker positioning edge is flush with the list item positioning edge. Note: The purpose of this somewhat convoluted definition is to position the marker flush against its list item, and then when "marker-side:list-container", keep all the markers for a given list on the same side of their list items even in mixed-direction text, so that authors can specify padding on only one side of the list container and still ensure their markers are visible. And on top of all that, do something sane in the face of potentially differing writing-modes on the marker, list item, and container. All elements or pseudo-elements with ''position:marker'' that share a common ancestor list item are known as markers associated with that list item. The 'top', 'right', 'bottom', and 'left' properties specify offsets relative to the top, right, bottom, and left edges (respectively) of the element itself, similar to how relative positioning works.
''position:marker'' can be used when the precise list marker is important for the content, not a stylistic choice, but the normal appearance of lists is still desired. For example, this trimmed snippet of the US Code of Laws may be marked up as the following in HTML:
			<style>
			ol { list-style: none; }
			.marker { position: marker; }
			</style>
			<ol>
			  <li>
			    <span class='marker'>(a)</span> Definitions.— For purposes of this section—
			    <ol>
			      <li><span class='marker'>(1)</span> the term “agency” means agency as...
			      <li><span class='marker'>(2)</span> the term “individual” means a citizen...
			    </ol>
			  <li>
			    <span class='marker'>(b)</span> Conditions of Disclosure.— No agency shall disclose...
			    <ol>
			      <li><span class='marker'>(1)</span> to those officers and employees of the agency...
			      <li><span class='marker'>(2)</span> required under section 552 of this title;
			    </ol>
			</ol>
		
The preceding document should render something like this:
			(a) Definitions.— For purposes of this section—
			    (1) the term “agency” means agency as...
			    (2) the term “individual” means a citizen...
			(b) Conditions of Disclosure.— No agency shall disclose...
			    (1) to those officers and employees of the agency...
			    (2) required under section 552 of this title;
		
Importantly, even if the stylesheet is unavailable, the list markers will appear the same (though they will be positioned slightly differently), so other documents can refer to those list markers and be confident that the reference will always be resolvable.

The 'marker-side' property

By default, elements or ''::marker'' pseudo-elements with ''position:marker'' position themselves according to their list item's directionality. However, if the list item is grouped with several other list items which may have different directionality (for example, multiple <li>s with different "dir" attributes in an <ol> in HTML), it is sometimes more useful to have all the markers line up on one side, so the author can specify a single "gutter" on that side and be assured that all the markers will lie in that gutter and be visible. The 'marker-side' property defined in this section allows an author to control this, switching list items to positioning their markers based off the list container's directionality instead.
	Name: marker-side
	Value: list-item | list-container
	Initial: list-item
	Applies to: list items
	Inherited: yes
	Percentages: n/a
	Media: visual
	Computed value: specified value
	
list-item
Any markers associated with the list item base their positioning off of the directionality of the list item.
list-container
The associated markers instead base their positioning off of the directionality of the list item's parent element. The normative meaning of this is specified in the section defining position:marker.
Here is an example of the effect that 'marker-side' can have on a list. Both of the following example renderings are generated from the following HTML, with the only difference being the value of 'marker-side' on the list:
			<ul>
			  <li>english one
			  <li dir=rtl>OWT WERBEH
			  <li>english three
			  <li dir=rtl>RUOF WERBEH
			</ul>
		
list-item list-container
* english one
		 OWT WERBEH *
* english three
		RUOF WERBEH *
* english one
*    OWT WERBEH
* english three
*   RUOF WERBEH

Automatic Numbering With Counters

A counter is a special concept used, among other things, to automatically number list items in CSS. Every element has a collection of zero or more counters, which are inherited through the document tree in a way similar to inherited property values. They are created and manipulated with the 'counter-increment', 'counter-set' and 'counter-reset' properties, and used with the ''counter()'' and ''counters()'' functions. Counters have a name, an integer value, a creator element, and possibly another counter nested inside themselves.

Manipulating Counters: the 'counter-increment', 'counter-set' and 'counter-reset' properties

	Name: counter-reset
	Value: [ <> <>? ]+ | none
	Initial: none
	Applies to: all elements
	Inherited: no
	Percentages: n/a
	Media: all
	Computed value: specified value
	
The 'counter-reset' property creates new counters on an element. Its values are defined as follows:
none
This element does not create any new counters.
<> <>?
The element creates one or more new counters. Each <> names a new counter to be created. If an <> is provided after an <>, the starting value of the new counter is that integer. Otherwise, the starting value of the new counter is ''0''. Implementations may have implementation-specific limits on the maximum or minimum value of a counter. If an increment would push the counter's value beyond these limits, the increment must be ignored, and the counter's value remain unchanged.
	Name: counter-set
	Value: [ <> <>? ]+ | none
	Initial: none
	Applies to: all elements
	Inherited: no
	Percentages: n/a
	Media: all
	Computed value: specified value
	
	Name: counter-increment
	Value: [ <> <>? ]+ | none
	Initial: none
	Applies to: all elements
	Inherited: no
	Percentages: n/a
	Media: all
	Computed value: specified value
	
The 'counter-set' and 'counter-increment' properties manipulate the value of existing counters. They only create new counters if there is no counter of the given name on the element yet. Their values are defined as follows:
none
This element does not alter the value of any counters.
<> <>?
The element alters the value of one or more counters on it. If there is not currently a counter of the given name on the element, the element creates a new counter of the given name with a starting value of ''0'' (though it may then immediately set or increment that value to something different). If an <> is provided after an <>, it sets the innermost counter of the given name's value to that integer (for 'counter-set') or increments the value of the innermost counter of the given name by that integer (for 'counter-increment'). Otherwise, the innermost counter of the given name's value is set to ''0'' (for 'counter-set') or incremented by ''1'' (for 'counter-increment').

This example shows a way to number chapters and sections with "Chapter 1", "1.1", "1.2", etc.

			h1::before {
					content: "Chapter " counter(chapter) ". ";
					counter-increment: chapter;  /* Add 1 to chapter */
					counter-reset: section;      /* Set section to 0 */
			}
			h2::before {
					content: counter(chapter) "." counter(section) " ";
					counter-increment: section;
			}
		
Inheriting counters must be done before resetting counters, which must be done before setting counters, which must be done before incrementing counters, which must be done before using counters (for example, in the 'content' property).
The counter properties follow the cascading rules as normal. Thus, due to cascading, the following style sheet:
				h1 { counter-reset: section -1 }
				h1 { counter-reset: imagenum 99 }
			
will only reset ''imagenum''. To reset both counters, they have to be specified together:
H1 { counter-reset: section -1 imagenum 99 }
The same principles apply to the 'counter-set' and 'counter-increment' properties.

Creating and Inheriting Counters

Every element has a (possibly empty) set of counters. Like many other CSS values, an element can inherit counters from another element. However, unlike other CSS values, the method that counters are inherited is somewhat complex. A counter and its value are inherited separately, possibly from different elements. If an element has a previous sibling, it must inherit all of the sibling's counters. Otherwise, if the element has a parent, it must inherit all of the parent's counters. Otherwise, the element must have an empty set of counters. The element then inherits counter values from the immediately preceding element in document order. This must be done by examining the set of counters that the immediately preceding element has, and, for every counter that exists in both the element's set and the preceding element's set, giving the element's counter the same value. (If an element is the first element in the document, and thus has no immediately preceding element, it also doesn't have a parent or a previous sibling, and thus no counters to begin with.)
Take the following code as an example:
			<ul style='counter-reset: example 0;'>
				<li id='foo' style='counter-increment: example;'>
					foo
					<div id='bar' style='counter-increment: example;'>bar</div>
				</li>
				<li id='baz'>
					baz
				</li>
			</ul>
		
Recall that "in document order" turns a document tree into an ordered list, where an element comes before its children, and its children come before its next sibling. In other words, for a language like HTML, its the order in which the parser encounters start tags as it reads the document. In here, the <ul> element establishes a new counter named "example", and sets its value to 0. The "foo" element, being the first child of the <ul>, inherits this counter. Its parent is also its immediately preceding element in document order, so it inherits the value 0 with it, and then immediately increments the value to 1. The same happens with the "bar" element. It inherits the "example" counter from "foo", and inherits the value 1 from it as well and increments it to 2. However, the "baz" element is a bit different. It inherits the "example" counter from the "foo" element, its previous sibling. However, rather than inheriting the value 1 from "foo" along with the counter, in inherits the value 2 from "bar", the previous element in document order. This behavior allows a single counter to be used throughout a document, continuously incrementing, without the author having to worry about the nested structure of their document.
Elements can create additional counters on themselves, which can then be passed onto siblings or children. To create a new counter, specify an element that's creating it, a name, and a starting value. The effect depends on what other counters of that name exist on the element: Regardless, the value of the new counter is set to the provided starting value.

Nested Counters

Counters are "self-nesting"; creating a new counter in an element which already has a counter with the same name simply creates a new counter of the same name, nested inside the existing counter. This is important for situations like lists in HTML, where lists can be nested inside lists to arbitrary depth. It would be impossible to define uniquely named counters for each level. As explained in a later section, the ''counter()'' function only uses the innermost counter of a given name on the element, but the ''counters()'' function uses all counters of a given name that contain the element.
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:
			ol { counter-reset: item }
			li { display: block }
			li::before { content: counter(item) ". "; counter-increment: item }
		
In this example, an ol will create a counter, and all children of the ol will refer to that counter.
If we denote the nth instance of the "item" counter by item[n], then the following HTML fragment will use the indicated counters. (We assume the style sheet as given in the example above).
<ol> item[0] is created, set to 0
<li> item[0] is incremented to 1
<li> item[0] is incremented to 2
<ol> item[1] is created, set to 0, nested in item[0]
<li> item[1] is incremented to 1
<li> item[1] is incremented to 2
<li> item[1] is incremented to 3
<ol> item[2] is created, set to 0, nested in item[1]
<li> item[2] is incremented to 1
<li> item[1] is incremented to 4
<ol> item[3] is created, set to 0, nested in item[1]
<li> item[3] is incremented to 1
<li> item[1] is incremented to 5
<li> item[0] is incremented to 3
<li> item[0] is incremented to 4
<ol> item[4] is created, set to 0
<li> item[4] is incremented to 1
<li> item[4] is incremented to 2

Counters in elements that do not generate boxes

An element that does not generate a box (for example, an element with 'display' set to ''display/none'', or a pseudo-element with 'content' set to ''content/none'') cannot set, reset, or increment a counter. The counter properties are still valid on such an element, but they must have no effect.
For example, with the following style sheet, H2s with class "secret" do not increment ''count2''.
			h2 { counter-increment: count2; }
			h2.secret { display: none; }
		
Other methods of "hiding" elements, such as setting 'visibility' to ''visibility/hidden'', still cause the element to generate a box, and so do not apply here.

Printing Counters: the ''counter()'' and ''counters()'' functions

Counters have no visible effect by themselves, but their values can be used with the ''counter()'' and ''counters()'' functions. This happens automatically in the default contents of ''::marker'' pseudo-elements, but can be used by an author anywhere that accepts a string. Their syntax is:
		counter()  =  counter( <> [, [ <> | none ] ]? )
		counters() = counters( <>, <> [, [ <> | none ] ]? )
	
For both functions, the first argument represents the name of a counter, and if the last argument is omitted it defaults to ''decimal''. A ''counter()'' represents a <>, obtained as follows:
			H1::before        { content: counter(chno, upper-latin) ". " }
			/* Generates headings like "A. A History of Discontent" */

			H2::before        { content: counter(section, upper-roman) " - " }
			/* Generates headings like "II - The Discontent Part" */

			BLOCKQUOTE::after { content: " [" counter(bq, decimal) "]" }
			/* Generates blockquotes that end like "... [3]" */

			DIV.note::before  { content: counter(notecntr, disc) " " }
			/* Simply generates a bullet before every div.note */

			P::before         { content: counter(p, none) }
			/* inserts nothing */
		
A ''counters()'' represents a <>, obtained as follows:
The following example shows a simple use of the ''counters()'' function:
			<ul>
				<li>one</li>
				<li>two
					<ul>
						<li>nested one</li>
						<li>nested two</li>
					</ul>
				</li>
				<li>three</li>
			</ul>
			<style>
			ul { counter-reset: list-item; }
			li { counter-increment: list-item; }
			li::marker { content: '(' counters(list-item,'.') ') '; }
			</style>
		
The preceding document should render something like this:
			(1) one
			(2) two
				 (2.1) nested one
				 (2.2) nested two
			(3) three
		
Because counters inherit to siblings as well, they can be used to number headings and subheadings, which aren't nested within each other. Unfortunately, this prevents the use of ''counters()'' as counters from siblings don't nest, but one can create multiple counters and manually concatenate them instead:
			<h1>First H1</h1>
			...
			<h2>First H2 in H1</h2>
			...
			<h2>Second H2 in H1</h2>
			...
			<h3>First H3 in H2</h3>
			...
			<h1>Second H1</h1>
			...
			<h2>First H2 in H1</h2>
			...
			<style>
			body { counter-reset: h1 h2 h3; }
			h1   { counter-increment: h1; counter-reset: h2 h3;}
			h2   { counter-increment: h2; counter-reset:    h3; }
			h3   { counter-increment: h3; }
			h1::before { content: counter(h1,upper-alpha) ' '; }
			h2::before { content: counter(h1,upper-alpha) '.'
														counter(h2,decimal) ' '; }
			h3::before { content: counter(h1,upper-alpha) '.'
			                      counter(h2,decimal) '.'
			                      counter(h3,lower-roman) ' '; }
			</style>
		
The preceding document should render something like this:
			A First H1
			...
			A.1 First H2 in H1
			...
			A.2 Second H2 in H1
			...
			A.2.i First H3 in H2
			...
			B Second H1
			...
			B.1 First H2 in H1
			...
		

Sample style sheet for HTML

This section is informative, not normative. HTML itself defines the actual default properties that apply to HTML lists.
		/* Set up list items */
		li {
			display: list-item;
			/* counter-increment: list-item; (implied by display: list-item) */
		}

		/* Set up ol and ul so that they reset the list-item counter */
		ol, ul {
			counter-reset: list-item;
		}

		/* Default list style types for ordered lists */
		ol {
			list-style-type: decimal;
		}

		/* Default list style types for unordered lists up to 3 deep */
		ul { list-style-type: disc; }
		ul ul { list-style-type: square; }
		ul ul ul { list-style-type: circle; }
		/* Alternately, if Values & Units Level 3 is supported, replace
			 the above three lines with: */
		ul { list-style-type: disc; }
		ul ul { list-style-type: cycle(disc, square, circle); }

		/* The type attribute on ol and ul elements */
		ul[type="disc"] { list-style-type: disc; }
		ul[type="circle"] { list-style-type: circle; }
		ul[type="square"] { list-style-type: square; }
		ol[type="1"] { list-style-type: decimal; }
		ol[type="a"] { list-style-type: lower-alpha; }
		ol[type="A"] { list-style-type: upper-alpha; }
		ol[type="i"] { list-style-type: lower-roman; }
		ol[type="I"] { list-style-type: upper-roman; }

		/* The start attribute on ol elements */
		ol[start] {
			counter-reset: list-item calc(attr(start integer, 1) - 1);
		}

		/* The value attribute on li elements */
		li[value] {
			counter-set: list-item attr(value integer, 1);
			counter-increment: none; /* Turn off default increase */
		}

		/* Handling reversed lists */
		ol[reversed] {
			counter-reset: list-item calc(attr(start integer, **magic**) + 1);
			/* Where **magic** is the number of child <li> elements. */
		}
		ol[reversed] > li {
			counter-increment: list-item -1;
		}

		/* Box Model Rules */
		ol, ul {
			display: block;
			margin: 1em 0;
			marker-side: list-container;
		}

		ol:dir(ltr), ul:dir(ltr) {
			padding-left: 40px;
		}
		ol:dir(rtl), ul:dir(rtl) {
			padding-right: 40px;
		}

		ol ol, ol ul, ul ul, ul ol {
			margin-top: 0;
			margin-bottom: 0;
		}

		li {
			text-align: match-parent;
		}

		li::marker {
			display: inline;
			text-align: end;
			unicode-bidi: isolate;
			/* 'position' computes to "static" or "marker" depending on list-style-position */
		}
	

Acknowledgments

The following people and documentation they wrote were very useful for defining the numbering systems: Alexander Savenkov, Arron Eicholz, Aryeh Gregor, Frank Tang, Jonathan Rosenne, Karl Ove Hufthammer, Musheg Arakelyan, Nariné Renard Karapetyan, Randall Bart, Richard Ishida, Simon Montagu (Mozilla, smontagu@smontagu.org)

Changes From CSS2.1

As described in the introduction section, there are significant changes in this module when compared to CSS2.1.

  1. The ''::marker'' pseudo-element has been introduced to allow styling of the list marker directly.
  2. The ''marker'' value for 'position' has been added, to allow elements in the document to position themselves similarly to how markers do.
  3. Many new list style types have been added, along with explicit algorithms for each.
  4. The list-item predefined counter identifier has been introduced.