CSS Generated Content Module Level 3
CSS Generated Content Module Level 3
Editor’s Draft
9 January 2026
More details about this document
This version:
Latest published version:
Previous Versions:
Feedback:
CSSWG Issues Repository
Inline In Spec
Editors:
Elika J. Etemad / fantasai
Apple, formerly Mozilla
Mike Bremford
BFO
Former Editors:
Dave Cramer
Hachette Livre
Håkon Wium Lie
Opera Software
Ian Hickson
Google
Suggest an Edit for this Spec:
GitHub Editor
Test Suite:
World Wide Web Consortium
W3C
liability
trademark
and
permissive document license
rules apply.
Abstract
This CSS3 Module describes how to insert content in a document.
CSS
is a language for describing the rendering of structured documents
(such as HTML and XML)
on screen, on paper, etc.
Status of this document
This is a public copy of the editors’ draft.
It is provided for discussion only and may change at any moment.
Its publication here does not imply endorsement of its contents by W3C.
Don’t cite this document other than as work in progress.
Please send feedback
by
filing issues in GitHub
(preferred),
including the spec code “css-content” in the title, like this:
“[css-content]
…summary of comment…
”.
All issues and comments are
archived
Alternately, feedback can be sent to the (
archived
) public mailing list
www-style@w3.org
This document is governed by the
18 August 2025 W3C Process Document
This is a very rough draft, and is not ready for implementation.
Introduction
Authors sometimes want user agents to render content that does not come from the document tree.
One familiar example of this is numbered headings;
the author does not want to mark the numbers up explicitly,
they want the user agent to generate them automatically.
Counters and markers are used to achieve these effects.
h1
:before
content
counter
section
": "
Similarly, authors may want the user agent to insert the word "Figure" before the caption of a figure,
or "Chapter 7" on a line before the seventh chapter title.
chapter
counter-increment
chapter
chapter > title::before
content
"Chapter "
counter
chapter
"\A"
Another common effect is replacing elements with images or other multimedia content.
Since not all user agents support all multimedia formats,
fallbacks may have to be provided.
/* Replace elements with the site's logo, using a format
* supported by the UA */
logo
content
url
logo.mov
),
url
logo.mng
),
url
logo.png
),
none
/* Replace

elements with the referenced document, or,
* failing that, with either the contents of the alt attribute or the
* contents of the element itself if there is no alt attribute */
figure
alt
content
attr
href url
),
attr
alt
);
figure:not
([
alt
])
content
attr
href url
),
contents
Tests
General tests for generated content
inheritance.html
(live test)
(source)
Value Definitions
This specification follows the
CSS property definition conventions
from
[CSS2]
using the
value definition syntax
from
[CSS-VALUES-3]
Value types not defined in this specification are defined in CSS Values & Units
[CSS-VALUES-3]
Combination with other CSS modules may expand the definitions of these value types.
In addition to the property-specific values listed in their definitions,
all properties defined in this specification
also accept the
CSS-wide keywords
as their property value.
For readability they have not been repeated explicitly.
1.
Inserting and Replacing Content: the
content
property
Name:
content
Value:
normal
none


] [/ [



Initial:
normal
Applies to:
all elements, tree-abiding pseudo-elements, and page margin boxes
Inherited:
no
Percentages:
n/a
Computed value:
See prose below
Canonical order:
per grammar
Animation type:
discrete
Tests
attr-case-sensitivity-001.html
(live test)
(source)
attr-case-sensitivity-002.html
(live test)
(source)
attr-case-sensitivity-003.html
(live test)
(source)
computed-value.html
(live test)
(source)
content-animation.html
(live test)
(source)
content-no-interpolation.html
(live test)
(source)
content-none-select-1.html
(live test)
(source)
element-replacement-alt.html
(live test)
(source)
element-replacement-display-contents.html
(live test)
(source)
element-replacement-display-none.html
(live test)
(source)
element-replacement-dynamic.html
(live test)
(source)
element-replacement-gradient.html
(live test)
(source)
element-replacement-image-alt.html
(live test)
(source)
element-replacement.html
(live test)
(source)
content-computed.html
(live test)
(source)
content-counter-valid.html
(live test)
(source)
content-invalid.html
(live test)
(source)
content-valid.html
(live test)
(source)
User agents are expected to support this property on all media, including non-visual ones.
The
content
property dictates what is rendered inside an element or
pseudo-element
For elements, it has only one purpose:
specifying that the element renders as normal,
or replacing the element with an image
(and possibly some associated "alt text").
For
pseudo-elements
and margin boxes,
it is more powerful.
It controls whether the element renders at all,
can replace the element with an image,
or replace it with arbitrary inline content
(text and images).
normal
For an element or page margin box, this computes to
contents
For
::before
and
::after
, this computes to
none
For
::marker
::placeholder
and
::file-selector-button
this computes to itself (
normal
).
none
On elements, this behaves as
normal
On
pseudo-elements
it inhibits the creation of the pseudo-element
as if it had
display: none
In neither case does it prevent any pseudo-elements which have this element or pseudo-element as an
originating element
from being generated.

Equal to:

Makes the element or
pseudo-element
replaced element
filled with the specified

Its normal contents are suppressed
and do not generate boxes,
as if they were
display: none
If the

represents an
invalid image
then it must be treated as instead representing an image with zero
natural
width and height,
filled with transparent black.
The above
invalid image
behavior appears to be what Chrome is doing.
Is this okay?
Is there a better behavior we can/should use?
Note:
Replaced elements use different layout rules than normal elements.
(In effect, it becomes equivalent to an HTML
img
element.)
Note:
Replaced elements do not have
::before
or
::after
pseudo-elements
the
content
property replaces their entire contents.
This value has historically been treated as

on
::before
and
::after
Presumably there’s a Web-compat requirement on this,
so these pseudo-elements might need an exception.
[Issue #2889]

Replaces the element’s contents with one or more anonymous inline boxes
corresponding to the specified values,
in the order specified.
Its normal contents are suppressed
and do not generate boxes,
as if they were
display: none
Each value contributes an inline box to the element’s contents.
For

, this is an inline anonymous replaced element;
for the others, it’s an anonymous inline run of text.
If an

represents an
invalid image
the user agent must do one of the following:
"Skip" the

, generating nothing for it.
Display some indication that the image can’t be displayed in place of the

such as a "broken image" icon.
This specification intentionally does not define which behavior a user agent must use,
but it must use one or the other consistently.
Note:
If the value of

is a single

it must instead be interpreted as a

Tests
pseudo-element-inline-box.html
(live test)
(source)
/ [



]+
Specifies the "alt text" for the element.
See
§ 1.2 Alternative Text for Accessibility
for details.
If omitted,
the element has no "alt text".
To correctly use

in "alt text" in unsupported browsers
one should specify
content
property twice.
First, a fallback without counter in "alt text".
Second, use counter in "alt text".
::before
content
"Chapter"
counter
chapter
);
content
"Chapter"
counter
chapter
"Chapter"
counter
chapter
);
Should the contents keyword be replaced with
content()
1.1.
Accessibility of Generated Content
Generated content should be searchable, selectable, and available to assistive technologies.
The
content
property applies to speech
and generated content must be rendered for speech output.
[CSS3-SPEECH]
Start work on an AAM for CSS.
1.2.
Alternative Text for Accessibility
Content intended for visual media sometimes needs alternative text for speech output or other non-visual mediums.
The
content
property thus accepts alternative text
to be specified after a slash (
) after the last

If such alternative text is provided,
it must be used for speech output instead.
This allows, for example, purely decorative text to be elided in speech output
(by providing the empty string as alternative text),
and allows authors to provide more readable alternatives
to images, icons, or text-encoded symbols.
Here the content property is an image, so the alt value is required to provide alternative text.
.new::before
content
url
./img/star.png
"New!"
/* or a localized attribute from the DOM: attr("data-alt") */
If the
pseudo-element
is purely decorative and its function is covered elsewhere, setting alt to the empty string can avoid reading out the decorative element. Here the ARIA attribute will be spoken as "collapsed". Without the empty string alt value, the content would also be spoken as "Black right-pointing pointer".
.expandable::before
content
"\25BA"
""
/* a.k.a. ► */
/* aria-expanded="false" already in DOM,
so this pseudo-element is decorative */
2.
Generated Content Values: the

type
The

value is used in
content
to fill an element with one or more anonymous inline boxes,
including images, strings, the values of counters, and the text value of elements.
In this section we enumerate the possibilities.
The syntax of

is defined as:



attr
()
contents

leader
()

string
()
content
()

2.1.
Basic Strings:

and

values

Represents an anonymous inline box filled with the specified text.
Note:
White space
in the string is handled the same as in literal text,
and controlled by the properties in
[CSS-TEXT-3]
and elsewhere.
In particular,
white space
character can collapse,
even across multiple strings,
such as in
content: "First " " Second";
which by default will render similar to
"First Second"
(with a single visible space between the two words).

The
attr()
functional notation represents
the string stored as the specified attribute’s value.
Its argument is a
CSS qualified name
qname
representing the attribute name and namespace, if any.
See
[CSS3-NAMESPACE]
Note:
As in
attribute selectors
attribute names without an explicit namespace
do not associate with any default namespace.
2.2.
2D Images:

values

Represents an anonymous inline replaced element
filled with the specified

If the

represents an
invalid image
this value instead represents nothing.
(No inline content is added to the element,
as if this value were "skipped".)
CSS2.1 explicitly allowed the UA to substitute a broken image icon
if the image was invalid.
However, no browser appears to do this.
Is this removal okay?
2.3.
Elemental Content: the
contents
keyword
contents
The element’s descendants.
Since this can only be used once per element
(you can’t duplicate the children if, e.g., one is a plugin or form control),
it is handled as follows:
If set on the element:
Always honoured.
Note that this is the default,
since the initial value of
content
is
normal
and
normal
computes to
contents
on an element.
If set on one of the element’s other
pseudo-elements
Check to see that it is not set on a "previous" pseudo-element, in the following order, depth first:
the element itself
::before
::after
Should this behave as an empty string on pseudo-elements?
If it is already used, then it evaluates to nothing (like
none
).
Only pseudo-elements that are actually generated are checked.
In the following case:
foo
content
normal
/* this is the initial value */
foo::after
content
contents
...the element’s
content
property would compute to
contents
and the
::after
pseudo-element
would have no contents
(equivalent to
none
and thus would not appear.
foo
content
none
foo::after
content
contents
But in this example, the ::after pseudo-element will contain the contents of the foo element.
Use cases for suppressing the content on the element and using it in a pseudo-element would be welcome.
Note:
While it is useless to include
contents
twice in a single
content
property,
that is not a parse error.
The second occurrence simply has no effect,
as it has already been used.
It is also not a parse error to use it on a
::marker
pseudo-element,
it is only during the rendering stage that it gets treated like
none
Do we need the statement about marker pseudo-elements here? Or is this legacy from the old version of the spec?
2.4.
Quotation Marks
The
quotes
property, which defines the
quotation mark system
of an
element,
in conjunction with the various
*-quote
values of the
content
property,
which insert corresponding quotation marks as generated content,
can be used to automatically insert opening and closing quotation marks,
such as for the HTML
element.
2.4.1.
Quotation Mark System: the
quotes
property
Name:
quotes
Value:
auto
none
match-parent


Initial:
auto
Applies to:
all elements
Inherited:
yes
Percentages:
n/a
Computed value:
the keyword
none
, the keyword
auto
or
match-parent
, or a list, each item a pair of string values
Canonical order:
per grammar
Animation type:
discrete
Tests
quotes-001.html
(live test)
(source)
quotes-002.html
(live test)
(source)
quotes-003.html
(live test)
(source)
quotes-004.html
(live test)
(source)
quotes-005.html
(live test)
(source)
quotes-006.html
(live test)
(source)
quotes-007.html
(live test)
(source)
quotes-008.html
(live test)
(source)
quotes-009.html
(live test)
(source)
quotes-010.html
(live test)
(source)
quotes-011.html
(live test)
(source)
quotes-012.html
(live test)
(source)
quotes-013.html
(live test)
(source)
quotes-014.html
(live test)
(source)
quotes-015.html
(live test)
(source)
quotes-016.html
(live test)
(source)
quotes-017.html
(live test)
(source)
quotes-018.html
(live test)
(source)
quotes-019.html
(live test)
(source)
quotes-020.html
(live test)
(source)
quotes-021.html
(live test)
(source)
quotes-022.html
(live test)
(source)
quotes-023.html
(live test)
(source)
quotes-024.html
(live test)
(source)
quotes-025.html
(live test)
(source)
quotes-026.html
(live test)
(source)
quotes-027.html
(live test)
(source)
quotes-028.html
(live test)
(source)
quotes-029.html
(live test)
(source)
quotes-030.html
(live test)
(source)
quotes-031.html
(live test)
(source)
quotes-032.html
(live test)
(source)
quotes-033.html
(live test)
(source)
quotes-034.html
(live test)
(source)
quotes-035.html
(live test)
(source)
quotes-first-letter-001.html
(live test)
(source)
quotes-first-letter-002.html
(live test)
(source)
quotes-first-letter-003.html
(live test)
(source)
quotes-first-letter-004.html
(live test)
(source)
quotes-first-letter-005.html
(live test)
(source)
quotes-first-line.html
(live test)
(source)
quotes-lang-dynamic-001.html
(live test)
(source)
User agents are expected to support this property on all media, including non-visual ones.
This property specifies the
quotation mark system
for the element,
defining how the
content
property’s
open-quote
and
close-quote
values behave.
See
§ 2.4.2 Inserting Quotation Marks: the *-quote keywords
Values have the following meanings:
none
The
open-quote
and
close-quote
values of the
content
property
produce no quotations marks,
as if they were
no-open-quote
and
no-close-quote
respectively.
auto
A typographically appropriate
quotation mark system
is automatically chosen by the UA
based on the
content language
of the parent
(or, if there is no parent, of the element itself).
Note:
The Unicode Common Locale Data Repository
[CLDR]
maintains information on typographically appropriate quotation marks.
UAs can use other sources of information as well,
particularly as typographic preferences can vary;
however it is encouraged to submit any improvements to Unicode
so that the entire software ecosystem can benefit.
match-parent
Specifies the same
quotation mark system
as the parent.
In general this is equivalent to inheriting the parent’s
computed value
except that
auto
it resolves
using the same
content language
that the parent used.
Two possible approaches here, currently speccing the latter:
a) this computes to the relevant string values, and inherits as such.
b) this value effectively inherits as a keyword + a language code,
meaning
auto
, but with this language.


]+
The
quotation mark system
is defined as
the specified list of pairs of quotation marks (opening and closing).
The first pair represents the outermost level of quotation,
the second pair the next level of embedding, etc.
Within a pair,
the
open-quote
value refers to the first

