Once a user agent has parsed a document and constructed a document tree, it must assign, for
every element in the tree, a value to every property that applies to the
target media type.

The final value of a property is the result of a four-step
calculation: the value is determined through specification (the
"specified value"), then resolved into a value that is used for
inheritance (the "computed value"), then converted into an absolute
value if necessary (the "used value"), and finally transformed
according to the limitations of the local environment (the "actual
value").

Specified values are resolved to computed values during the cascade;
for example URIs are made absolute and 'em' and 'ex'
units are computed to pixel or absolute lengths. Computing a value
never requires the user agent to render the document.

The computed value of URIs that the UA cannot resolve to absolute
URIs is the specified value.

The computed value of a
property is determined as specified by the Computed Value line in the
definition of the
property. See the section on inheritance
for the definition of computed values when the specified value is
'inherit'.

The computed value exists even when the property does not apply, as
defined by the 'Applies To' line.
However, some
properties may define the computed value of a property for an element
to depend on whether the property applies to that element.

Computed values are processed as far as possible without formatting
the document. Some values, however, can only be determined when the
document is being laid out. For example, if the width of an element is
set to be a certain percentage of its containing block, the width
cannot be determined until the width of the containing block has been
determined. The used value is the result of
taking the computed value and resolving any remaining dependencies
into an absolute value.

A used value is in principle the value used for rendering, but a
user agent may not be able to make use of the value in a given
environment. For example, a user agent may only be able to render
borders with integer pixel widths and may therefore have to
approximate the computed width, or the user agent may be forced to
use only black and white shades instead of full color. The actual
value is the used value after any approximations have been applied.

Some values are inherited by the children of an element in the document tree, as described above. Each property defines whether it is inherited or
not.

Suppose there is an H1 element with an emphasizing element (EM)
inside:

<H1>The headline <EM>is</EM> important!</H1>

If no color has been assigned to the EM element, the emphasized
"is" will inherit the color of the parent element, so if H1 has the
color blue, the EM element will likewise be in blue.

When inheritance occurs, elements inherit computed values. The
computed value from the parent element becomes both the specified
value and the computed value on the child.

Example(s):

For example, given the following style sheet:

body { font-size: 10pt }
h1 { font-size: 130% }

and this document fragment:

<BODY>
<H1>A <EM>large</EM> heading</H1>
</BODY>

the 'font-size' property
for the H1 element will have the computed value '13pt' (130% times
10pt, the parent's value). Since the computed value of 'font-size' is inherited, the EM
element will have the computed value '13pt' as well. If the
user agent does not have the 13pt font available, the
actual value of 'font-size'
for both H1 and EM might be, for example, '12pt'.

Note that inheritance follows the document tree and is
not intercepted by anonymous boxes.

Each property may also have a cascaded value of 'inherit', which
means that, for a given element, the property takes the same specified
value as the property for the element's parent. The 'inherit' value
can be used to enforce inheritance of values, and it can also be used on
properties that are not normally inherited.

If the 'inherit' value is set on the root element, the property is
assigned its initial value.

Example(s):

In the example below, the 'color' and 'background' properties are set on
the BODY element. On all other elements, the 'color' value will be
inherited and the background will be transparent. If these rules are
part of the user's style sheet, black text on a white background will
be enforced throughout the document.

The '@import' rule allows users to
import style rules from other style sheets. In CSS 2.1, any
@import rules must precede all other rules (except the @charset rule,
if present). See the section on
parsing for when user agents must ignore @import rules. The
'@import' keyword must be followed by the URI of the style sheet to
include. A string is also allowed; it will be interpreted as if it had
url(...) around it.

Example(s):

The following lines are equivalent in meaning and illustrate both
'@import' syntaxes (one with "url()" and one with a bare string):

Style sheets may have three different origins: author, user, and
user agent.

Author. The author specifies style sheets
for a source document according to the conventions of the document
language. For instance, in HTML, style sheets may be included in the
document or linked externally.

User: The user may be able to specify style
information for a particular document. For example, the user may
specify a file that contains a style sheet or the user agent may
provide an interface that generates a user style sheet (or behaves as
if it did).

User agent: Conforming user agents must apply
a default style sheet
(or behave as if they did). A user agent's default style sheet should
present the
elements of the document language in ways that satisfy general
presentation expectations for the document language (e.g., for visual
browsers, the EM element in HTML is presented using an italic
font). See A sample style sheet for HTML
for a recommended default style sheet for HTML documents.

Note that the user may modify system settings (e.g.,
system colors) that affect the default style sheet. However, some user
agent implementations make it impossible to change the values in the
default style sheet.

Style sheets from these three origins will overlap in scope, and
they interact according to the cascade.

The CSS cascade
assigns a weight to each style rule. When several rules apply, the one
with the greatest weight takes precedence.

By default, rules in author style sheets have more weight than
rules in user style sheets. Precedence is reversed, however, for
"!important" rules. All user and author rules have more weight
than rules in the UA's default style sheet.

To find the value for an element/property combination, user agents
must apply the following sorting order:

Find all declarations that apply to the element and property in
question, for the target media type.
Declarations apply if the associated selector matches the element in question and the
target medium matches the media list on all @media rules
containing the declaration and on all links on the path through
which the style sheet was reached.

Sort according to importance (normal or important)
and origin (author, user, or user agent). In ascending order of
precedence:

user agent declarations

user normal declarations

author normal declarations

author important declarations

user important declarations

Sort rules with the same importance and origin by specificity
of selector: more specific
selectors will override more general ones. Pseudo-elements and
pseudo-classes are counted as normal elements and classes,
respectively.

Finally, sort by order specified: if two declarations have the
same weight, origin and specificity, the latter specified wins.
Declarations in imported style sheets are considered to be before any
declarations in the style sheet itself.

Apart from the "!important" setting on individual declarations,
this strategy gives author's style sheets higher weight than those of
the reader. User agents must give the user the ability to turn off the
influence of specific author style sheets, e.g., through a pull-down
menu. Conformance to UAAG 1.0 checkpoint 4.14 satisfies this condition [UAAG10].

The first rule in the user's style sheet in the following example
contains an "!important" declaration, which overrides the corresponding
declaration in the author's style sheet. The second declaration
will also win due to being marked "!important". However, the third
rule in the user's style sheet is not "!important" and will therefore
lose to the second rule in the author's style sheet (which happens to
set style on a shorthand property). Also, the third author rule will
lose to the second author rule since the second rule is
"!important". This shows that "!important" declarations have a
function also within author style sheets.

count 1 if the declaration is from is a 'style' attribute rather
than a rule with a
selector, 0 otherwise (= a) (In HTML, values of an element's "style"
attribute are style sheet rules. These rules have no selectors, so
a=1, b=0, c=0, and d=0.)

count the number of ID attributes in the selector (= b)

count the number of other attributes and pseudo-classes
in the selector (= c)

count the number of element names and pseudo-elements in the selector (= d)

The specificity is based only on the form of the selector. In
particular, a selector of the form "[id=p33]" is counted as an
attribute selector (a=0, b=0, c=1, d=0), even if the id attribute is
defined as an "ID" in the source document's DTD.

Concatenating the four numbers a-b-c-d (in a number system with a large
base) gives the specificity.

In the above example, the color of the P element would be
green. The declaration in the "style" attribute will override the one in
the STYLE element because of cascading rule 3, since it has a higher
specificity.

The UA may choose to honor presentational attributes in an HTML source
document. If so, these attributes are translated to the corresponding
CSS rules with specificity equal to 0, and are treated as if they were
inserted at the start of the author style sheet. They may therefore be
overridden by subsequent style sheet rules. In a transition phase,
this policy will make it easier for stylistic attributes to coexist
with style sheets.

For other languages, all document language-based styling must be
translated to the corresponding CSS and either enter the cascade at
the user agent level or, as with HTML presentational hints, be treated
as author level rules with a specificity of zero placed at the start
of the author style sheet.

Example(s):

The following user style sheet would override the font weight of
'b' elements in all documents, and the color of 'font'
elements with color attributes in XML documents. It would not affect
the color of any 'font' elements with color attributes in HTML
documents:

b { font-weight: normal; }
font[color] { color: orange; }

The following, however, would override the color of font elements in all documents: