8000 csswg-drafts/css-values/Overview.bs at c3a09de917dc034fa39071077ed57453d6ef0441 · w3c/csswg-drafts · GitHub
Skip to content
8000

Latest commit

 

History

History
2130 lines (1755 loc) · 85.7 KB

File metadata and controls

2130 lines (1755 loc) · 85.7 KB
<h1>CSS Values and Units Module Level 3</h1>
<pre class='metadata'>
Group: CSSWG
Shortname: css-values
Level: 3
Status: ED
Work Status: Testing
ED: http://dev.w3.org/csswg/css-values/
TR: http://www.w3.org/TR/css-values/
Previous Version: http://www.w3.org/TR/2015/CR-css-values-3-20150611/
Previous Version: http://www.w3.org/TR/2013/CR-css3-values-20130730/
Previous Version: http://www.w3.org/TR/2013/CR-css3-values-20130404/
Previous Version: http://www.w3.org/TR/2012/CR-css3-values-20120828/
Previous Version: http://www.w3.org/TR/2012/WD-css3-values-20120308/
Previous Version: http://www.w3.org/TR/2011/WD-css3-values-20110906/
Previous Version: http://www.w3.org/TR/2006/WD-css3-values-20060919
Previous Version: http://www.w3.org/TR/2005/WD-css3-values-20050726
Previous Version: http://www.w3.org/TR/2001/WD-css3-values-20010713/
Editor: Tab Atkins, Google, http://xanthir.com/contact/
Editor: fantasai, http://fantasai.inkedblade.net/contact
Former Editor: Håkon Wium Lie, Opera Software, howcome@opera.com
Abstract: This CSS3 module describes the common values and units that CSS properties accept and the syntax used for describing them in CSS property definitions.
Issue Tracking: Tracker http://www.w3.org/Style/CSS/Tracker/products/33
At Risk: ''toggle()'', ''attr()''
Ignored Terms: <spacing-limit>, containing block
Ignored Vars: Cn+1, n
</pre>
<pre class='link-defaults'>
spec: css-backgrounds-3; type: type; text: <position>
spec: css21; type: property; text: border-collapse
spec: css-color-4; type: value; text: currentcolor
</pre>
<style>
code, small { white-space: nowrap }
pre.value { font: inherit; white-space: pre-wrap; margin: 0; padding: 0; }
#propvalues td { text-align: right; }
#propvalues td + td { text-align: left; }
dt + dt::before { content: ", "; }
dt { display: inline; }
td > small { display: block; }
</style>
<h2 id="intro">
Introduction</h2>
The value definition field of each CSS property can contain keywords,
data types (which appear between ''&lt;'' and ''>''), and information on how
they can be combined.
Generic data types (<<length>> being the most widely used)
that can be used by many properties are described in this specification,
while more specific data types (e.g., <<spacing-limit>>)
are described in the corresponding modules.
<h3 id="placement">
Module Interactions</h3>
This module replaces and extends the data type definitions in [[!CSS21]]
sections
<a href="http://www.w3.org/TR/CSS21/about.html#value-defs">1.4.2.1</a>,
<a href="http://www.w3.org/TR/CSS21/syndata.html#values">4.3</a>,
and <a href="http://www.w3.org/TR/CSS21/aural.html#aural-intro">A.2</a>.
<!--
██████ ██ ██ ██ ██ ████████ ███ ██ ██
██ ██ ██ ██ ███ ██ ██ ██ ██ ██ ██
██ ████ ████ ██ ██ ██ ██ ██ ██
██████ ██ ██ ██ ██ ██ ██ ██ ███
██ ██ ██ ████ ██ █████████ ██ ██
██ ██ ██ ██ ███ ██ ██ ██ ██ ██
██████ ██ ██ ██ ██ ██ ██ ██ ██
-->
<h2 id="value-defs">
Value Definition Syntax</h2>
The syntax described here is used to define the set of valid values
for CSS properties. A property value can have one or more components.
<h3 id="component-types">
Component value types</h3>
Component value types are designated in several ways:
<ol>
<li>
<a href="#keywords">keyword</a> values (such as <css>auto</css>, ''disc'', etc.),
which appear literally, without quotes (e.g. <code>auto</code>)
<li>
basic data types, which appear between ''&lt;'' and ''>''
(e.g., <<length>>, <<percentage>>, etc.).
<li>
types that have the same range of values as a property bearing the same name
(e.g., <<'border-width'>>, <<'background-attachment'>>, etc.).
In this case, the type name is the property name (complete with quotes) between the brackets.
Such a type does <em>not</em> include <a href="#common-keywords">CSS-wide keywords</a> such as ''inherit''.
<li>
non-terminals that do not share the same name as a property.
In this case, the non-terminal name appears between ''&lt;'' and ''>'',
as in <<spacing-limit>>.
Notice the distinction between <<border-width>> and <<'border-width'>>:
the latter is defined as the value of the 'border-width' property,
the former requires an explicit expansion elsewhere.
The definition of a non-terminal is typically located near its first appearance in the specification.
</ol>
Some property value definitions also include the slash (/),
the comma (,),
and/or parentheses as literals.
These represent their corresponding tokens.
Other non-keyword literal characters that may appear in a component value,
such as “+”,
must be written enclosed in single quotes.
<dfn lt="," id='comb-comma' export grammar>Commas</dfn> specified in the grammar are <strong>implicitly omittable</strong> in some circumstances,
when used to separate optional terms in the grammar.
Within a top-level list in a property or other CSS value,
or a function's argument list,
a comma specified in the grammar must be omitted if:
<ul>
<li>
all items preceding the comma have been omitted
<li>
all items following the comma have been omitted
<li>
multiple commas would be adjacent (ignoring whitespace/comments),
due to the items between the commas being omitted.
</ul>
<div class='example'>
For example, if a function can accept three arguments in order,
but all of them are optional,
the grammar can be written like:
<pre class='prod'>
example( first? , second? , third? )
</pre>
Given this grammar,
writing ''example(first, second, third)'' is valid,
as is ''example(first, second)'' or ''example(first, third)'' or ''example(second)''.
However, ''example(first, , third)'' is invalid, as one of those commas are no longer separating two options;
similarly, ''example(,second)'' and ''example(first,)'' are invalid.
''example(first second)'' is also invalid,
as commas are still required to actually separate the options.
If commas were not implicitly omittable,
the grammar would have to be much more complicated
to properly express the ways that the arguments can be omitted,
greatly obscuring the simplicity of the feature.
</div>
All CSS properties also accept the <a href="#common-keywords">CSS-wide keyword values</a>
as the sole component of their property value.
For readability these are not listed explicitly in the property value syntax definitions.
For example, the full value definition of 'border-color'
is <code>&lt;color>{1,4} | inherit | initial | unset</code>
(even though it is listed as <code>&lt;color>{1,4}</code>).
Note: This implies that, in general,
combining these keywords with other component values in the same declaration
results in an invalid declaration.
For example,
''background: url(corner.png) no-repeat, inherit;'' is invalid.
<h3 id="component-combinators">
Component value combinators</h3>
Component values can be arranged into property values as follows:
<ul export dfn-type="grammar">
<li>Juxtaposing components means that
8096
all of them must occur, in the given order.
<li>A double ampersand (<dfn id='comb-all'>&&</dfn>) separates two or more components,
all of which must occur, in any order.
<li>A double bar (<dfn id='comb-any'>||</dfn>) separates two or more options:
one or more of them must occur, in any order.
<li>A bar (<dfn id='comb-one'>|</dfn>) separates two or more alternatives:
exactly one of them must occur.
<li>Brackets ([&nbsp;]) are for grouping.
</ul>
Juxtaposition is stronger than the double ampersand, the double
ampersand is stronger than the double bar, and the double bar
is stronger than the bar. Thus, the following lines are equivalent:
<pre>
a b | c || d && e f
[ a b ] | [ c || [ d && [ e f ]]]
</pre>
For re-orderable combinators (||, &&),
ordering of the grammar does not matter:
components in the same grouping may be interleaved in any order.
Thus, the following lines are equivalent:
<pre>
a || b || c
b || a || c
</pre>
<h3 id="component-multipliers">
Component value multipliers</h3>
Every type, keyword, or bracketed group may be followed by one of
the following modifiers:
<ul export dfn-type="grammar">
<li>An asterisk (<dfn id='mult-zero-plus'>*</dfn>) indicates that the preceding type, word, or
group occurs zero or more times.
<li>A plus (<dfn id='mult-one-plus'>+</dfn>) indicates that the preceding type, word, or group
occurs one or more times.
<li>A question mark (<dfn id='mult-opt'>?</dfn>) indicates that the preceding type, word, or
group is optional (occurs zero or one times).
<li>A single number in curly braces (<dfn id='mult-num'>{<var>A</var>}</dfn>)
indicates that the preceding type, word, or group occurs <var>A</var> times.
<li>A comma-separated pair of numbers in curly braces (<dfn id='mult-num-range'>{<var>A</var>,<var>B</var>}</dfn>)
indicates that the preceding type, word, or group occurs at least
<var>A</var> and at most <var>B</var> times.
The <var>B</var> may be omitted ({<var>A</var>,})
to indicate that there must be at least <var>A</var> repetitions,
with no upper bound on the number of repetitions.
<li>A hash mark (<dfn id='mult-comma'>#</dfn>) indicates that the preceding type, word, or
group occurs one or more times, separated by comma tokens
(which may optionally be surrounded by white space and/or comments).
It may optionally be followed by the curly brace forms, above,
to indicate precisely how many times the repetition occurs,
like ''&lt;length>#{1,4}''.
<li>An exclamation point (<dfn id='mult-req'>!</dfn>) after a group indicates that the group is required
and must produce at least one value;
even if the grammar of the items within the group would otherwise allow the entire contents to be omitted,
at least one component value must not be omitted.
</ul>
For repeated component values (indicated by ''*'', ''+'', or ''#''),
UAs must support at least 20 repetitions of the component.
If a property value contains more than the supported number of repetitions,
the declaration must be ignored as if it were invalid.
<h3 id='combinator-multiplier-patterns'>
Combinator and Multiplier Patterns</h3>
There are a small set of common ways to combine multiple independent <a>component values</a> in particular numbers and orders.
In particular, it's common to want to express that,
from a set of component value,
the author must select zero or more, one or more, or all of them,
and in either the order specified in the grammar or in any order.
All of these can be easily expressed using simple patterns of <a href="#component-combinators">combinators</a> and <a href="#component-multipliers">multipliers</a>:
<table class='data'>
<thead>
<tr>
<th>
<th>in order
<th>any order
<tbody>
<tr>
<th>zero or more
<td><pre>A? B? C?</pre>
<td><pre> A? || B? || C?</pre>
<tr>
<th>one or more
<td><pre> [ A? B? C? ]!</pre>
<td><pre>A || B || C</pre>
<tr>
<th>all
<td><pre>A B C </pre>
<td><pre>A && B && C</pre>
</table>
Note that all of the "any order" possibilities are expressed using combinators,
while the "in order" possibilities are all variants on juxtaposition.
<h3 id="component-whitespace">
Component values and white space</h3>
Unless otherwise specified,
white space and/or comments may appear before, after, and/or between
components combined using the above
<a href="#component-combinators">combinators</a> and
<a href="#component-multipliers">multipliers</a>.
Note: In many cases, spaces will in fact be <em>required</em> between components
in order to distinguish them from each other.
For example, the value ''1em2em'' would be parsed as a single <<dimension-token>>
with the number ''1'' and the identifier ''em2em'',
which is an invalid unit.
In this case, a space would be required before the ''2''
to get this parsed as the two lengths ''1em''and ''2em''.
<h3 id="value-examples">
Property value examples</h3>
Below are some examples of properties with their corresponding value
definition fields
<div class=example>
<table class="data" id="propvalues">
<thead>
<tr><th>Property
<th>Value definition field
<th>Example value
</thead>
<tbody>
F882
<tr><td>'orphans'
<td>&lt;integer>
<td>''3''
<tr><td>'text-align'
<td>left | right | center | justify
<td>''text-align/center''
<tr><td>'padding-top'
<td>&lt;length> | &lt;percentage>
<td>''5%''
<tr><td>'outline-color'
<td>&lt;color> | invert
<td>''#fefefe''
<tr><td>'text-decoration'
<td>none | underline || overline || line-through || blink
<td>''overline underline''
<tr><td><a property>font-family</a>
<td>[ &lt;family-name> | &lt;generic-family> ]#
<td>''"Gill Sans", Futura, sans-serif''
<tr><td>'border-width'
<td>[ &lt;length> | thick | medium | thin ]{1,4}
<td>''2px medium 4px''
<tr><td>'text-shadow'
<td>[ inset? && [ &lt;length>{2,4} && &lt;color>? ] ]# | none
<td>''3px 3px rgba(50%, 50%, 50%, 50%), lemonchiffon 0 0 4px inset''
</tbody>
</table>
</div>
<h2 id="textual-values">
Textual Data Types</h2>
An <dfn>identifier</dfn> is a sequence of characters conforming to the <<ident-token>> grammar. [[!CSS3SYN]]
Identifiers cannot be quoted;
otherwise they would be interpreted as a string.
<!--
██ ██ ████████ ██ ██ ██ ██ ███████ ████████ ████████ ██████
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ██ ██ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
█████ ██████ ██ ██ ██ ██ ██ ██ ████████ ██ ██ ██████
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ██ ████████ ██ ███ ███ ███████ ██ ██ ████████ ██████
-->
<h3 id="keywords">
Pre-defined Keywords</h3>
In the value definition fields,
keywords with a pre-defined meaning appear literally.
Keywords are CSS <a>identifiers</a>
and are interpreted <a lt="ASCII case-insensitive">ASCII case-insensitively</a>
(i.e., \[a-z] and \[A-Z] are equivalent).
<div class="example">
For example, here is the value definition for the 'border-collapse'
property:
<pre>Value: collapse | separate</pre>
And here is an example of its use:
<pre>table { border-collapse: separate }</pre>
</div>
<h4 id="common-keywords">
CSS-wide keywords: ''initial'', ''inherit'' and ''unset''</h4>
As defined <a href="#component-types">above</a>,
all properties accept the <dfn export>CSS-wide keywords</dfn>,
which represent value computations common to all CSS properties.
The ''initial'' keyword represents the value specified as the property's initial value.
The ''inherit'' keyword represents the computed value of the property on the element's parent.
The ''unset'' keyword acts as either ''inherit'' or ''initial'',
depending on whether the property is inherited or not.
All of these keywords are normatively defined in the Cascade module. [[!CSS3CASCADE]]
Other CSS specifications can define additional CSS-wide keywords.
<!-- Make it easier to add CSS-wide keywords by defining a grammar production. -->
<h3 id='custom-idents'>
Author-defined Identifiers: the <<custom-ident>> type</h3>
Some properties accept arbitrary author-defined identifiers as a component value.
This generic data type is denoted by <dfn id="identifier-value">&lt;custom-ident></dfn>,
and represents any valid CSS <a>identifier</a>
that would not be misinterpreted as a pre-defined keyword in that property's value definition.
Such identifiers are fully case-sensitive,
even in the ASCII range
(e.g. ''example'' and ''EXAMPLE'' are two different, unrelated user-defined identifiers).
The <a>CSS-wide keywords</a> are not valid <<custom-ident>>s.
The ''default'' keyword is reserved
and is also not a valid <<custom-ident>>.
Specifications using <<custom-ident>> must specify clearly
what other keywords are excluded from <<custom-ident>>, if any--
for example by saying that any pre-defined keywords in that property's value definition are excluded.
Excluded keywords are excluded in all <a lt="ASCII case-insensitive">ASCII case permutations</a>.
When parsing positionally-ambiguous keywords in a property value,
a <<custom-ident>> production can only claim the keyword if no other unfulfilled production can claim it.
<div class="example">
For example, the shorthand declaration ''animation: ease-in ease-out''
is equivalent to the longhand declarations
''animation-timing-function: ease-in; animation-name: ease-out;''.
''ease-in'' is claimed by the <<single-timing-function>> production belonging to 'animation-timing-function',
leaving ''ease-out'' to be claimed by the <<custom-ident>> production belonging to 'animation-name'.
</div>
Note: When designing grammars with <<custom-ident>>,
the <<custom-ident>> should always be "positionally unambiguous",
so that it's impossible to conflict with any keyword values in the property.
<!--
██████ ████████ ████████ ████ ██ ██ ██████
██ ██ ██ ██ ██ ██ ███ ██ ██ ██
██ ██ ██ ██ ██ ████ ██ ██
██████ ██ ████████ ██ ██ ██ ██ ██ ████
██ ██ ██ ██ ██ ██ ████ ██ ██
██ ██ ██ ██ ██ ██ ██ ███ ██ ██
██████ ██ ██ ██ ████ ██ ██ ██████
-->
<h3 id="strings">
Quoted Strings: the <<string>> type</h3>
<dfn export lt="string">Strings</dfn> are denoted by <dfn id="string-value">&lt;string></dfn>
and consist of a sequence of characters delimited by double quotes or
single quotes. They correspond to the <<string-token>> production
in the <a href="http://www.w3.org/TR/css-syntax/">CSS Syntax Module</a> [[!CSS3SYN]].
<div class=example>
Double quotes cannot occur inside double quotes, unless
<a href="http://www.w3.org/TR/CSS21/syndata.html#escaped-characters">escaped</a>
(as <code>"\""</code> or as <code>"\22"</code>).
Analogously for single quotes (<code>&#39;\&#39;&#39;</code> or <code>&#39;\27&#39;</code>).
<pre>
content: "this is a &#39;string&#39;.";
content: "this is a \"string\".";
content: &#39;this is a "string".&#39;;
content: &#39;this is a \&#39;string\&#39;.&#39;
</pre>
</div>
It is possible to break strings over several lines, for aesthetic or
other reasons, but in such a case the newline itself has to be escaped
with a backslash (\). The newline is subsequently removed from the
string. For instance, the following two selectors are exactly the
same:
<div class="example">
<p style="display:none">Example(s):
<pre>
a[title="a not s\
o very long title"] {/*...*/}
a[title="a not so very long title"] {/*...*/}
</pre>
</div>
Since a string cannot directly represent a newline, to include a
newline in a string, use the escape "\A". (Hexadecimal A is the line
feed character in Unicode (U+000A), but represents the generic notion
of "newline" in CSS.)
<!--
██ ██ ████████ ██
██ ██ ██ ██ ██
██ ██ ██ ██ ██
██ ██ ████████ ██
██ ██ ██ ██ ██
██ ██ ██ ██ ██
███████ ██ ██ ████████
-->
<h3 id="urls">
Resource Locators: the <<url>> type</h3>
A <dfn>URL</dfn> is a pointer to a resource
and is a <a href="#functional-notation">functional notation</a>
denoted by <<url>>.
The syntax of a <<url>> is:
<pre class="prod"><dfn id="url-value">&lt;url></dfn> = url( <<string>> <<url-modifier>>* )</pre>
<div class="example">
Below is an example of a URL being used as a background image:
<pre>body { background: url("http://www.example.com/pinkish.gif") }</pre>
</div>
In addition to the syntax defined above,
a <<url>> can sometimes be written in other ways:
* For legacy reasons,
a <<url>> can be written without quotation marks around the URL itself.
This syntax is <a lt="consume a url token" spec=css-syntax-3>specially-parsed</a>,
and produces a <<url-token>> rather than a <a>function</a> syntactically. [[!CSS3SYN]]
* Some CSS contexts, such as ''@import'', allow a <<url>> to be represented by a <<string>> instead.
This behaves identically to writing a ''url()'' function containing that string.
Because these alternate ways of writing a <<url>> are not <a>functional notations</a>,
they cannot accept any <<url-modifier>>s.
Note: The special parsing rules for the legacy quotation mark-less <<url>> syntax
means that parentheses, whitespace characters, single quotes (&#39;) and double quotes (") appearing in a URL
must be escaped with a backslash,
e.g. ''url(open\(parens)'', ''url(close\)parens)''.
Depending on the type of URL,
it might also be possible to write these characters as URL-escapes
(e.g. ''url(open%28parens)'' or ''url(close%29parens)'')
as described in [[URL]].
(If written as a normal function containing a string, ordinary string escaping rules apply;
only newlines and the character used to quote the string need to be escaped.)
<h4 id="relative-urls">
Relative URLs</h4>
In order to create modular style sheets that are not dependent on
the absolute location of a resource, authors should use relative URLs.
Relative URLs (as defined in [[!URL]]) are resolved to full URLs
using a base URL. RFC&nbsp;3986, section&nbsp;3, defines the normative
algorithm for this process.
For CSS style sheets, the base URL is that of the style sheet itself,
not that of the styled source document.
Style sheets embedded within a document have
the base URL associated with their container.
When a <<url>> appears in the computed value of a property,
it is resolved to an absolute URL,
as described in the preceding paragraph.
The computed value of a URL that the UA cannot resolve to an absolute URL is the specified value.
<div class="example">
For example, suppose the following rule:
<pre>body { background: url("tile.png") }</pre>
is located in a style sheet designated by the URL:
<pre>http://www.example.org/style/basic.css</pre>
The background of the source document's <code>&lt;body></code>
will be tiled with whatever image is described by the resource designated by the URL:
<pre>http://www.example.org/style/tile.png</pre>
The same image will be used regardless of the URL of the source document containing the <code>&lt;body></code>.
</div>
<h4 id='url-modifiers'>
URL Modifiers</h4>
The ''url()'' function supports specifying additional <dfn>&lt;url-modifier></dfn>s,
which change the meaning or the interpretation of the URL somehow.
A <<url-modifier>> is either an <<ident>> or a <a>function</a>.
This specification does not define any <<url-modifier>>s,
but other specs may do so.
<h2 id="numeric-types">
Numeric Data Types</h2>
Properties may restrict numeric values to some range.
If the value is outside the allowed range,
the declaration is invalid and must be <a href="http://www.w3.org/TR/CSS21/conform.html#ignore">ignored</a>.
CSS theoretically supports infinite precision and infinite ranges for all value types;
however in reality implementations have finite capacity.
UAs should support reasonably useful ranges and precisions.
<!--
The recommended minimum ranges and precision,
and the required rounding and clamping rules,
are given in <a href="#required-ranges">Appendix A</a>.
-->
<!--
████ ██ ██ ████████ ████████ ██████ ████████ ████████
██ ███ ██ ██ ██ ██ ██ ██ ██ ██
██ ████ ██ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██████ ██ ████ ██████ ████████
██ ██ ████ ██ ██ ██ ██ ██ ██ ██
██ ██ ███ ██ ██ ██ ██ ██ ██ ██
████ ██ ██ ██ ████████ ██████ ████████ ██ ██
-->
<h3 id="integers">
Integers: the <<integer>> type</h3>
Integer values are denoted by <dfn id="integer-value">&lt;integer></dfn>.
An <dfn>integer</dfn> is one or more decimal digits ''0'' through ''9''
and corresponds to a subset of the <<number-token>> production
in the CSS Syntax Module [[!CSS3SYN]].
The first digit of an integer may be immediately preceded by ''-'' or ''+''
to indicate the integer's sign.
<!--
██ ██ ██ ██ ██ ██ ████████ ████████ ████████
███ ██ ██ ██ ███ ███ ██ ██ ██ ██ ██
████ ██ ██ ██ ████ ████ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ███ ██ ████████ ██████ ████████
██ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ███ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ██ ███████ ██ ██ ████████ ████████ ██ ██
-->
<h3 id="numbers">
Real Numbers: the <<number>> type</h3>
Number values are denoted by <dfn id="number-value">&lt;number></dfn>.
A <dfn>number</dfn> is either an <<integer>>
or zero or more decimal digits followed by a dot (.) followed by one or more decimal digits
and optionally an exponent composed of "e" or "E" and an integer.
It corresponds to the <<number-token>> production
in the <a href="http://www.w3.org/TR/css-syntax/">CSS Syntax Module</a> [[!CSS3SYN]].
As with integers, the first character of a number may be immediately preceded by ''-'' or ''+''
to indicate the number's sign.
<!--
█████ ██
██ ██ ██
█████ ██
██
██ █████
██ ██ ██
██ █████
-->
<h3 id="percentages">
Percentages: the <<percentage>> type</h3>
A <dfn>percentage</dfn> value is denoted by
<dfn id="percentage-value">&lt;percentage></dfn>,
and consists of a <<number>>
immediately followed by a percent sign ''%''.
It corresponds to the <<percentage-token>> production
in the <a href="http://www.w3.org/TR/css-syntax/">CSS Syntax Module</a> [[!CSS3SYN]].
Percentage values are often relative to another value,
for example a length.
Each property that allows percentages also defines the value to which the percentage refers.
The value may be that of another property for the same element,
a property for an ancestor element,
or a value of the formatting context
< 9E70 div>
(e.g., the width of a <a>containing block</a>).
While such "relative" percentages are often indicated in prose,
they can also be indicated with an explicit grammar term,
one for each basic <a>dimension</a> type:
: <dfn>&lt;length-percentage></dfn>
:: Equivalent to <code class=prod>[ <<length>> | <<percentage>> ]</code>,
where the <<percentage>> will resolve to a <<length>>.
: <dfn>&lt;frequency-percentage></dfn>
:: Equivalent to <code class=prod>[ <<frequency>> | <<percentage>> ]</code>,
where the <<percentage>> will resolve to a <<frequency>>.
: <dfn>&lt;angle-percentage></dfn>
:: Equivalent to <code class=prod>[ <<angle>> | <<percentage>> ]</code>,
where the <<percentage>> will resolve to an <<angle>>.
: <dfn>&lt;time-percentage></dfn>
:: Equivalent to <code class=prod>[ <<time>> | <<percentage>> ]</code>,
where the <<percentage>> will resolve to a <<time>>.
: <dfn>&lt;number-percentage></dfn>
:: Equivalent to <code class=prod>[ <<number>> | <<percentage>> ]</code>,
where the <<percentage>> will resolve to a <<number>>.
<div class="example">
For example, in the 'width' property <<percentage>> values are relative to the width of the containing block.
If the containing block is ''1000px'' wide,
then ''width: 500px;'' and ''width: 50%'' have the exact same behavior.
This means that ''width: calc(500px + 50%);'' is allowed--
it has the same behavior as ''width: calc(500px + 500px)'',
which is an easy length+length calculation.
On the other hand, the second and third arguments of the ''hsl()'' function are bare <<percentage>>s,
not relative to any other value.
They cannot be combined with anything in ''calc()''
(except themselves, in useless expressions like ''calc(10% + 20%)'').
An exceptional case is 'background-position'--
there, <<percentage>>s and <<length>>s actually cause different behavior/interpretations.
However, there is prose defining how to interpret a ''calc()'' mixing the two in that context.
</div>
<h3 id='dimensions'>
Numbers with Units: <a>dimensions</a></h3>
A <dfn>dimension</dfn> is a <<number>>
immediately followed by a unit identifier.
It corresponds to the <<dimension-token>> production
in the <a href="http://www.w3.org/TR/css-syntax/">CSS Syntax Module</a> [[!CSS3SYN]].
Like keywords, unit identifiers are <a>ASCII case-insensitive</a>.
<p>CSS uses <a>dimensions</a> to specify
distances (<<length>>),
durations (<<time>>),
frequencies (<<frequency>>),
resolutions (<<resolution>>),
and other quantities.
<!--
██ ████████ ██ ██ ██████ ████████ ██ ██
██ ██ ███ ██ ██ ██ ██ ██ ██
██ ██ ████ ██ ██ ██ ██ ██
██ ██████ ██ ██ ██ ██ ████ ██ █████████
██ ██ ██ ████ ██ ██ ██ ██ ██
██ ██ ██ ███ ██ ██ ██ ██ ██
████████ ████████ ██ ██ ██████ ██ ██ ██
-->
<h2 id="lengths">
Distance Units: the <<length>> type</h2>
Lengths refer to distance measurements
and are denoted by <dfn id="length-value">&lt;length></dfn> in the property definitions.
A length is a <a>dimension</a>.
However, for zero lengths the unit identifier is optional
(i.e. can be syntactically represented as the <<number>> ''0'').
Properties may restrict the length value to some range.
If the value is outside the allowed range,
the declaration is invalid and must be <a href="http://www.w3.org/TR/CSS21/conform.html#ignore">ignored</a>.
While some properties allow negative length values,
this may complicate the formatting and there may be implementation-specific limits.
If a negative length value is allowed but cannot be supported,
it must be converted to the nearest value that can be supported.
In cases where the <a lt="used value">used</a> length cannot be supported,
user agents must approximate it in the <a lt="actual value">actual</a> value.
There are two types of length units: <a lt="relative length">relative</a> and <a lt="absolute length">absolute</a>.
<h3 id="relative-lengths">
Relative lengths</h3>
<dfn lt="relative length">Relative length units</dfn> specify a length relative to another length.
Style sheets that use relative units can more easily scale from one output environment to another.
The relative units are:
<table class="data">
<caption>Informative Summary of Relative Units</caption>
<thead>
<tr><th>unit<th>relative to
</thead>
<tbody>
<tr><td>''em''
<td>font size of the element
<tr><td>''ex''
<td>x-height of the element's font
<tr><td>''ch''
<td>width of the "0" (ZERO, U+0030) glyph in the element's font
<tr><td>''rem''
<td>font size of the root element
<tr><td>''vw''
<td>1% of viewport's width
<tr><td>''vh''
<td>1% viewport's height
<tr><td>''vmin''
<td>1% of viewport's smaller dimension
<tr><td>''vmax''
<td>1% of viewport's larger dimension
</tbody>
</table>
Child elements do not inherit the relative values as specified for their parent;
they inherit the <a>computed values</a>.
<!--
████████ ██ ██ ██ ████████ ████████ ██████
██ ███ ███ ██ ██ ██ ██ ██
██ ████ ████ ██ ██ ██ ██
██████ ██ ███ ██ ██ ██████ ██ ██
██ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ██
████████ ██ ██ ██ ████████ ██ ██████
-->
<h4 id="font-relative-lengths">
Font-relative lengths: the ''em'', ''ex'', ''ch'', ''rem'' units</h4>
Aside from ''rem'' (which refers to the font-size of the root element),
the <dfn export id="font-relative-length">font-relative lengths</dfn> refer to the font metrics of the element on which they are used.
The exception is when they occur in the value of the 'font-size' property itself,
in which case they refer to the computed font metrics of the parent element
(or the computed font metrics corresponding to the initial values of the 'font' property,
if the element has no parent).
<dl export>
<dt><dfn lt="em">em unit</dfn>
<dd>
Equal to the computed value of the 'font-size' property of the element on which it is used.
<div class="example">
The rule:
<pre>h1 { line-height: 1.2em }</pre>
means that the line height of <code>h1</code> elements
will be 20% greater than the font size of <code>h1</code> element.
On the other hand:
<pre>h1 { font-size: 1.2em }</pre>
means that the font size of <code>h1</code> elements
will be 20% greater than the computed font size inherited by <code>h1</code> elements.
</div>
<dt><dfn lt="ex">ex unit</dfn>
<dd>
Equal to the used x-height of the <a href="http://www.w3.org/TR/css3-fonts/#first-available-font">first available font</a>. [[!CSS3-FONTS]]
The x-height is so called because it is often equal to the height of the lowercase "x".
However, an ''ex'' is defined even for fonts that do not contain an "x".
The x-height of a font can be found in different ways. Some fonts
contain reliable metrics for the x-height. If reliable font metrics
are not available, UAs may determine the x-height from the height
of a lowercase glyph. One possible heuristic is to look at how far
the glyph for the lowercase "o" extends below the baseline, and
subtract that value from the top of its bounding box. In the cases
where it is impossible or impractical to determine the x-height,
a value of 0.5em must be assumed.
<dt><dfn lt="ch">ch unit</dfn>
<dd>
Equal to the used advance measure of the "0" (ZERO, U+0030) glyph
found in the font used to render it.
In the cases where it is impossible or impractical to determine the measure of the "0" glyph,
a value of 0.5em must be assumed.
<dt><dfn lt="rem">rem unit</dfn>
<dd>
Equal to the computed value of 'font-size' on the root element.
When specified on the 'font-size' property of the root element,
the ''rem'' units refer to the property's <em>initial value</em>.
</dl>
<!--
██ ██ ██ ██ ██ ████████ ████████ ██████
██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██████ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██
███ ███ ███ ██ ████████ ██ ██████
-->
<h4 id="viewport-relative-lengths">
Viewport-percentage lengths: the ''vw'', ''vh'', ''vmin'', ''vmax'' units</h4>
The <dfn export>viewport-percentage lengths</dfn> are relative to the size of the
<a href="http://www.w3.org/TR/CSS21/visudet.html#containing-block-details">initial containing block</a>.
When the height or width of the initial containing block is changed,
they are scaled accordingly.
However, when the value of 'overflow' on the root element is ''overflow/auto'',
any scroll bars are assumed not to exist.
<span class='note'>Note that the initial containing block's size is affected by the presence of scrollbars on the viewport.</span>
For paged media, the exact definition of the viewport-percentage lengths
is deferred to [[!CSS3PAGE]].
<dl export>
<dt><dfn lt="vw">vw unit</dfn>
<dd>
Equal to 1% of the width of the initial containing block.
<div class="example">
In the example below, if the width of the viewport is 200mm,
the font size of <code>h1</code> elements will be 16mm
(i.e. (8×200mm)/100).
<pre>h1 { font-size: 8vw }</pre>
</div>
<dt><dfn lt="vh">vh unit</dfn>
<dd>
Equal to 1% of the height of the initial containing block.
<dt><dfn lt="vmin">vmin unit</dfn>
<dd>
Equal to the smaller of ''vw'' or ''vh''.
<dt><dfn lt="vmax">vmax unit</dfn>
<dd>
Equal to the larger of ''vw'' or ''vh''.
</dl>
<!--
████████ ██ ██ ██ ████████ ████████ ██████
██ ██ ██ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ██
████████ ███ ██ ██████ ██ ██
██ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ████████ ██ ██████
-->
<h3 id="absolute-lengths">
Absolute lengths: the ''cm'', ''mm'', ''q'', ''in'', ''pt'', ''pc'', ''px'' units</h3>
The <dfn lt="absolute length">absolute length units</dfn> are fixed in relation to each other
and anchored to some physical measurement.
They are mainly useful when the output environment is known.
The absolute units consist of
the <dfn>physical units</dfn> (''in'', ''cm'', ''mm'', ''pt'', ''pc'', ''q'')
and the <dfn>visual angle unit</dfn> (''px''):
<table class="data" export>
<thead>
<tr><th>unit
<th>name
<th>equivalence
<tbody>
<tr><th><dfn>cm</dfn>
<td>centimeters
<td>1cm = 96px/2.54
<tr><th><dfn>mm</dfn>
<td>millimeters
<td>1mm = 1/10th of 1cm
<tr><th><dfn>q</dfn>
<td>quarter-millimeters
<td>1q = 1/40th of 1cm
<tr><th><dfn>in</dfn>
<td>inches
<td>1in = 2.54cm = 96px
<tr><th><dfn>pc</dfn>
<td>picas
<td>1pc = 1/6th of 1in
<tr><th><dfn>pt</dfn>
<td>points
<td>1pt = 1/72th of 1in
<tr><th><dfn lt="px|pixel unit">px</dfn>
<td>pixels
<td>1px = 1/96th of 1in
</table>
<div class="example">
<pre>
h1 { margin: 0.5in } /* inches */
h2 { line-height: 3cm } /* centimeters */
h3 { word-spacing: 4mm } /* millimeters */
h3 { letter-spacing: 1Q } /* quarter-millimeters */
h4 { font-size: 12pt } /* points */
h4 { font-size: 1pc } /* picas */
p { font-size: 12px } /* px */
</pre>
</div>
For a CSS device, these dimensions are anchored either
<ul>
<li>(i) by relating the <a>physical units</a> to their physical measurements, or
<li>(ii) by relating the <a>pixel unit</a> to the <a>reference pixel</a>.
</ul>
For print media and similar high-resolution devices,
the anchor unit should be one of the standard physical units (inches, centimeters, etc).
For lower-resolution devices,
and devices with unusual viewing distances,
it is recommended instead that the anchor unit be the pixel unit.
For such devices it is recommended that the pixel unit
refer to the whole number of device pixels that best approximates the reference pixel.
Note: Note that if the anchor unit is the pixel unit,
the physical units might not match their physical measurements.
Alternatively if the anchor unit is a physical unit,
the pixel unit might not map to a whole number of device pixels.
Note: Note that this definition of the pixel unit and the physical units
differs from previous versions of CSS.
In particular, in previous versions of CSS the pixel unit and the physical units
were not related by a fixed ratio:
the physical units were always tied to their physical measurements
while the pixel unit would vary to most closely match the reference pixel.
(This change was made because too much existing content relies on the assumption of 96dpi,
and breaking that assumption breaks the content.)