close-quote
refers to the second.
2.4.2.
Inserting Quotation Marks: the
*-quote
keywords

= open-quote
close-quote
no-open-quote
no-close-quote
Tests
quotes-slot-scoping.html
(live test)
(source)
open-quote
close-quote
These values are replaced by the appropriate string
as defined by the
quotes
property,
and increments (for
open-quote
or decrements (for
close-quote
the level of nesting for quotes.
no-open-quote
no-close-quote
Inserts nothing (as in
none
),
but increments (for
no-open-quote
or decrements (for
no-close-quote
the level of nesting for quotes.
Quotation marks can be 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 a quotation mark string
as defined by the
quotation mark system
specified by the
quotes
property,
based on the
depth of nesting
Which pair of quotes is used depends on the nesting level of quotes
(the
quote depth
):
the number of occurrences of
open-quote
in all generated text before the current occurrence,
minus the number of occurrences of
close-quote
in all generated text before and including the current occurence.
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.
Note:
Quote depth
is independent of
the nesting of the source document or the formatting structure.
Also, like
counter inheritance
it operates on the “flattened element tree”
in the context of the
[DOM]
close-quote
or
no-close-quote
that would make the
quote depth
negative
is in error and is ignored (at rendering time):
the depth stays at 0 and no quote mark is inserted
(although the rest of the
content
property’s value is still inserted).
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.
The following style sheet puts opening quotation marks on every paragraph in a
blockquote
and inserts a single closing quote at the end:
blockquote p::before
content
open-quote
blockquote p::after
content
no-close-quote
blockquote p:last-child::after
content
close-quote
For symmetry, there is also a
no-open-quote
keyword,
which inserts nothing,
but increments the quotation depth by one.
Note:
If a quotation is in a different language than the surrounding text,
it is customary to quote the text with the quote marks of the language of the surrounding text,
not the language of the quotation itself.
For example, French inside English:
The device of the order of the garter is “Honi soit qui mal y pense.”
English inside French:
Il disait: « Il faut mettre l’action en ‹ fast forward ›. »
A style sheet like the following will set the
quotes
property
so that
open-quote
and
close-quote
will work correctly on all elements.
These rules are for documents that contain only English, French, or both.
One rule is needed for every additional language.
Note the use of the child combinator (">")
to set quotes on elements based on the language of the surrounding text:
:lang
fr
> *
quotes
"\00AB\2005"
"\2005\00BB"
"\2039\2005"
"\2005\203A"
:lang
en
> *
quotes
"\201C"
"\201D"
"\2018"
"\2019"
The quotation marks are shown here in a form that most people will be able to type.
If you can type them directly, they will look like this:
:lang
fr
> *
quotes
"« "
" »"
"‹ "
" ›"
:lang
en
> *
quotes
"“"
"”"
"‘"
"’"
For example, applying the following style sheet:
/* Specify pairs of quotes for two levels in two languages */
:lang
en
> q
quotes
'"'
'"'
"'"
"'"
:lang
no
> q
quotes
"«"
"»"
"’"
"’"
/* Insert quotes before and after Q element content */
q::before
content
open-quote
q::after
content
close-quote
to the following HTML fragment:
"en"

Quotes


Quote me!




would allow a user agent to produce:
"Quote me!"
while this HTML fragment:
"no"

Quotes


Trøndere gråter når Vinsjan på kaia blir deklamert.




would produce:
«Trøndere gråter når ’Vinsjan på kaia’ blir deklamert.»
2.5.
Leaders
A leader, sometimes known as a tab leader or a dot leader,
is a repeating pattern used to visually connect content across horizontal spaces.
They are most commonly used in tables of contents,
between titles and page numbers.
The
leader()
function,
as a value for the content property,
is used to create leaders in CSS.
This function takes a string (the leader string),
which describes the repeating pattern for the leader.
2.5.1.
The
leader()
function
leader(

Inserts a leader.
See the section on
leaders
for more information.
leader
()
leader


= dotted
solid
space

Three keywords are shorthand values for common strings:
dotted
Equivalent to
leader(".")
solid
Equivalent to
leader("_")
space
Equivalent to
leader(" ")

Issue: Define this.
ol.toc a::after
content
leader
'.'
target-counter
attr
href
),
page
);

Table of Contents


    "toc"
  1. "#chapter1"
    >Loomings

  2. "#chapter2"
    >The Carpet-Bag

  3. "#chapter3"
    >The Spouter-Inn


This might result in:
Table of Contents
. Loomings....................
.1
. The Carpet-Bag..............
.9
. The Spouter-Inn............
.13
Do leaders depend on the assumption that the content after the leader is right-aligned (end-aligned)?
2.5.2.
Rendering leaders
Consider a line which contains the content before the leader (the “before content”),
the leader,
and the content after the leader (the “after content”).
Leaders obey the following rules:
The leader string must appear in full at least once.
The leader should be as long as possible
Visible characters in leaders should vertically align with each other when possible.
Line break characters in the leader string must be ignored.
White space in the leader string follows normal CSS rules.
A leader only appears between the start content and the end content.
A leader only appears on a single line, even if the before content and after content are on different lines.
A leader can’t be the only thing on a line.
2.5.3.
Procedure for rendering leaders
Lay out the
before content
until reaching the line where the
before content
ends.
BBBBBBBBBB
BBB
The leader string consists of one or more glyphs,
and is thus an inline box.
A leader is a row of these boxes,
drawn from the end edge to the start edge,
where only those boxes not overlaid by the before or after content.
On this line,
draw the leader string,
starting from the end edge,
repeating as many times as possible until reaching the start edge.
BBBBBBBBBB
..........
Draw the before and after content on top of the leader.
If any part of the
before content
or
after content
overlaps a glyph in a leader string box,
that glyph is not displayed.
BBBBBBBBBB
BBB....AAA
If one full copy of the leader string is not visible:
BBBBBBB
BBBBBBA
Insert a line break after the
before content
draw the leader on the next line,
and draw the
after content
on top,
and hide any leader strings that are not fully displayed.
BBBBBBB
BBBBBB
......A
what to do if
after content
is wider than the line box?
Leaders don’t quite work in table layouts. How can we fix this?
Procedure for drawing leaders
Procedure for drawing leaders when the content doesn’t fit on a single line
2.6.
Cross References
Many documents contain internal references:
See chapter 7
in section 4.1
on page 23
Three new values for the content property
are used to automatically create these types of cross-references:
target-counter()
target-counters()
, and
target-text()
Each of these displays information obtained from the target end of a link.

target-counter
()
target-counters
()
target-text
()
See sections below for details on each of these.
2.6.1.
The
target-counter()
function
target-counter
()
target-counter




The
target-counter()
function retrieves the value
of the innermost counter with a given name.
The required arguments are the url of the target
and the name of the counter.
An optional counter-style argument can be used to format the result.
These functions only take a fragment URL
which points to a location in the current document.
If there’s no fragment,
if the ID referenced isn’t there,
or if the URL points to an outside document,
the user agent must treat that as an error.
what should error handling be?
restrict syntactically to local references for now.
HTML:
…which will be discussed on page "#chapter4_sec2"
>
.
CSS:
:after
content
target-counter
attr
href url
),
page
Result:
…which will be discussed on page
137
Page numbers in tables of contents can be generated automatically:
HTML:

CSS:
.frontmatter a::after
content
leader
'.'
target-counter
attr
href url
),
page
lower-roman
.bodymatter a::after
content
leader
'.'
target-counter
attr
href url
),
page
decimal
Result:
Preface.............vii
Introduction.........xi
Chapter One..........
.1
2.6.2.
The
target-counters()
function
This functions fetches the value of all counters of a given name
from the end of a link,
and formats them by inserting a given string between the value of each nested counter.
target-counters
()
target-counters





I have not found a compelling example for
target-counters
()
yet.
found a compelling example, in CSS specs. Do something.
2.6.3.
The
target-text()
function
The
target-text()
function retrieves
the text value of the element referred to by the URL.
An optional second argument specifies what content is retrieved,
using the same values as the
string-set
property above.
target-text
()
target-text


content
before
after
first-letter
A simpler syntax has been proposed by fantasai:
…which will be discussed "#chapter_h1_1"
>later
.

a::after
content
", in the chapter entitled "
target-text
attr
href url
))
Result: …which will be discussed later, in the chapter entitled Loomings.
2.7.
Named Strings
This section introduces
named strings
which are the textual equivalent of counters
and which have a distinct namespace from counters.
Named strings follow the same nesting rules as counters.
The
string-set
property accepts values similar to the
content
property,
including the extraction of the current value of counters.
Named strings are a convenient way to pull metadata out of the document
for insertion into headers and footers.
In HTML, for example,
META elements contained in the document HEAD
can set the value of named strings.
In conjunction with attribute selectors,
this can be a powerful mechanism:
meta
author
string-set
author
attr
author
);
head > title
string-set
title contents
@page
:left
@top
text-align
left
vertical-align
middle
content
string
title
);
@page
:right
@top
text-align
right
vertical-align
middle
content
string
author
);
2.7.1.
Naming Strings: the
string-set
property
Name:
string-set
Value:
none


Initial:
none
Applies to:
all elements, but not
pseudo-elements
Inherited:
no
Percentages:
N/A
Computed value:
the keyword
none
or a list, each item an identifier paired with a list of string values
Canonical order:
per grammar
Animation type:
discrete
User agents are expected to support this property on all media, including non-visual ones.
The
string-set
property copies the text content of an element into a
named string
which functions as a variable.
The text content of this named string can be retrieved using the
string()
function.
Since these variables may change on a given page,
an optional second value for the
string()
function
allows authors to choose which value on a page is used.
none
The element does not set any named strings.


The element establishes one or more named strings,
corresponding to each comma-separated entry in the list.
For each entry, the

gives the name of the named string.
It’s followed by one or more

values,
which are concatenated together to form the value of the named string.
If an element has
style containment
the
string-set
property must have no effects on descendants of that element.
The following example captures the contents of H1 elements,
which represent chapter names in this hypothetical document.
H1
string-set
chapter contents
When an H1 element is encountered,
the
chapter
string is set to the element’s textual contents,
and the previous value of
chapter
, if any, is overwritten.
2.7.2.
Inserting Named Strings: the
string()
function
string
()
string

first
start
last
first-except
The
string()
function is used to copy the value of a named string to the document,
via the
content
property.
This function requires one argument,
the name of the named string.
Since the value of a named string may change several times on a page
(as multiple elements defining the string can appear)
an optional second argument indicates which value of the named string should be used.
The second argument of the
string()
function is one of the following keywords:
first
The value of the first assignment on the page is used.
If there is no assignment on the page,
the
entry value
is used.
If no second argument is provided,
this is the default value.
start
If the element is the first element on the page,
the value of the first assignment is used.
Otherwise the
entry value
is used.
The
entry value
may be empty if the
named string
hasn’t yet appeared.
last
The
exit value
of the named string is used.
first-except
This is identical to
first
except that the empty string is used on the page where the value is assigned.
we may need to kill the entire content string. Is this necessary?
The content values of named strings
are assigned at the point when the content box of the element is first created
(or would have been created if the element’s display value is none).
The
entry value
for a page
is the assignment in effect at the end of the previous page.
The
exit value
for a page
is the assignment in effect at the end of the current page.
CSS:
@page
size
15
cm
10
cm
margin
1.5
cm
@top-left
content
"first: "
string
heading
first
);
@top-center
content
"start: "
string
heading
start
);
@top-right
content
"last: "
string
heading
last
);
h2
string-set
heading
content
()
The following figures show the first, start, and last assignments
of the “heading” string on various pages.
The
start
value is empty,
as the string had not yet been set at the start of the page.
Since the page starts with an h2,
the
start
value is the value of that head.
Since there’s not an h2 at the top of this page,
the
start
value is the
exit value
of the previous page.
2.7.3.
The
content()
function
content
()
content
text
before
after
first-letter
marker
text
The string value of the element.
If no value is specified in
content()
it acts as if
text
were specified.
before
The string value of the
::before
pseudo-element
after
The string value of the
::after
pseudo-element
first-letter
The first letter of the element, as defined for the
::first-letter
pseudo-element
marker
The string value of the
::marker
pseudo-element
HTML:

Loomings


CSS:
h1
:before
content
'Chapter '
counter
chapter
);
h1
string-set
header
content
before
':'
content
text
);
h1::after
content
'.'
The value of the named string “header” will be “Chapter 1: Loomings”.
HTML:
"Loomings"
CSS:
section
string-set
header
attr
title
The value of the “header” string will be “Loomings”.
2.8.
Automatic Counters and Numbering
See
CSS Lists 3
§ 4 Automatic Numbering With Counters
Should this move back to CSS Content?
3.
Bookmarks
Some document formats,
most notably PDF,
allow the use of
bookmarks
as an aid to navigation.
Bookmarks provide a list of links to document elements,
as well as text to label the links and a level value.
A bookmark has three properties:
bookmark-level
bookmark-label
, and
bookmark-state
When a user activates a bookmark,
the user agent must bring that reference point to the user’s attention,
exactly as if navigating to that element by fragment URL.
This will also trigger matching the
:target
pseudo-class.
If an element has
style containment
, the
bookmark-level
bookmark-label
, and
bookmark-state
properties
must have no effect on descendants of the element.
3.1.
Setting a Bookmark: the
bookmark-level
property
The
bookmark-level
property determines if a bookmark is created,
and at what level.
If this property is absent,
or has value
none
no bookmark should be generated,
regardless of the values of
bookmark-label
or
bookmark-state
Name:
bookmark-level
Value:
none

Initial:
none
Applies to:
all elements
Inherited:
no
Percentages:
N/A
Computed value:
the keyword
none
or the specified integer
Canonical order:
per grammar
Animation type:
by computed value type

defines the level of the bookmark, with the top level being 1 (negative and zero values are invalid).
none
no bookmark is generated.
section h1
bookmark-level
section section h1
bookmark-level
section section section h1
bookmark-level
Note:
Bookmarks do not need to create a strict hierarchy of levels.
Should a bookmark be created for elements with
display
none
3.2.
Labelling a Bookmark: the
bookmark-label
property
Name:
bookmark-label
Value:

Initial:
content(text)
Applies to:
all elements
Inherited:
no
Percentages:
N/A
Computed value:
specified value
Canonical order:
per grammar
Animation type:
discrete


is defined above, in the section on the
string-set
property. The value of

becomes the text content of the bookmark label.
HTML:

Loomings


CSS:
h1
bookmark-label
content
text
);
bookmark-level
The bookmark label will be “Loomings”.
3.3.
Initial Bookmark Toggle State: the
bookmark-state
property
The
bookmark-state
may be open or closed. The user must be able to toggle the bookmark state.
Name:
bookmark-state
Value:
open
closed
Initial:
open
Applies to:
block-level elements
Inherited:
no
Percentages:
N/A
Computed value:
specified keyword
Canonical order:
per grammar
Animation type:
discrete
open
Subsequent bookmarks with
bookmark-level
greater than the given bookmark are displayed,
until reaching another bookmark of the same level or lower.
If one of subsequent bookmark is closed,
apply the same test to determine if its subsequent bookmarks should be displayed.
closed
Subsequent bookmarks of bookmark-level greater than the given bookmark are not displayed,
until reaching another bookmark of the same level or lower.
Is the initial bookmark state,
or the bookmark state updated by the UA as appropriate?
4.
Changes
Significant changes since the
2 August 2019 Working Draft
consist primarily of:
Updated
auto
to reference the
parent
content language
rather than the
content language
of the element itself.
Issue 5478
Added
match-parent
value to
quotes
Issue 5478
Prevent negative
quote depth
by ignoring excess closing quotes,
consistent with
[CSS2]
Issue 2034
Defined computed value of
content: normal
for
::placeholder
and
::file-selector-button
Issue 6124
Fixed an off-by-one error for the
quote depth
of closing quotes.
Issue 2506
Inlined the definition of
attr()
, since it has been dropped from
[CSS-VALUES-4]
Added Web Platform Tests coverage.
Miscellaneous editorial spec clean up.
See also
previous changes
Acknowledgements
Stuart Ballard,
David Baron,
Bert Bos,
Tantek Çelik
and James Craig
provided invaluable suggestions used in this specification.
Privacy Considerations
No new privacy considerations have been reported on this specification.
Security Considerations
No new security considerations have been reported on this specification.
Conformance
Document conventions
Conformance requirements are expressed with a combination of
descriptive assertions and RFC 2119 terminology. The key words “MUST”,
“MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”,
“RECOMMENDED”, “MAY”, and “OPTIONAL” in the normative parts of this
document are to be interpreted as described in RFC 2119.
However, for readability, these words do not appear in all uppercase
letters in this specification.
All of the text of this specification is normative except sections
explicitly marked as non-normative, examples, and notes.
[RFC2119]
Examples in this specification are introduced with the words “for example”
or are set apart from the normative text with
class=
"example"
like this:
This is an example of an informative example.
Informative notes begin with the word “Note” and are set apart from the
normative text with
class=
"note"
, like this:
Note, this is an informative note.
Advisements are normative sections styled to evoke special attention and are
set apart from other normative text with
"advisement"
, like
this:
UAs MUST provide an accessible alternative.
Tests
Tests relating to the content of this specification
may be documented in “Tests” blocks like this one.
Any such block is non-normative.
Conformance classes
Conformance to this specification
is defined for three conformance classes:
style sheet
CSS
style sheet
renderer
UA
that interprets the semantics of a style sheet and renders
documents that use them.
authoring tool
UA
that writes a style sheet.
A style sheet is conformant to this specification
if all of its statements that use syntax defined in this module are valid
according to the generic CSS grammar and the individual grammars of each
feature defined in this module.
A renderer is conformant to this specification
if, in addition to interpreting the style sheet as defined by the
appropriate specifications, it supports all the features defined
by this specification by parsing them correctly
and rendering the document accordingly. However, the inability of a
UA to correctly render a document due to limitations of the device
does not make the UA non-conformant. (For example, a UA is not
required to render color on a monochrome monitor.)
An authoring tool is conformant to this specification
if it writes style sheets that are syntactically correct according to the
generic CSS grammar and the individual grammars of each feature in
this module, and meet all other conformance requirements of style sheets
as described in this module.
Partial implementations
So that authors can exploit the forward-compatible parsing rules to
assign fallback values, CSS renderers
must
treat as invalid (and
ignore
as appropriate
) any at-rules, properties, property values, keywords,
and other syntactic constructs for which they have no usable level of
support. In particular, user agents
must not
selectively
ignore unsupported component values and honor supported values in a single
multi-value property declaration: if any value is considered invalid
(as unsupported values must be), CSS requires that the entire declaration
be ignored.
Implementations of Unstable and Proprietary Features
To avoid clashes with future stable CSS features,
the CSSWG recommends
following best practices
for the implementation of
unstable
features and
proprietary extensions
to CSS.
Non-experimental implementations
Once a specification reaches the Candidate Recommendation stage,
non-experimental implementations are possible, and implementors should
release an unprefixed implementation of any CR-level feature they
can demonstrate to be correctly implemented according to spec.
To establish and maintain the interoperability of CSS across
implementations, the CSS Working Group requests that non-experimental
CSS renderers submit an implementation report (and, if necessary, the
testcases used for that implementation report) to the W3C before
releasing an unprefixed implementation of any CSS features. Testcases
submitted to W3C are subject to review and correction by the CSS
Working Group.
Further information on submitting testcases and implementation reports
can be found from on the CSS Working Group’s website at
Questions should be directed to the
public-css-testsuite@w3.org
mailing list.
Index
Terms defined by this specification
after
, in § 2.7.3
attr()
, in § 2.1
auto
, in § 2.4.1
before
, in § 2.7.3
bookmark-label
, in § 3.2
bookmark-level
, in § 3.1
bookmarks
, in § 3
bookmark-state
, in § 3.3
closed
, in § 3.3
close-quote
, in § 2.4.2
content
, in § 1
content()
, in § 2.7.3

type for content
, in § 1
value for bookmark-label
, in § 3.2

, in § 1
contents
, in § 2.3
dotted
, in § 2.5.1
entry value
, in § 2.7.2
exit value
, in § 2.7.2
first
, in § 2.7.2
first-except
, in § 2.7.2
first-letter
, in § 2.7.3

, in § 2.2

, in § 3.1
last
, in § 2.7.2
leader()
(function)
, in § 2.5.1
function for content,
, in § 2.5.1

, in § 2.5.1
marker
, in § 2.7.3
match-parent
, in § 2.4.1
named string
, in § 2.7
no-close-quote
, in § 2.4.2
none
value for bookmark-level
, in § 3.1
value for content
, in § 1
value for quotes
, in § 2.4.1
value for string-set
, in § 2.7.1
no-open-quote
, in § 2.4.2
normal
, in § 1
open
, in § 3.3
open-quote
, in § 2.4.2
quotation mark system
, in § 2.4.1

, in § 2.4.2
quote depth
, in § 2.4.2
quotes
, in § 2.4.1
solid
, in § 2.5.1
space
, in § 2.5.1
start
, in § 2.7.2

value for content,
, in § 2.1
value for leader()
, in § 2.5.1
string()
, in § 2.7.2
/ [ | | ]+
, in § 1
string-set
, in § 2.7.1

, in § 2.6
target-counter()
, in § 2.6.1
target-counters()
, in § 2.6.2
target-text()
, in § 2.6.3
text
, in § 2.7.3
Terms defined by reference
[CSS-CASCADE-5]
defines the following terms:
computed value
[CSS-CONTAIN-2]
defines the following terms:
style containment
[CSS-COUNTER-STYLES-3]
defines the following terms:

[CSS-DISPLAY-4]
defines the following terms:
display
[CSS-IMAGES-3]
defines the following terms:

natural dimension
[CSS-IMAGES-4]
defines the following terms:
invalid image
[CSS-LISTS-3]
defines the following terms:

[CSS-PSEUDO-4]
defines the following terms:
::after
::before
::file-selector-button
::first-letter
::marker
::placeholder
[CSS-TEXT-4]
defines the following terms:
content language
white space
[CSS-VALUES-4]
defines the following terms:




CSS-wide keywords
[CSS-VALUES-5]
defines the following terms:
attr()
[CSS3-NAMESPACE]
defines the following terms:
CSS qualified name
[HTML]
defines the following terms:
img
[SELECTORS-4]
defines the following terms:
:target
originating element
pseudo-elements
References
Normative References
[CSS-CASCADE-5]
Elika Etemad; Miriam Suzanne; Tab Atkins Jr..
CSS Cascading and Inheritance Level 5
. URL:
[CSS-CONTAIN-2]
Tab Atkins Jr.; Florian Rivoal; Vladimir Levin.
CSS Containment Module Level 2
. URL:
[CSS-COUNTER-STYLES-3]
Tab Atkins Jr..
CSS Counter Styles Level 3
. URL:
[CSS-DISPLAY-4]
Elika Etemad; Tab Atkins Jr..
CSS Display Module Level 4
. URL:
[CSS-IMAGES-3]
Tab Atkins Jr.; Elika Etemad; Lea Verou.
CSS Images Module Level 3
. URL:
[CSS-IMAGES-4]
Elika Etemad; Tab Atkins Jr.; Lea Verou.
CSS Images Module Level 4
. URL:
[CSS-LISTS-3]
Elika Etemad; Tab Atkins Jr..
CSS Lists and Counters Module Level 3
. URL:
[CSS-PSEUDO-4]
Elika Etemad; Alan Stearns.
CSS Pseudo-Elements Module Level 4
. URL:
[CSS-TEXT-4]
Elika Etemad; et al.
CSS Text Module Level 4
. URL:
[CSS-VALUES-3]
Tab Atkins Jr.; Elika Etemad.
CSS Values and Units Module Level 3
. URL:
[CSS-VALUES-4]
Tab Atkins Jr.; Elika Etemad.
CSS Values and Units Module Level 4
. URL:
[CSS-VALUES-5]
Tab Atkins Jr.; Elika Etemad; Miriam Suzanne.
CSS Values and Units Module Level 5
. URL:
[CSS2]
Bert Bos; et al.
Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification
. URL:
[CSS3-NAMESPACE]
Elika Etemad.
CSS Namespaces Module Level 3
. URL:
[CSS3-SPEECH]
Léonie Watson; Elika Etemad.
CSS Speech Module Level 1
. URL:
[HTML]
Anne van Kesteren; et al.
HTML Standard
. Living Standard. URL:
[RFC2119]
S. Bradner.
Key words for use in RFCs to Indicate Requirement Levels
. March 1997. Best Current Practice. URL:
[SELECTORS-4]
Elika Etemad; Tab Atkins Jr..
Selectors Level 4
. URL:
Non-Normative References
[CLDR]
Unicode Common Locale Data Repository
. URL:
[CSS-TEXT-3]
Elika Etemad; Koji Ishii; Florian Rivoal.
CSS Text Module Level 3
. URL:
[DOM]
Anne van Kesteren.
DOM Standard
. Living Standard. URL:
Property Index
Name
Value
Initial
Applies to
Inh.
%ages
Anim­ation type
Canonical order
Com­puted value
bookmark-label

content(text)
all elements
no
N/A
discrete
per grammar
specified value
bookmark-level
none |
none
all elements
no
N/A
by computed value type
per grammar
the keyword none or the specified integer
bookmark-state
open | closed
open
block-level elements
no
N/A
discrete
per grammar
specified keyword
content
normal | none | [ | ] [/ [ | | ]+ ]?
normal
all elements, tree-abiding pseudo-elements, and page margin boxes
no
n/a
discrete
per grammar
See prose below
quotes
auto | none | match-parent | [ ]+
auto
all elements
yes
n/a
discrete
per grammar
the keyword none, the keyword auto or match-parent, or a list, each item a pair of string values
string-set
none | [ + ]#
none
all elements, but not pseudo-elements
no
N/A
discrete
per grammar
the keyword none or a list, each item an identifier paired with a list of string values
Issues Index
The above
invalid image
behavior appears to be what Chrome is doing.
Is this okay?
Is there a better behavior we can/should use?
This value has historically been treated as

on
::before
and
::after
Presumably there’s a Web-compat requirement on this,
so these pseudo-elements might need an exception.
[Issue #2889]
Should the contents keyword be replaced with
content()
Start work on an AAM for CSS.
CSS2.1 explicitly allowed the UA to substitute a broken image icon
if the image was invalid.
However, no browser appears to do this.
Is this removal okay?
Should this behave as an empty string on pseudo-elements?
Use cases for suppressing the content on the element and using it in a pseudo-element would be welcome.
Do we need the statement about marker pseudo-elements here? Or is this legacy from the old version of the spec?
Two possible approaches here, currently speccing the latter:
a) this computes to the relevant string values, and inherits as such.
b) this value effectively inherits as a keyword + a language code,
meaning
auto
, but with this language.
Do leaders depend on the assumption that the content after the leader is right-aligned (end-aligned)?
what to do if
after content
is wider than the line box?
Leaders don’t quite work in table layouts. How can we fix this?
what should error handling be?
restrict syntactically to local references for now.
found a compelling example, in CSS specs. Do something.
A simpler syntax has been proposed by fantasai:
we may need to kill the entire content string. Is this necessary?
Should this move back to CSS Content?
Should a bookmark be created for elements with
display
none
Is the initial bookmark state,
or the bookmark state updated by the UA as appropriate?
MDN
content
In all current engines.
Firefox
1+
Safari
1+
Chrome
1+
Opera
4+
Edge
79+
Edge (Legacy)
12+
IE
8+
Firefox for Android
iOS Safari
Chrome for Android
Android WebView
Samsung Internet
Opera Mobile
10.1+
MDN
quotes
In all current engines.
Firefox
1.5+
Safari
9+
Chrome
11+
Opera
4+
Edge
79+
Edge (Legacy)
12+
IE
8+
Firefox for Android
iOS Safari
Chrome for Android
Android WebView
37+
Samsung Internet
Opera Mobile