<pre class='metadata'>
Title: CSS Values and Units Module Level 4
Group: CSSWG
Shortname: css-values
Level: 4
Status: ED
Work Status: Refining
ED: https://drafts.csswg.org/css-values-4/
TR: https://www.w3.org/TR/css-values-4/
Editor: Tab Atkins, Google, http://xanthir.com/contact/, w3cid 42199
Editor: Elika J. Etemad / fantasai, Apple, http://fantasai.inkedblade.net/contact, w3cid 35400
Abstract: This CSS module describes the common values and units that CSS properties accept and the syntax used for describing them in CSS property definitions.
Ignored Terms: <spacing-limit>, containing block, property
Ignored Vars: Cn+1, n
Inline Github Issues: no
Default Highlight: css
Include Can I Use Panels: yes
</pre>
<pre class='link-defaults'>
spec: css2;
	type: property; text: border-collapse
spec: css-borders-4; type: property;
	text: border-color
	text: box-shadow
	text: border-top-width
	text: border-left-width
	text: border-bottom-width
	text: border-right-width
	text: border-width
spec: css-color-4; type: value; text: currentcolor
spec: css-color-5; type: type; text: <color>
spec: css-color-5; type:type; text: <absolute-color-function>
spec: css-shapes-1; type: function; text: rect();
spec: css-sizing-3; type: property;
	text: min-width
	text: box-sizing
spec: cssom-1; type:dfn;text:owner node; for:CSSStyleSheet;
spec: selectors-4; type: type; text: <q-name>
spec: infra; type: dfn; text: string;
spec: css-2023; type: dfn; text: ua
spec:css-typed-om-1; type:dfn; text:internal representation
spec:url; type:dfn; text:url; for:/
</pre>
<pre class="ignored-specs">
spec: css-device-adapt-1;
</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: ", "; }
dl:not(.switch) dt { display: inline; }
td > small { display: block; }
</style>

<style>
/* Put nice boxes around each algorithm. */
[data-algorithm]:not(.heading) {
	padding: .5em;
	border: thin solid #ddd; border-radius: .5em;
	margin: .5em calc(-0.5em - 1px);
}
[data-algorithm]:not(.heading) > :first-child {
	margin-top: 0;
}
[data-algorithm]:not(.heading) > :last-child {
	margin-bottom: 0;
}
[data-algorithm] [data-algorithm] {
	margin: 1em 0;
}
</style>

<h2 id="intro">
Introduction</h2>

	The value definition field of each CSS property can contain keywords,
	data types (which appear between <css>&lt;</css> and <css>></css>),
	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 [[!CSS2]]
	sections
	<a href="https://www.w3.org/TR/CSS2/about.html#value-defs">1.4.2.1</a>,
	<a href="https://www.w3.org/TR/CSS2/syndata.html#values">4.3</a>,
	and <a href="https://www.w3.org/TR/CSS2/aural.html#aural-intro">A.2</a>.

<!-- Big Text: syntax

 ███▌  █   ▐▌ █    █▌ █████▌  ███▌  █     █
█▌  █▌ ▐▌  █  █▌   █▌   █▌   ▐█ ▐█   █   █
█▌      █ ▐▌  ██▌  █▌   █▌   █▌  █▌   █ █
 ███▌   ▐▌█   █▌▐█ █▌   █▌   █▌  █▌    █
    █▌   █▌   █▌  ██▌   █▌   █████▌   █ █
█▌  █▌   █▌   █▌   █▌   █▌   █▌  █▌  █   █
 ███▌    █▌   █▌   ▐▌   █▌   █▌  █▌ █     █
-->

<h2 id="value-defs">
Value Definition Syntax</h2>

	The <dfn for=CSS export lt="value definition syntax | CSS value definition syntax">value definition syntax</dfn> described here
	is used to define the set of valid values for CSS properties
	(and the valid syntax of many other parts of CSS).
	A value so described can have one or more components.

<h3 id="component-types">
Component Value Types</h3>

	Component value types are designated in several ways:

	1. <a href="#keywords">Keyword</a> values (such as <code>auto</code>, ''disc'', etc.)
		and at-keywords representing the start of an [=at-rule=],
		which appear literally, without quotes (e.g. <code>auto</code> or <code>@media</code>).

		Note: It is possible, with <a spec=css-syntax-3>escaping</a>, to construct a [=CSS identifier=]
		whose value ends with <code>(</code> or  starts with <code>@</code>.
		Such a token is an <<ident-token>> (i.e. a [=keyword=]),
		not a <<function-token>> or an <<at-keyword-token>>.

	2. Basic data types,
		which appear between <code>&lt;</code> and <code>></code>
		(e.g., <<length>>, <<percentage>>, etc.).
		For <a>numeric data types</a>,
		this type notation can annotate any range restrictions
		using the [[#numeric-ranges|bracketed range notation]] described below.

	3. Property value ranges,
		which represent the same pattern of values as a property bearing the same name.
		These are written as the property name,
		surrounded by single quotes,
		between <code>&lt;</code> and <code>></code>,
		e.g., <<'border-width'>>, <<'background-attachment'>>, etc.

		These types <em>do not</em> include <a href="#common-keywords">CSS-wide keywords</a> such as ''inherit''.
		Additionally,
		if the property's value grammar
		is a <a lt=# grammar>comma-separated repetition</a>,
		the corresponding type
		does not include the top-level <a lt=# grammar>comma-separated list multiplier</a>.
		(E.g. if a property named <code>pairing</code> is defined as <code>[ <<custom-ident>> <<integer>>? ]#</code>,
		then <code>&lt;\'pairing'></code> is equivalent to <code>[ <<custom-ident>> <<integer>>? ]</code>,
		not <code>[ <<custom-ident>> <<integer>>? ]#</code>.)

		<details class=note>
			<summary>Why remove the multiplier?</summary>

			The top-level multiplier is ripped out of these value types
			because top-level comma-separated repetitions are mostly used for
			[=coordinating list properties=],
			and when a shorthand combines several such properties,
			it needs the unmultiplied grammar
			so it can construct its <em>own</em> comma-separated repetition.

			Without this special treatment,
			every such longhand would have to be defined
			with an ad-hoc production just for the inner value,
			which makes the grammars harder to understand overall.
		</details>

	4. Functional notations and their arguments.
		These may be written literally as defined in [[#component-functions]],
		or referenced by a non-terminal using the function's name,
		followed by an empty parentheses pair,
		between <code>&lt;</code> and <code>></code>,
		e.g. <<calc()>>,
		and references the correspondingly-named [=functional notation=].

	5. Other non-terminals.
		These are written as the name of the non-terminal
		between <code>&lt;</code> and <code>></code>,
		as in <<spacing-limit>>.
		Notice the distinction between <<border-width>> and <<'border-width'>>:
		the latter represents the grammar 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.

	6. Delimiters, which represent their corresponding tokens.
		Slashes (<code>/</code>),
		<a lt="," grammar>commas</a> (<code>,</code>),
		colons (<code>:</code>),
		semicolons (<code>;</code>),
		parentheses (<code>(</code> and <code>)</code>),
		and braces (<code>{</code> and <code>}</code>)
		are written literally.
		Other delimiters must be written enclosed in single quotes
		(such as <code>'+'</code>).

	<strong><dfn lt="," id='comb-comma' export grammar>Commas</dfn> specified in the grammar are implicitly omissible</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 <a href="https://www.w3.org/TR/css-syntax/#whitespace">white space</a>/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'
	under [[CSS-CASCADE-3|CSS Cascading and Inheritance Level 3]]
	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
			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 reorderable 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>

	Note: Combinators are <em>not</em> associative, so grouping is significant.
	For example, ''a || b || c'' and ''a || [ b || c ]'' are distinct grammars:
	the first allows a value like ''b a c'', but the second does not.

<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 <a href="https://www.w3.org/TR/css-syntax/#whitespace">white space</a> 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>

	The <css>+</css> and <css>#</css> multipliers may be stacked as ''+#'';
	similarly, the <css>#</css> and <css>?</css> multipliers, <css>{A}</css> and <css>?</css> multipliers, and <css>{A,B}</css> and <css>?</css> multipliers may be stacked as ''#?'', ''{A}?'', and ''{A,B}?'', respectively.
	These stacks each represent the later multiplier
	applied to the result of the earlier multiplier.
	(These same stacks can be represented using grouping,
	but in complex grammars this can push the number of brackets beyond readability.)

	For repeated component values (indicated by <css>*</css>, <css>+</css>, or <css>#</css>),
	[=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><code>A? B? C?</code>
				<td><code>A? || B? || C?</code>

			<tr>
				<th>one or more
				<td><code>[ A? B? C? ]!</code>
				<td><code>A || B || C</code>

			<tr>
				<th>all
				<td><code>A B C </code>
				<td><code>A && B && C</code>
	</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,
	<a href="https://www.w3.org/TR/css-syntax/#whitespace">white space</a> 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="component-functions">
	Functional Notation Definitions</h3>

	The syntax of a [=functional notation=] is defined
	as a sequence of:

	1. The function's name written as an identifier
		followed by an open parenthesis
		(such as ''example(''),
		or the <<function-token>> production
		to indicate a function with an arbitrary name.

	2. The function's arguments, if any,
		expressed using the [=value definition syntax=].

	3. A literal closing parenthesis.

	The function’s arguments are considered <em>implicitly grouped</em>,
	as if surrounded by brackets (''[ ... ]'').

	<div class=example>
		For example, a grammar like:

		<xmp class=prod>
			example( <length> , <length> )
		</xmp>

		will match a function whose name is "example"
		and whose arguments match "<<length>> , <<length>>".
	</div>

	<div class=example>
		For example, the Selectors grammar defines pseudo-classes generically,
		allowing any possibly function name after the initial colon:

		<xmp class=prod>
			<pseudo-class-selector> = : <ident-token> | : <function-token> <any-value> )
		</xmp>

		This represents <em>any</em> function name,
		with <<any-value>> as the function arguments.
	</div>

	<div class="example">
		Since the [=functional notation=] <em>implicitly groups</em> its contents,
		the effect of any combinator inside it
		is scoped to the function’s argument.
		For example, the [=functional notation=] syntax definition
		''example( foo | bar )'' is equivalent to ''example( [ foo | bar ] )''.
	</div>

<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>
				<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;font-family-name> | &lt;generic-font-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>'box-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>

<h3 id="production-blocks">
Non-Terminal Definitions and Grammar Production Blocks</h3>

	The precise grammar of non-terminals, like <<position>> or <<calc()>>,
	is often specified in a <dfn export>CSS grammar production block</dfn>.
	These are conventionally represented in a preformatted block of definitions
	like this:

	<div class="example">
		The <css>&lt;foo></css> syntax is defined as follows:

		<xmp class=prod>
			<foo> = keyword | <bar> |
			        some-really-long-pattern-of-stuff
			<bar> = <length>
		</xmp>
	</div>

	Each definition starts on its own line,
	and consists of the non-terminal to be defined,
	followed by an <code>=</code>,
	followed by the fragment of [=value definition syntax=] to which it expands.
	A definition can stretch across multiple lines,
	and terminates before the next line that starts a new grammar production
	or at the end of the grammar production block
	(whichever comes first).

	<div class="example">
		In the above example, the <css>&lt;foo></css> definition covers two lines.
		The third line starts a new definition for <css>&lt;bar></css>.
		(A naked <code>=</code> is never valid in [=value definition syntax=],
		so it's unambiguous when a new line starts a fresh definition.)
	</div>


<h2 id="combining-values">
Combining Values: Interpolation, Addition, and Accumulation</h2>

	Some procedures, for example
	<a href="https://www.w3.org/TR/css-transitions/">transitions</a>
	and <a href="https://www.w3.org/TR/css-animations/">animations</a>,
	<dfn export>combine</dfn> two CSS property values.
	The following combining operations--
	on the two <a>computed values</a> <var>V<sub>A</sub></var> and <var>V<sub>B</sub></var>
	yielding the <a>computed value</a> <var>V<sub>result</sub></var>--
	are defined.
	For operations that are not commutative
	(for example, matrix multiplication,
	or accumulation of mismatched transform lists)
	<var>V<sub>A</sub></var> represents
	the first term of the operation and
	<var>V<sub>B</sub></var> represents
	the second.

	<dl export>
		<dt><dfn id="interpolation" lt="interpolation | interpolate | value interpolation | interpolation procedure">interpolation</dfn>
		<dd>
			Given two property values
			<var>V<sub>A</sub></var> and <var>V<sub>B</sub></var>,
			produces an intermediate value
			<var>V<sub>result</sub></var>
			at a distance of <var>p</var>
			along the interval between
			<var>V<sub>A</sub></var> and <var>V<sub>B</sub></var>
			such that <var>p</var> = 0 produces <var>V<sub>A</sub></var>
			and <var>p</var> = 1 produces <var>V</var><sub>B</sub>.

			The range of <var>p</var> is (&minus;∞, ∞)
			due to the effect of <a>timing functions</a>.
			As a result, this procedure must also define
			extrapolation behavior for <var>p</var> outside [0, 1].

		<dt><dfn id="addition" lt="value addition | addition procedure" local-lt="add | addition">addition</dfn>
		<dd>
			Given two property values
			<var>V<sub>A</sub></var> and <var>V<sub>B</sub></var>,
			returns the sum of the two properties,
			<var>V</var><sub>result</sub>.

			Note: While <a>addition</a>
			can often be expressed
			in terms of the same weighted sum function
			used to define <a>interpolation</a>,
			this is not always the case.
			For example, interpolation of transform matrices involves
			decomposing and interpolating the matrix components
			whilst addition relies on matrix multiplication.

			If a value type does not define a specific procedure for <a>addition</a>
			or is defined as <dfn export>not additive</dfn>,
			its <a>addition</a> operation is simply
			<var>V<sub>result</sub></var> = <var>V<sub>B</sub></var>.

		<dt><dfn id="accumulation" lt="value accumulation | accumulation procedure" local-lt="accumulate | accumulation">accumulation</dfn>
		<dd>
			Given two property values
			<var>V<sub>A</sub></var> and <var>V<sub>B</sub></var>,
			returns the result, <var>V<sub>result</sub></var>,
			of combining the two operands
			such that <var>V<sub>B</sub></var>
			is treated as a <em>delta</em> from <var>V<sub>A</sub></var>.

			<div class="note">
				Note: For many types of animation such as numbers or lengths,
				<a>accumulation</a> is defined to be identical
				to <a>addition</a>.

				A common case where the definitions differ
				is for list-based types
				where <a>addition</a> may be defined as appending to a list
				whilst <a>accumulation</a> may be defined
				as component-based addition.
				For example, the filter list values ''blur(2)'' and ''blur(3)'',
				when <a>added</a> together would produce ''blur(2) blur(3)'',
				but when <a>accumulated</a> would produce ''blur(5)''.
			</div>

			If a value type does not define a specific procedure for <a>accumulation</a>,
			its <a>accumulation</a> operation is identical to <a>addition</a>.
	</dl>

	These operations are only defined on <a>computed values</a>.
	(As a result, it is not necessary to define, for example,
	how to add a <<length>> value of ''15pt'' with ''5em''
	since such values will be resolved to their <a>canonical unit</a>
	before being passed to any of the above procedures.)



<h3 id="combining-range">
Range Checking</h3>

	Interpolation can result in a value outside the valid range for a property,
	even if all of the inputs to interpolation are valid;
	this especially happens when |p| is outside the [0, 1] range,
	but some [=easing functions=] can cause this to occur even within that range.
	If the final result
	<em>after</em> interpolation, addition, and accumulation
	is out-of-range for the target context the value is being used in,
	it does not cause the declaration to be invalid.
	Instead, the value must be clamped to the range allowed in the target context,
	exactly the same as [=math functions=]
	(see [[#calc-range]]).

	Note: Even if interpolation results in an out-of-range value,
	addition/accumulation might "correct" the result and bring it back into range.
	Thus, clamping is only applied to the <em>final</em> result
	of applying all interpolation-related operations.

<h2 id="textual-values">
Textual Data Types</h2>

	The <dfn export for=CSS>textual data types</dfn> include
	various keywords and identifiers
	as well as strings (<<string>>) and URLs (<<url>>).
	Aside from the casing of <a href="#keywords">pre-defined keywords</a>
	or as explicitly defined for a given property,
	no normalization is performed,
	not even Unicode normalization:
	the <a lt="specified value">specified</a> and <a>computed value</a> of a property
	are exactly the provided Unicode values after parsing
	(which includes character set conversion and [[css-syntax-3#escaping|escaping]]).
	[[!UNICODE]] [[!CSS-SYNTAX-3]]

	[=Strings=], denoted by <dfn id="string-value">&lt;string></dfn>,
	are sequences of characters representing arbitrary textual data.
	When written literally,
	they are delimited by double quotes or single quotes,
	and correspond to the <<string-token>> production. [[!CSS-SYNTAX-3]].

	CSS <dfn export lt="CSS identifier | CSS ident | identifier | ident" for="CSS">identifiers</dfn>,
	generically denoted by <dfn>&lt;ident></dfn>,
	represent names,
	and are written as an unquoted sequence of (potentially escaped) characters
	corresponding to the <<ident-token>> grammar. [[!CSS-SYNTAX-3]]
	Identifiers cannot be quoted;
	otherwise they would be interpreted as strings.
	CSS properties accept two classes of [=CSS/identifiers=]:
	[[#keywords|pre-defined keywords]]
	and [[#custom-idents|author-defined identifiers]].

	Note: The <<ident>> production is not meant for property value definitions--
	<<custom-ident>> should be used instead.
	It is provided as a convenience for defining other syntactic constructs.

	All textual data types <a>interpolate</a> as <a>discrete</a>
	and are <a>not additive</a>.

<!-- Big Text: keywords

█▌  █▌ █████▌ █   ▐▌ █▌    █▌  ███▌  ████▌  ████▌   ███▌
█▌ █▌  █▌     ▐▌  █  █▌    █▌ █▌  █▌ █▌  █▌ █▌  █▌ █▌  █▌
█▌█▌   █▌      █ ▐▌  █▌    █▌ █▌  █▌ █▌  █▌ █▌  █▌ █▌
██     ████    ▐▌█   █▌    █▌ █▌  █▌ ████▌  █▌  █▌  ███▌
█▌█▌   █▌       █▌   █▌ ▐  █▌ █▌  █▌ █▌▐█   █▌  █▌     █▌
█▌ █▌  █▌       █▌   █▌ █▌ █▌ █▌  █▌ █▌ ▐█  █▌  █▌ █▌  █▌
█▌  █▌ █████▌   █▌    ██ ▐█▌   ███▌  █▌  █▌ ████▌   ███▌
-->

<h3 id="keywords">
Pre-defined Keywords</h3>

	In the value definition fields,
	<dfn lt="keyword" export for=CSS>keywords</dfn> with a pre-defined meaning appear literally.
	Keywords are [=CSS/identifiers=]
	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.
	These keywords are normatively defined in
	the <a href="https://www.w3.org/TR/css-cascade/#defaulting-keywords">CSS Cascading and Inheritance Module</a>.

	<wpt>
	css/css-multicol/multicol-inherit-002.xht
	css/css-multicol/multicol-rule-color-inherit-001.xht
	css/css-multicol/multicol-rule-color-inherit-002.xht
	css/CSS2/values/units-008.xht
	</wpt>

	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'>
Unprefixed 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 identifier=]
	that would not be misinterpreted as a pre-defined keyword in that property's value definition.
	Such identifiers are fully case-sensitive
	(meaning they're compared using the "[=identical to=]" operation),
	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 <css>default</css> 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 <<easing-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.
	Such conflicts can alternatively be avoided by using <<dashed-ident>>.

<h3 id='dashed-idents'>
Prefixed Author-defined Identifiers: the <<dashed-ident>> type</h3>

	Some contexts accept <em>both</em> author-defined identifiers
	<em>and</em> CSS-defined identifiers.
	If not handled carefully,
	this can result in difficulties adding new CSS-defined values;
	[=UAs=] have to study existing usage
	and gamble that there are sufficiently few author-defined identifiers in use
	matching the new CSS-defined one,
	so giving the new value a special CSS-defined meaning
	won't break existing pages.

	While there are many legacy cases in CSS
	that mix these two values spaces in exactly this fraught way,
	the <<dashed-ident>> type is meant to be an easy way
	to distinguish author-defined identifiers
	from CSS-defined identifiers.

	The <dfn><<dashed-ident>></dfn> production
	is a <<custom-ident>>,
	with all the case-sensitivity that implies,
	with the additional restriction that it must start with two dashes
	(U+002D HYPHEN-MINUS).

	<<dashed-ident>>s are reserved solely for use as author-defined names.
	CSS will never define a <<dashed-ident>> for its own use.

	<div class=example>
		For example, [=custom properties=] need to be distinguishable from CSS-defined properties,
		as new properties are added to CSS regularly.
		To allow this,
		[=custom property=] names are required to be <<dashed-ident>>s,
		as in this example:

		<pre highlight=css>
		.foo {
			--fg-color: blue;
		}
		</pre>
	</div>

	<div class=example>
		<<dashed-ident>>s are also used in the ''@color-profile'' rule,
		to separate author-defined color profiles
		from pre-defined ones like ''device-cmyk'',
		and allow CSS to define more pre-defined (but overridable) profiles in the future
		without fear of clashing with author-defined profiles:

		<pre highlight=css>
		@color-profile --foo { src: url(https://example.com/foo.icc); }
		.foo {
			color: color(--foo 1 0 .5 / .2);
		}
		</pre>
	</div>

	<div class=example>
		CSS will use <<dashed-ident>> more in the future,
		as more author-controlled syntax is added.
		CSS authoring tools,
		such as preprocessors that turn custom syntax into standard CSS,
		<em>should</em> use <<dashed-ident>> as well,
		to avoid clashing with future CSS design.

		For example,
		if a CSS preprocessor added a new "custom" at-rule,
		it <em>shouldn't</em> spell it <css>@custom</css>,
		as this would clash with a future official <css>@custom</css> rule added by CSS.
		Instead, it should use <css>@--custom</css>,
		which is guaranteed to never clash with anything defined by CSS.

		Even better, it should use <css>@--library1-custom</css>,
		so that if Library2 adds their own "custom" at-rule
		(spelled @--library2-custom),
		there's no possibility of clash.
		Ideally this prefix should be customizable,
		if allowed by the tooling,
		so authors can manually avoid clashes on their own.
	</div>


<!-- Big Text: string

 ███▌  █████▌ ████▌  ████ █    █▌  ███▌
█▌  █▌   █▌   █▌  █▌  ▐▌  █▌   █▌ █▌  █▌
█▌       █▌   █▌  █▌  ▐▌  ██▌  █▌ █▌
 ███▌    █▌   ████▌   ▐▌  █▌▐█ █▌ █▌ ██▌
    █▌   █▌   █▌▐█    ▐▌  █▌  ██▌ █▌  █▌
█▌  █▌   █▌   █▌ ▐█   ▐▌  █▌   █▌ █▌  █▌
 ███▌    █▌   █▌  █▌ ████ █▌   ▐▌  ███▌
-->

<h3 id="strings">
Quoted Strings: the <<string>> type</h3>

	[=Strings=], denoted by <dfn id="string-value">&lt;string></dfn>,
	are sequences of characters representing arbitrary textual data.
	When written literally,
	they are delimited by double quotes or single quotes,
	and correspond to the <<string-token>> production. [[!CSS-SYNTAX-3]].

	<div class=example>
		Double quotes cannot occur inside double quotes, unless
		<a href="https://www.w3.org/TR/CSS2/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.)

<!-- Big Text: url

█▌  █▌ ████▌  █▌
█▌  █▌ █▌  █▌ █▌
█▌  █▌ █▌  █▌ █▌
█▌  █▌ ████▌  █▌
█▌  █▌ █▌▐█   █▌
█▌  █▌ █▌ ▐█  █▌
 ███▌  █▌  █▌ █████
-->

<h3 id="urls">
Resource Locators: the <<url>> type</h3>

	The <<url>> type,
	written with the <dfn>url()</dfn> and <dfn>src()</dfn> functions,
	represents a <l spec=url>[=/URL=]</l>,
	which is a pointer to a resource.

	The syntax of <<url>> is:

	<pre class="prod">
		<dfn id="url-value">&lt;url></dfn> = <<url()>> | <<src()>>

		&lt;url()> = url( <<string>> <<url-modifier>>* ) | <<url-token>>
		&lt;src()> = src( <<string>> <<url-modifier>>* )
	</pre>

	<div class="example">
		This example shows a URL being used as a background image:

		<pre highlight=css>
		body { background: url("http://www.example.com/pinkish.gif") }
		</pre>
	</div>

	A ''url()'' can be written without quotation marks around the URL value,
	in which case it is <a lt="consume a url token" spec=css-syntax-3>specially-parsed</a>
	as a <<url-token>>; see [[css-syntax-3#consume-url-token]]. [[!CSS-SYNTAX-3]]

	Note: Because of this special parsing,
	''url()'' can only express its value literally.
	To provide a URL by functions such as ''var()'',
	use the ''src()'' notation,
	which does not have this special parsing rule.

	<div class="example">
		For example, the following declarations are identical:

		<pre>
			background: url("http://www.example.com/pinkish.gif");
			background: url(http://www.example.com/pinkish.gif);
		</pre>

		And these have the same meaning as well:

		<pre>
			background: src("http://www.example.com/pinkish.gif");
			--foo: "http://www.example.com/pinkish.gif";
			background: src(var(--foo));
		</pre>

		But this does <em>not</em> work:

		<pre>
			--foo: "http://www.example.com/pinkish.gif";
			background: url(var(--foo));
		</pre>

		...because the unescaped "(" in the value causes a parse error,
		so the entire declaration is thrown out as invalid.
	</div>

	Note: The unquoted ''url()'' syntax cannot accept a <<url-modifier>> argument
	and has extra escaping requirements:
	parentheses, <a href="https://www.w3.org/TR/css-syntax/#whitespace">whitespace</a> 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)''.
	(In quoted <<string>> ''url()''s,
	only newlines and the character used to quote the string need to be escaped.)
	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]].

	Some CSS contexts (such as ''@import'') also allow a <<url>>
	to be represented by a bare <<string>>, without the function wrapper.
	In such cases the string behaves identically to a ''url()'' function containing that string.

	<div class="example">
		For example, the following statements act identically:
		<pre>
			@import url("base-theme.css");
			@import "base-theme.css";
		</pre>
	</div>

<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.

	Note: For HTML documents,
	the <a href="https://html.spec.whatwg.org/multipage/urls-and-fetching.html#dynamic-changes-to-base-urls">base URL is mutable</a>.

	When a <<url>> appears in the computed value of a property,
	it is [=resolve a style resource URL|resolved to an absolute URL=].
	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>

<h5 id='local-urls'>
Fragment URLs</h5>

	To enable element ID references to work in CSS
	regardless of base URL changes
	or shadow DOM,
	<<url>>s have special behavior
	when they contain only a fragment.

	If a <<url>>'s value starts with a U+0023 NUMBER SIGN (<code>#</code>) character,
	then the URL additionally has its
	<dfn export for="<url>">local url flag</dfn> set,
	and is a [=tree-scoped reference=]
	for the URL's [=url/fragment=].

	When matching a <<url>> with the <a>local url flag</a> set:

	* if the URL's fragment is an element ID reference
		(rather than, say, a media fragment),
		resolve it as a [=tree-scoped reference=]
		with the tree's IDs as the associated [=tree-scoped names=]:
		specifically, resolve to the first element
		in [=tree order=]
		among the associated [=node tree=]'s descendants
		with the URL's [=url/fragment=] as its ID.
		(And, as usual for [=tree-scoped references=],
		continuing up to the host's tree if needed.)

		If no such element is found,
		the URL fails to resolve.

	* otherwise, resolve the fragment against the current document.

	Issue: Possibly reference <l spec=html>[=find a potential indicated element=]</l>,
	but that is defined specifically for {{Document}}s,
	not {{ShadowRoot}}s.

	Note: This means that such fragments will resolve
	against the contents of the current document
	(or whichever [=node tree=] the stylesheet lives in,
	if shadow DOM is involved)
	regardless of how such relative URLs would resolve elsewhere
	(ignoring, for example, <{base}> elements
	changing the base URL,
	or relative URLs in linked stylesheets
	resolving against the stylesheet's URL).

	<div class="example">
		In the following example,
		<code>#anchor</code> will resolve against <code>http://example.com/</code>
		whereas <code>#image</code> will resolve against the elements in the HTML document itself:

		<xmp highlight=html>
			<!DOCTYPE html>
			<base href="http://example.com/">
			...
			<a href="#anchor" style="background-image: url(#image)">link</a>
		</xmp>
	</div>

	When <a href="https://www.w3.org/TR/cssom-1/#serializing-css-values">serializing</a>
	a ''url()'' with the <a>local url flag</a> set,
	it must serialize as just the fragment.


<h4 id="url-empty">
Empty URLs</h4>

	If the value of the <<url>> is the empty string
	(like ''url("")'' or ''url()''),
	the url must resolve to an invalid resource
	(similar to what the url ''about:invalid'' does).

	Its computed value is ''url("")'' or ''src("")'',
	whichever was specified,
	and it must serialize as such.

	<wpt>
	css/css-values/urls/empty.html
	</wpt>

	Note: This matches the behavior of empty urls for embedded resources elsewhere in the web platform,
	and avoids excess traffic re-requesting the stylesheet or host document
	due to editing mistakes leaving the ''url()'' value empty,
	which are almost certain to be invalid resources for whatever the ''url()'' shows up in.
	Linking on the web platform <em>does</em> allow empty urls,
	so if/when CSS gains some functionality to control hyperlinks,
	this restriction can be relaxed in those contexts.

<h4 id='url-modifiers'>
URL Modifiers</h4>

	<<url>>s support 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>functional notation</a>.

	This specification does not define any <<url-modifier>>s,
	but other specs may do so.

	Note: A <<url>> that is either unquoted or not wrapped in ''url()'' notation
	cannot accept any <<url-modifier>>s.

<h4 id='url-processing'>
URL Processing Model</h4>

	<div algorithm="style resource base URL">
		To compute the <dfn export>style resource base URL</dfn> for a [=CSS rule=] or a [=CSS declaration block=] |cssRuleOrDeclaration|:
			1. Let |sheet| be null.

			1. If |cssRuleOrDeclaration| is a [=CSS declaration block=] whose [=parent CSS rule=] is not null,
				set |cssRuleOrDeclaration| to |cssRuleOrDeclaration|'s [=parent CSS rule=].

			1. If |cssRuleOrDeclaration| is a [=CSS rule=], set |sheet| to |cssRuleOrDeclaration|'s {{CSSRule/parentStyleSheet|parent style sheet}}.

			1. If |sheet| is not null:
				1. If |sheet|'s <a spec=cssom>stylesheet base URL</a> is not null,
					return |sheet|'s <a spec=cssom>stylesheet base URL</a>.

				1. If |sheet|'s <a spec=cssom>location</a> is not null, return |sheet|'s <a spec=cssom>location</a>.

			1. Return |cssRuleOrDeclaration|'s [=relevant settings object=]'s [=environment settings object/API base URL=].

	</div>

	<div algorithm="resolve a style resource URL">
		To <dfn>resolve a style resource URL</dfn> from a [=/url=] or <<url>> |urlValue|,
		and a [=CSS rule=] or a [=CSS declaration block=] |cssRuleOrDeclaration|:
			1. Let |base| be the [=style resource base URL=] given |cssRuleOrDeclaration|.
			1. Return the result of the [=URL parser=] steps with |urlValue|'s [=/url=] and |base|.
	</div>

	<div algorithm="fetch a style resource">
		To <dfn export>fetch a style resource</dfn> from a [=/url=] or <<url>> |urlValue|,
		given an [=CSS rule=] or a [=css declaration block=] |cssRuleOrDeclaration|,
		a string |destination| matching a {{RequestDestination}},
		a "no-cors" or "cors" |corsMode|,
		and an algorithm |processResponse| accepting a [=/response=]
		and a null, failure or byte stream:

		1. Let |parsedUrl| be the result of [=resolve a style resource URL|resolving=] |urlValue| given |cssRuleOrDeclaration|.
			If that failed, return.

		1. Let |settingsObject| be |cssRuleOrDeclaration|'s [=relevant settings object=].

		4. Let |req| be a new [=/request=] whose [=request/url=] is |parsedUrl|,
			whose [=request/destination=] is |destination|,
			[=request/mode=] is |corsMode|,
			[=request/origin=] is |settingsObject|'s [=environment settings object/origin=],
			[=request/credentials mode=] is "same-origin",
			[=request/use-url-credentials flag=] is set,
			[=request/client=] is |settingsObject|,
			and whose [=request/referrer=] is "client".

		5. If |corsMode| is "no-cors", set |req|'s [=request/credentials mode=] to "include".

		6. Apply any <dfn export>URL request modifier steps</dfn> that apply to this request.

			Note: This specification does not define any URL request modification steps,
			but other specs may do so.

		7. If |req|'s [=request/mode=] is "cors", and |sheet| is not null, then
			set |req|'s [=request/referrer=] to the [=style resource base URL=] given |cssRuleOrDeclaration|. [[CSSOM]]

		8. If |sheet|'s <a spec=cssom>origin-clean flag</a> is set,
			set |req|'s [=request/initiator type=] to "css". [[CSSOM]]

		9. [=/Fetch=] |req|,
			with [=fetch/processresponseconsumebody|processResponseConsumeBody=] set to |processResponse|.
	</div>

	When interpreting [=URLs=] expressed in CSS,
	the [=URL parser's=] <var ignore>encoding</var> argument
	must be omitted
	(i.e. use the default, UTF-8),
	regardless of the stylesheet encoding.

	Note: In other words, a URL written in CSS
	will always <l spec=url>[=string/percent-encode after encoding|percent-encode=]</l> non-ASCII codepoints
	using UTF-8 in the [=URL=] object
	(and thus whenever using the [=URL=] value for e.g. network requests),
	regardless of the stylesheet's own encoding.
	Note that this occurs [[css-syntax-3#input-byte-stream|after decoding the stylesheet]]
	into Unicode [=code points=].

<h2 id="numeric-types">
Numeric Data Types</h2>

	Numeric data types are used to represent
	quantities, indexes, positions, and other such values.
	Although many syntactic variations can exist
	in expressing the quantity (numeric aspect) in a given numeric value,
	the <a lt="specified value">specified</a> and <a>computed value</a>
	do not distinguish these variations:
	they represent the value’s abstract quantity,
	not its syntactic representation.

	The <dfn>numeric data types</dfn> include
	<<integer>>,
	<<number>>,
	<<percentage>>,
	and various <a>dimensions</a>
	including <<length>>, <<angle>>, <<time>>, <<frequency>>, and <<resolution>>.

	Note: While general-purpose <a>dimensions</a> are defined here,
	some other modules define additional data types
	(e.g. [[css-grid-1]] introduces ''fr'' units)
	whose usage is more localized.

	The precision and supported range of numeric values in CSS
	is [=implementation-defined=],
	and can vary based on the property or other context a value is used in.
	However, within the CSS specifications,
	infinite precision and range is assumed.
	When a value cannot be explicitly supported due to range/precision limitations,
	it must be converted to the closest value supported by the implementation,
	but how the implementation defines "closest" is [=implementation-defined=] as well.

	If an <<angle>> must be converted
	due to exceeding the implementation-defined range of supported values,
	it must be clamped to the nearest supported multiple of ''360deg''.

<h3 id="numeric-ranges">
Range Restrictions and Range Definition Notation</h3>

	Properties can restrict numeric values to some range.
	If the value is outside the allowed range,
	then unless otherwise specified,
	the declaration is invalid and must be <a href="https://www.w3.org/TR/CSS2/conform.html#ignore">ignored</a>.
	Range restrictions can be annotated in the numeric type notation
	using <dfn export local-lt="bracketed range notation">CSS bracketed range notation</dfn>--
	<code>[<var>min</var>,<var>max</var>]</code>--
	within the angle brackets, after the identifying keyword,
	indicating a closed range
	between (and including) <var>min</var> and <var>max</var>.
	For example, <<integer [0,10]>> indicates an integer between ''0'' and ''10'', inclusive,
	while <<angle [0, 180deg]>> indicates an angle between ''0deg'' and ''180deg''
	(expressed in any unit).

	Note: CSS values generally do not allow open ranges;
	thus only square-bracket notation is used.

	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.
	Range extremes that are ideally unlimited
	are indicated using ∞ or &minus;∞ as appropriate.
	For example, <<length [0, ∞]>> indicates a non-negative length.

	If no range is indicated,
	either by using the <a>bracketed range notation</a>
	or in the property description,
	then <code>[&minus;∞,∞]</code> is assumed.

	Values of &minus;∞ or ∞ must be written without units,
	even if the value type uses units.
	Values of ''0'' <em>can</em> be written without units,
	even if the value type doesn't allow “unitless zeroes”
	(such as <<time>>).

	Note: At the time of writing,
	the <a>bracketed range notation</a> is new;
	thus in most CSS specifications
	any range limitations are described only in prose.
	(For example, “Negative values are not allowed” or
	“Negative values are invalid”
	indicate a <code>[0,∞]</code> range.)
	This does not make them any less binding.

<!--
	The recommended minimum ranges and precision,
	and the required rounding and clamping rules,
	are given in <a href="#required-ranges">Appendix A</a>.
-->

<!-- Big Text: integer

████ █    █▌ █████▌ █████▌  ███▌  █████▌ ████▌
 ▐▌  █▌   █▌   █▌   █▌     █▌  █▌ █▌     █▌  █▌
 ▐▌  ██▌  █▌   █▌   █▌     █▌     █▌     █▌  █▌
 ▐▌  █▌▐█ █▌   █▌   ████   █▌ ██▌ ████   ████▌
 ▐▌  █▌  ██▌   █▌   █▌     █▌  █▌ █▌     █▌▐█
 ▐▌  █▌   █▌   █▌   █▌     █▌  █▌ █▌     █▌ ▐█
████ █▌   ▐▌   █▌   █████▌  ███▌  █████▌ █▌  █▌
-->

<h3 id="integers">
Integers: the <<integer>> type</h3>

	Integer values are denoted by <dfn id="integer-value">&lt;integer></dfn>.

	When written literally,
	an <dfn export>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 [[!CSS-SYNTAX-3]].
	The first digit of an integer may be immediately preceded by <css>-</css> or <css>+</css>
	to indicate the integer's sign.

	<wpt>
	css/css-multicol/multicol-count-non-integer-001.xht
	css/css-multicol/multicol-count-non-integer-002.xht
	css/css-multicol/multicol-count-non-integer-003.xht
	css/CSS2/values/numbers-units-001.xht
	css/CSS2/values/numbers-units-004.xht
	</wpt>

	Unless otherwise specified,
	in the CSS specifications
	<dfn for=CSS export lt="round to the nearest integer">rounding to the nearest integer</dfn>
	requires rounding in the direction of +∞
	when the fractional portion is exactly 0.5.
	(For example, ''1.5'' rounds to ''2'', while ''-1.5'' rounds to ''-1''.)

<h4 id="combine-integers">
Computation and Combination of <<integer>></h4>

	Unless otherwise specified,
	the <a>computed value</a> of a specified <<integer>>
	is the specified abstract integer.

	<a>Interpolation</a> of <<integer>> is defined as
	<var>V</var><sub>result</sub> =
		round((1 - <var>p</var>) &times; <var>V<sub>A</sub></var> +
		<var>p</var> &times; <var>V<sub>B</sub></var>);
	that is, interpolation happens in the real number space
	as for <<number>>s, and the result is converted to an <<integer>>
	by [=rounding to the nearest integer=].

	<a>Addition</a> of <<integer>> is defined as
	<var>V<sub>result</sub></var> =
		<var>V<sub>A</sub></var> + <var>V<sub>B</sub></var>

	<wpt>
	css/css-values/calc-positive-fraction-001.html
	css/css-values/rgba-011.html
	</wpt>

<!-- Big Text: number

█    █▌ █▌  █▌ █     █ ████▌  █████▌ ████▌
█▌   █▌ █▌  █▌ ██   ██ █▌  █▌ █▌     █▌  █▌
██▌  █▌ █▌  █▌ █▌█ █▐█ █▌  █▌ █▌     █▌  █▌
█▌▐█ █▌ █▌  █▌ █▌ █ ▐█ █████  ████   ████▌
█▌  ██▌ █▌  █▌ █▌   ▐█ █▌  █▌ █▌     █▌▐█
█▌   █▌ █▌  █▌ █▌   ▐█ █▌  █▌ █▌     █▌ ▐█
█▌   ▐▌  ███▌  █▌   ▐█ ████▌  █████▌ █▌  █▌
-->

<h3 id="numbers">
Real Numbers: the <<number>> type</h3>

	Number values are denoted by <dfn id="number-value">&lt;number></dfn>,
	and represent real numbers, possibly with a fractional component.

	<wpt>
	css/css-animations/animation-iteration-count-calc.html
	css/CSS2/values/numbers-units-002.xht
	css/CSS2/values/numbers-units-003.xht
	</wpt>

	When written literally,
	a <dfn export>number</dfn> is either an <a>integer</a>,
	or zero or more decimal digits followed by a dot (.) followed by one or more decimal digits;
	optionally, it can be concluded by the letter “e” or “E”
	followed by an integer indicating the base-ten exponent
	in <a href="https://en.wikipedia.org/wiki/Scientific_notation">scientific notation</a>.
	It corresponds to the <<number-token>> production
	in the <a href="https://www.w3.org/TR/css-syntax/">CSS Syntax Module</a> [[!CSS-SYNTAX-3]].
	As with integers, the first character of a number
	may be immediately preceded by <css>-</css> or <css>+</css>
	to indicate the number's sign.

	The value <dfn id=zero-value>&lt;zero></dfn> represents a literal <a>number</a>
	with the value 0.
	Expressions that merely evaluate to a <<number>> with the value 0
	(for example, ''calc(0)'')
	do not match <<zero>>;
	only literal <<number-token>>s do.

<h4 id="combine-numbers">
Computation and Combination of <<number>></h4>

	Unless otherwise specified,
	the <a>computed value</a> of a specified <<number>>
	is the specified abstract number.

	<a>Interpolation</a> of <<number>> is defined as
	<var>V</var><sub>result</sub> =
		(1 - <var>p</var>) &times; <var>V<sub>A</sub></var> +
		<var>p</var> &times; <var>V<sub>B</sub></var>

	<a>Addition</a> of <<number>> is defined as
	<var>V<sub>result</sub></var> =
		<var>V<sub>A</sub></var> + <var>V<sub>B</sub></var>

<h3 id='dimensions'>
Numbers with Units: <a>dimension</a> values</h3>

	The general term <dfn export>dimension</dfn> refers to
	a number with a unit attached to it;
	and is denoted by <dfn>&lt;dimension></dfn>.

	When written literally,
	a <a>dimension</a> is a <a>number</a>
	immediately followed by a unit identifier,
	which is an [=CSS/identifier=].
	It corresponds to the <<dimension-token>> production
	in the <a href="https://www.w3.org/TR/css-syntax/">CSS Syntax Module</a> [[!CSS-SYNTAX-3]].
	Like keywords, unit identifiers are <a>ASCII case-insensitive</a>.

	<wpt>
	css/css-values/angle-units-003.html
	</wpt>

	CSS uses <<dimension>>s to specify
	distances (<<length>>),
	durations (<<time>>),
	frequencies (<<frequency>>),
	resolutions (<<resolution>>),
	and other quantities.

<h4 id="compat">
Compatible Units</h4>

	When <a href="https://www.w3.org/TR/cssom-1/#serializing-css-values">serializing</a> <a>computed values</a> [[!CSSOM]],
	<dfn export local-lt=compatible>compatible units</dfn>
	(those related by a static multiplicative factor,
	like the 96:1 factor between ''px'' and ''in'',
	or the computed 'font-size' factor between ''em'' and ''px'')
	are converted into a single <dfn export local-lt=canonical>canonical unit</dfn>.
	Each group of compatible units defines which among them is the <a>canonical unit</a>
	that will be used for serialization.

	When serializing <a href="https://www.w3.org/TR/cssom-1/#resolved-values">resolved values</a>
	that are <a>used values</a>,
	all value types (percentages, numbers, keywords, etc.)
	that represent lengths are considered <a>compatible</a> with lengths.
	Likewise any future API that returns <a>used values</a>
	must consider any values that represent distances/durations/frequencies/etc.
	as <a>compatible</a> with the relevant class of <a>dimensions</a>,
	and canonicalize accordingly.

	<wpt>
	css/css-values/calc-serialization-002.html
	</wpt>

<h4 id="combine-dimensions">
Combination of Dimensions</h4>

	<a>Interpolation</a> of <a>compatible</a> <a>dimensions</a>
	(for example, two <<length>> values)
	is defined as
	<var>V</var><sub>result</sub> =
		(1 - <var>p</var>) &times; <var>V<sub>A</sub></var> +
		<var>p</var> &times; <var>V<sub>B</sub></var>

	<a>Addition</a> of <a>compatible</a> <a>dimensions</a> is defined as
	<var>V<sub>result</sub></var> =
		<var>V<sub>A</sub></var> + <var>V<sub>B</sub></var>

<!-- Big Text: %

▐█▌  █
█ █ ▐▌
▐█▌ █
   ▐▌
   █ ▐█▌
  ▐▌ █ █
  █  ▐█▌
-->

<h3 id="percentages">
Percentages: the <<percentage>> type</h3>

	Percentage values are denoted by <dfn id="percentage-value">&lt;percentage></dfn>,
	and indicates a value that is some fraction of another reference value.

	When written literally,
	a <dfn export>percentage</dfn> consists of a <a>number</a>
	immediately followed by a percent sign <css>%</css>.
	It corresponds to the <<percentage-token>> production
	in the <a href="https://www.w3.org/TR/css-syntax/">CSS Syntax Module</a> [[!CSS-SYNTAX-3]].

	Percentage values are always relative to another quantity,
	for example a length.
	Each property that allows percentages also defines the quantity to which the percentage refers.
	This quantity can be a value of another property for the same element,
	the value of a property for an ancestor element,
	a measurement of the formatting context
	(e.g., the width of a <a>containing block</a>),
	or something else.

	<wpt>
	css/CSS2/values/numbers-units-016.xht
	css/CSS2/values/numbers-units-017.xht
	</wpt>

<h4 id="combine-percentages">
Computation and Combination of <<percentage>></h4>

	Unless otherwise specified
	(such as in 'font-size', which computes its <<percentage>> values to <<length>>),
	the <a>computed value</a> of a percentage
	is the specified percentage.

	<a>Interpolation</a> of <<percentage>> is defined as
	<var>V</var><sub>result</sub> =
		(1 - <var>p</var>) &times; <var>V<sub>A</sub></var> +
		<var>p</var> &times; <var>V<sub>B</sub></var>

	<a>Addition</a> of <<percentage>> is defined as
	<var>V<sub>result</sub></var> =
		<var>V<sub>A</sub></var> + <var>V<sub>B</sub></var>

<h3 id="mixed-percentages">
Mixing Percentages and Dimensions</h3>

	In cases where a <<percentage>> can represent the same quantity
	as a <a>dimension</a> in the same <a>component value</a> position,
	and can therefore be combined with them in a ''calc()'' expression,
	the following convenience notations may be used in the property grammar:

	: <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>>.

	<div class="example">
		For example, the 'width' property can accept a <<length>> or a <<percentage>>,
		both representing a measure of distance.
		This means that ''width: calc(500px + 50%);'' is allowed--
		both values are converted to absolute lengths and added.
		If the containing block is ''1000px'' wide,
		then ''width: 50%;'' is equivalent to ''width: 500px'',
		and ''width: calc(50% + 500px)'' thus ends up equivalent to ''width: calc(500px + 500px)'' or ''width: 1000px''.

		On the other hand, the second and third arguments of the ''hsl()'' function
		can only be expressed as <<percentage>>s.
		Although ''calc()'' productions are allowed in their place,
		they can only combine percentages with themselves,
		as in ''calc(10% + 20%)''.
	</div>

	Note: Specifications should never alternate <<percentage>> in place of a dimension
	in a grammar unless they are <a>compatible</a>.

	Note: More &lt;<var ignore>type</var>-percentage> productions can be added in the future as needed.
	A &lt;number-percentage> will never be added,
	as <<number>> and <<percentage>> can't be combined in ''calc()''.

<h4 id="combine-mixed">
Computation and Combination of Percentage and Dimension Mixes</h4>

	The [=computed value=] of a percentage-dimension mix is defined as

	* a computed dimension if the percentage component is zero
		or is defined specifically to compute to a dimension value
	* a computed percentage if the dimension component is zero
	* a [[#calc-computed-value|computed calc() expression]] otherwise

	<a>Interpolation</a> of percentage-dimension value combinations
	(e.g. <<length-percentage>>, <<frequency-percentage>>, <<angle-percentage>>, <<time-percentage>>
	or equivalent notations)
	is defined as
	<ul>
		<li>
			equivalent to <a>interpolation</a> of <<length>>
			if both <var>V<sub>A</sub></var> and <var>V<sub>B</sub></var> are pure <<length>> values

		<li>
			equivalent to <a>interpolation</a> of <<percentage>>
			if both <var>V<sub>A</sub></var> and <var>V<sub>B</sub></var> are pure <<percentage>> values
		<li>
			equivalent to converting both values into a ''calc()'' expression
			representing the sum of the dimension type and a percentage
			(each possibly zero)
			and <a>interpolating</a> each component individually
			(as a <<length>>/<<frequency>>/<<angle>>/<<time>>
			and as a <<percentage>>, respectively)
	</ul>

	<a>Addition</a> of <<percentage>> is defined
	the same as <a>interpolation</a>
	except by <a>adding</a> each component
	rather than <a>interpolating</a> it.

<h3 id='ratios'>
Ratios: the <<ratio>> type</h3>

	Ratio values are denoted by <dfn id=ratio-value>&lt;ratio></dfn>,
	and represent the ratio of two numeric values.
	It most often represents an aspect ratio,
	relating a width (first) to a height (second).

	When written literally,
	a <dfn export>ratio</dfn> has the syntax:

	<pre class=prod>
		<<ratio>> = <<number [0,∞]>> [ / <<number [0,∞]>> ]?
	</pre>

	The second <<number>> is optional,
	defaulting to ''1''.
	However, <<ratio>> is always serialized with both components.

	The computed value of a <<ratio>> is the pair of numbers provided.

	If either number in the <<ratio>> is 0 or infinite,
	it represents a <dfn export>degenerate ratio</dfn>
	(and, generally, won't do anything).

	If two <<ratio>>s need to be compared,
	divide the first number by the second,
	and compare the results.
	For example, <css>3/2</css> is less than <css>2/1</css>,
	because it resolves to 1.5 while the second resolves to 2.
	(In other words, “tall” aspect ratios are less than “wide” aspect ratios.)

<h4 id='combine-ratio'>
Combination of <<ratio>></h4>

	The interpolation of a <<ratio>> is defined
	by converting each <<ratio>> to a number
	by dividing the first value by the second
	(so a ratio of ''3 / 2'' would become ''1.5''),
	taking the logarithm of that result
	(so the ''1.5'' would become approximately ''0.176''),
	then interpolating those values.
	The result during the interpolation
	is converted back to a <<ratio>>
	by inverting the logarithm,
	then interpreting the result as a <<ratio>>
	with the result as the first value and ''1'' as the second value.

	If either <<ratio>> is [=degenerate ratio|degenerate=],
	the values cannot be interpolated.

	<div class='example'>
		For example,
		halfway through a linear interpolation from ''5 / 1'' to ''3 / 2'',
		the result is approximately the ratio ''2.73 / 1''
		(roughly ''11 / 4'', slightly taller than a ''3 / 1'' ratio):

		<pre>
		start  = log(5);   // ≈ 0.69897
		end    = log(1.5); // ≈ 0.17609
		interp = 0.69897*.5 + 0.17609*.5; // ≈ 0.43753
		final  = 10^interp; // ≈ 2.73
		</pre>
	</div>

	Note: Interpolating over the logarithm of the ratio
	means the results are scale-independent
	(''5 / 1'' to ''300 / 200'' would give the same results as above),
	that they're symmetrical over "wide" and "tall" variants
	(interpolating from ''1 / 5'' to ''2 / 3'' would give
	a ratio approximately equal to ''1 / 2.73'' at the halfway point),
	and that they're symmetrical over whether the width is fixed and the height is based on the ratio
	or vice versa.
	These properties are not shared by many other possible interpolation strategies.

	Note: Due to the properties of logarithms,
	any log can be used;
	the example here uses base-10 log,
	but if, say, the natural log and e was used,
	the intermediate results would be different
	but the final result would be the same.

	Addition of <<ratio>>s is not possible.

<!-- Big Text: length

█▌    █████▌ █    █▌  ███▌  █████▌ █▌  █▌
█▌    █▌     █▌   █▌ █▌  █▌   █▌   █▌  █▌
█▌    █▌     ██▌  █▌ █▌       █▌   █▌  █▌
█▌    ████   █▌▐█ █▌ █▌ ██▌   █▌   █████▌
█▌    █▌     █▌  ██▌ █▌  █▌   █▌   █▌  █▌
█▌    █▌     █▌   █▌ █▌  █▌   █▌   █▌  █▌
█████ █████▌ █▌   ▐▌  ███▌    █▌   █▌  █▌
-->

<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>.

	For zero lengths the unit identifier is optional
	(i.e. can be syntactically represented as the <<number>> ''0'').
	However, if a ''0'' could be parsed as either a <<number>> or a <<length>> in a property
	(such as 'line-height'),
	it must parse as a <<number>>.

	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="https://www.w3.org/TR/CSS2/conform.html#ignore">ignored</a>.

	<wpt>
	css/mediaqueries/min-width-001.xht
	css/CSS2/values/numbers-units-005.xht
	css/CSS2/values/numbers-units-006.xht
	</wpt>

	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:
	[=relative length|relative=] and [=absolute length|absolute=].
	The [=specified value=] of a length (<dfn export>specified length</dfn>) is
	represented by its quantity and its unit.
	The [=computed value=] of a length (<dfn export>computed length</dfn>) is
	the [=specified length=] resolved to an [=absolute length=],
	and its unit is not distinguished:
	it can be represented by any [=absolute length unit=]
	(but will be serialized using its [=canonical unit=], ''px'').

	<wpt>
	css/css-values/calc-unit-analysis.html
	css/css-shapes/shape-outside/values/shape-outside-circle-002.html
	css/css-shapes/shape-outside/values/shape-outside-circle-004.html
	css/css-shapes/shape-outside/values/shape-outside-ellipse-002.html
	css/css-shapes/shape-outside/values/shape-outside-ellipse-004.html
	css/css-shapes/shape-outside/values/shape-outside-inset-003.html
	css/css-shapes/shape-outside/values/shape-outside-polygon-004.html
	</wpt>

	While the exact supported precision of numeric values,
	and how they are rounded to match that precision,
	is generally [=implementation-defined=],
	<<length>>s in 'border-width' and a few other properties
	are rounded in a specific fashion
	to ensure reasonable visual display.
	(This algorithm is called by individual properties explicitly.)

	<div algorithm>
		To <dfn export lt="snap as a line width | snap a length as a line width | snap a length as a border width | snap as a border width">snap a length as a line width</dfn>
		given a <<length>> |len|:

		1. If |len| is an integer number of [=device pixels=],
			do nothing.

		2. If the absolute value of |len| is greater than zero, but less than 1 [=device pixel=],
			round it away from zero to 1 or -1 [=device pixel=].

		4. If the absolute value of |len| is greater than 1 [=device pixel=],
			round it towards zero to the nearest integer number of [=device pixels=].
	</div>

<h3 id="relative-lengths">
Relative Lengths</h3>

	<dfn lt="relative length | relative length unit">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>''cap''
			<td>cap height (the nominal height of capital letters) of the element's font
		<tr><td>''ch''
			<td>typical <a lt="advance measure">character advance</a>
				of a narrow glyph in the element’s font,
				as represented by the “0” (ZERO, U+0030) glyph
		<tr><td>''ic''
			<td>typical <a lt="advance measure">character advance</a>
				of a fullwidth glyph in the element’s font,
				as represented by the “水” (CJK water ideograph, U+6C34) glyph
		<tr><td>''rem''
			<td>font size of the root element
		<tr><td>''lh''
			<td>line height of the element
		<tr><td>''rlh''
			<td>line height of the root element
		<tr><td>''vw''
			<td>1% of viewport's width
		<tr><td>''vh''
			<td>1% of viewport's height
		<tr><td>''vi''
			<td>1% of viewport's size in the root element's <a>inline axis</a>
		<tr><td>''vb''
			<td>1% of viewport's size in the root element's <a>block axis</a>
		<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>.

<!-- Big Text: em/etc

█████▌ █     █    █ █████▌ █████▌  ███▌
█▌     ██   ██   ▐▌ █▌       █▌   █▌  █▌
█▌     █▌█ █▐█   █  █▌       █▌   █▌
████   █▌ █ ▐█  ▐▌  ████     █▌   █▌
█▌     █▌   ▐█  █   █▌       █▌   █▌
█▌     █▌   ▐█ ▐▌   █▌       █▌   █▌  █▌
█████▌ █▌   ▐█ █    █████▌   █▌    ███▌
-->

<h4 id="font-relative-lengths">
Font-relative Lengths: the ''em'', ''rem'', ''ex'', ''rex'', ''cap'', ''rcap'', ''ch'', ''rch'', ''ic'', ''ric'', ''lh'', ''rlh'' units</h4>

	The <dfn export id="font-relative-length">font-relative lengths</dfn>
	refer to the font metrics
	either of the element on which they are used
	(for the <dfn export>local font-relative lengths</dfn>)
	or of the root element
	(for the <dfn export>root font-relative lengths</dfn>).

	<figure>
		<img src="images/Typography_Line_Terms.svg" width=361 height=97 alt="The word 'Sphinx' annotated with various font metrics: ascender height, to the top of the h's serif; cap height, to the visually approximate top of the S; the x height, to the visually approximate top of the x; the baseline, along the bottom of S, h, i, n, and x; and the descender height, to the bottom fo the p.">
		<figcaption>
			Common typographic metrics
		</figcaption>
	</figure>

	<dl export dfn-type=value dfn-for="<length>">
		<dt><dfn id="em" lt="em | em unit">em</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 id="rem" lt="rem | rem unit" caniuse="rem">rem</dfn>
		<dd>
			Equal to the computed value of the ''em'' unit on the root element.

			<wpt>
			css/css-values/calc-rem-lang.html
			</wpt>

		<dt><dfn id="ex" lt="ex | ex unit">ex</dfn>
		<dd>
			Equal to the used x-height of the <a href="https://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.

			<wpt>
			css/css-values/ex-unit-001.html
			css/css-values/ex-unit-002.html
			css/css-values/ex-unit-003.html
			css/CSS2/values/numbers-units-007.xht
			css/CSS2/values/numbers-units-009.xht
			css/CSS2/values/numbers-units-010.xht
			css/CSS2/values/numbers-units-011.xht
			css/CSS2/values/numbers-units-012.xht
			css/CSS2/values/numbers-units-013.xht
			css/CSS2/values/numbers-units-015.xht
			css/CSS2/values/numbers-units-019.xht
			css/CSS2/values/units-001.xht
			css/CSS2/values/units-002.xht
			css/CSS2/values/units-003.xht
			css/CSS2/values/units-004.xht
			css/CSS2/values/units-005.xht
			css/css-values/calc-ch-ex-lang.html
			</wpt>

		<dt><dfn id="rex" lt="rex | rex unit">rex</dfn>
		<dd>
			Equal to the value of the ''ex'' unit on the root element.

		<dt><dfn id="cap" lt="cap | cap unit">cap</dfn>
		<dd>
			Equal to the used cap-height of the <a href="https://www.w3.org/TR/css3-fonts/#first-available-font">first available font</a> [[!CSS3-FONTS]].
			The cap-height is so called because it is approximately equal to the height of a capital Latin letter.
			However, a ''cap'' is defined even for fonts that do not contain Latin letters.
			The cap-height of a font can be found in different ways.
			Some fonts contain reliable metrics for the cap-height.
			If reliable font metrics are not available,
			[=UAs=] may determine the cap-height from the height of an uppercase glyph.
			One possible heuristic is to look at
			how far the glyph for the uppercase “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 cap-height,
			the font's ascent must be used.

		<dt><dfn id="rcap" lt="rcap | rcap unit">rcap</dfn>
		<dd>
			Equal to the value of the ''cap'' unit on the root element.

		<dt><dfn id="ch" lt="ch | ch unit" caniuse="ch-unit">ch</dfn>
		<dd>
			Represents the typical <a>advance measure</a> of European alphanumeric characters,
			and measured as the used <a>advance measure</a> of the “0” (ZERO, U+0030) glyph
			in the font used to render it.
			(The <dfn dfn>advance measure</dfn> of a glyph is its advance width or height,
			whichever is in the inline axis of the element.)

			Note: This measurement is an approximation
			(and in monospace fonts, an exact measure)
			of a single narrow glyph’s <a>advance measure</a>,
			thus allowing measurements based on an expected glyph count.

			Note: The advance measure of a glyph depends on writing-mode and text-orientation
			as well as font settings, text-transform, and any other properties that affect glyph selection or orientation.

			In the cases where it is impossible or impractical to determine the measure of the “0” glyph,
			it must be assumed to be 0.5em wide by 1em tall.
			Thus, the ''ch'' unit falls back to ''0.5em'' in the general case,
			and to ''1em'' when it would be typeset upright
			(i.e. 'writing-mode' is ''vertical-rl'' or ''vertical-lr''
			and 'text-orientation' is ''text-orientation/upright'').

			<wpt>
			css/css-values/ch-unit-001.html
			css/css-values/ch-unit-002.html
			css/css-values/ch-unit-003.html
			css/css-values/ch-unit-004.html
			css/css-values/ch-unit-008.html
			css/css-values/ch-unit-009.html
			css/css-values/ch-unit-010.html
			css/css-values/ch-unit-011.html
			css/css-values/ch-unit-012.html
			css/css-values/ch-unit-016.html
			css/css-values/ch-unit-017.html
			css/css-values/line-break-ch-unit.html
			css/css-values/calc-ch-ex-lang.html
			</wpt>

		<dt><dfn id="rch" lt="rch | rch unit">rch</dfn>
		<dd>
			Equal to the value of the ''ch'' unit on the root element.

		<dt><dfn id="ic" lt="ic | ic unit">ic</dfn>
		<dd>
			Represents the typical <a>advance measure</a> of CJK letters,
			and measured as the used <a>advance measure</a> of the “水” (CJK water ideograph, U+6C34) glyph
			found in the font used to render it.

			Note: This measurement is a typically an exact measure
			(in the few fonts with proportional fullwidth glyphs, an approximation)
			of a single <a href="http://unicode.org/reports/tr11/#Definitions">fullwidth</a> glyph’s <a>advance measure</a>,
			thus allowing measurements based on an expected glyph count.

			In the cases where it is impossible or impractical to determine the ideographic advance measure,
			it must be assumed to be 1em.

			<wpt>
			css/css-values/ic-unit-001.html
			css/css-values/ic-unit-002.html
			css/css-values/ic-unit-003.html
			css/css-values/ic-unit-004.html
			css/css-values/ic-unit-008.html
			css/css-values/ic-unit-009.html
			css/css-values/ic-unit-010.html
			css/css-values/ic-unit-011.html
			css/css-values/ic-unit-012.html
			</wpt>

		<dt><dfn id="ric" lt="ric | ric unit">ric</dfn>
		<dd>
			Equal to the value of the ''ic'' unit on the root element.

		<dt><dfn id="lh" lt="lh | lh unit">lh</dfn>
		<dd>
			Equal to the computed value of the 'line-height' property of the element on which it is used,
			converting ''line-height/normal'' to an absolute length
			by using only the metrics of the <a href="https://www.w3.org/TR/css3-fonts/#first-available-font">first available font</a>.

			<wpt>
			css/css-values/lh-rlh-on-root-001.html
			css/css-values/lh-unit-001.html
			css/css-values/lh-unit-002.html
			</wpt>

		<dt><dfn id="rlh" lt="rlh | rlh unit">rlh</dfn>
		<dd>
			Equal to the value of the ''lh'' unit on the root element.

			Note: Setting the 'height' of an element using either the ''lh'' or the ''rlh'' units
			does not enable authors to control the actual number of lines in that element.
			These units only enable length calculations based on the theoretical size of an ideal empty line;
			the size of actual lines boxes may differ based on their content.
			In cases where an author wants to limit the number of actual lines in an element,
			the 'max-lines' property can be used instead.

			<wpt>
			css/css-values/lh-rlh-on-root-001.html
			</wpt>

	</dl>

	When used in the value of any 'font-*' property on the element they refer to,
	the [=font-relative lengths=] resolve against the computed metrics of the parent element--
	or against the computed metrics corresponding to the initial values
	of the 'font' and 'line-height' properties,
	if the element has no parent.
	Similarly,
	when ''lh'' or ''rlh'' units are used
	in the value of the 'line-height' property or 'font-*' properties on the element they refer to,
	they resolve against the computed 'line-height' and font metrics of the parent element--
	or the computed metrics corresponding to the initial values
	of the 'font' and 'line-height' properties,
	if the element has no parent.
	(The other font-relative lengths continue to resolve against
	the element’s own metrics when used in 'line-height'.)

	When used outside the context of an element
	(such as in <a>media queries</a>),
	the [=font-relative lengths=] units refer to the metrics corresponding
	to the initial values of the 'font' and 'line-height' properties.
	Similarly, when specified in a document with no root element,
	the [=root font-relative lengths=] are resolved
	assuming the initial values of the 'font' and 'line-height' properties.

	Note: Font-relative units such as ''ch'' and ''ic'' can trigger font downloads,
	if a required font is not yet loaded.

	The [=font-relative lengths=] are calculated in the absence of shaping.

	Some user-agents allow users to apply additional restrictions to font sizes in a document,
	such as setting minimum font sizes to ensure readability.
	Such restrictions must be applied to the [=used value=] of the affected properties only;
	they <em>must not</em> affect the resolution of [=font-relative lengths=] used in properties.
	However, in other contexts
	(such as in [=media queries=]),
	to the extent that they would impact the used font metrics,
	such restrictions <em>do</em> affect the resolution of [=font-relative lengths=].

	Note: In general, respecting a user's preferences, like minimum font sizes,
	is desirable;
	it's useful for a media query like ''(min-width: 40em)''
	to use the actual font size the document will be displayed in.
	However, having these preferences affect font-relative lengths <em>in properties on an element</em>
	was found to not be Web-compatible;
	too many pages expect these units to be exact multiples of the specified 'font-size',
	rather than the <em>actual</em> font-size after applying user preferences.

	Some user-agents apply restrictions to the 'line-height' values on form controls.
	These must have no effect on the ''lh'' and ''rlh'' units.
	The effect on their descendants, however, is [=implementation-defined=].

<!-- Big Text: vw/etc

█▌   █▌ █▌    █▌    █ █████▌ █████▌  ███▌
█▌   █▌ █▌    █▌   ▐▌ █▌       █▌   █▌  █▌
█▌   █▌ █▌    █▌   █  █▌       █▌   █▌
▐▌   █  █▌    █▌  ▐▌  ████     █▌   █▌
 █  ▐▌  █▌ ▐  █▌  █   █▌       █▌   █▌
 ▐▌ █   █▌ █▌ █▌ ▐▌   █▌       █▌   █▌  █▌
  ▐█     ██ ▐█▌  █    █████▌   █▌    ███▌
-->

<h4 id="viewport-relative-lengths" caniuse="viewport-units">
Viewport-percentage Lengths: the ''*vw'', ''*vh'', ''*vi'', ''*vb'', ''*vmin'', ''*vmax'' units</h4>

	The <dfn export>viewport-percentage lengths</dfn> are relative to the size of the
	<a href="https://www.w3.org/TR/CSS2/visudet.html#containing-block-details">initial containing block</a>--
	which is itself based on the size of either
	the viewport (for [=continuous media=])
	or the [=page area=] (for [=paged media=]).
	When the height or width of the initial containing block is changed,
	they are scaled accordingly.

<h5 id="viewport-variants" class="no-toc">
The Large, Small, and Dynamic Viewport Sizes</h5>

	There are four variants of the [=viewport-percentage length=] units,
	corresponding to three (possibly identical) notions of the viewport size.

	<dl export>
		<dt>large viewport
		<dd>
			The <dfn export>large viewport-percentage units</dfn>
			(''lv*'')
			and <dfn export>default viewport-percentage units</dfn>
			(''v*'')
			are defined with respect to the <dfn export>large viewport size</dfn>:
			the viewport sized assuming
			any [=UA=] interfaces that are dynamically expanded and retracted
			to be retracted.
			This allows authors to size content
			such that it is guaranteed to fill the viewport,
			noting that such content might be hidden behind such interfaces
			when they are expanded.

			The sizes of the [=large viewport-percentage units=] are fixed
			(and therefore stable) unless the viewport itself is resized.

			<div class=example>
				For example, on phones,
				where screen real-estate is at a premium,
				browsers will often hide part or all of the title and address bar
				once the user starts scrolling the page.
				The [=large viewport-percentage units=] are sized relative to
				this larger everything-retracted space,
				so content using these units will fill the entire visible page
				when these UI elements are hidden.
				However, when these retractable elements are shown,
				they can obscure content
				that is sized or positioned using these units.
			</div>

		<dt>small viewport
		<dd>
			The <dfn export>small viewport-percentage units</dfn>
			(''sv*'')
			are defined with respect to the <dfn export>small viewport size</dfn>:
			the viewport sized assuming
			any [=UA=] interfaces that are dynamically expanded and retracted
			to be expanded.
			This allows authors to size content
			such that it can fit within the viewport
			even when such interfaces are present,
			noting that such content might not fill the viewport
			when such interfaces are retracted.

			The sizes of the [=small viewport-percentage units=] are fixed
			(and therefore stable) unless the viewport itself is resized.

			<div class=example>
				An element that is sized as ''height: 100svh'', for example,
				will fill the screen perfectly,
				without any of its content being obscured,
				when all the dynamic UI elements of the UA are shown.

				Once those UI elements start being hidden, however,
				there will be extra space around the element.
				The [=small viewport-percentage units=] units are thus “safer” in general,
				but might not produce the most attractive layout
				once the user starts interacting with the page.
			</div>

		<dt>dynamic viewport
		<dd>
			The <dfn export>dynamic viewport-percentage units</dfn>
			(''dv*'')
			are defined with respect to the <dfn export>dynamic viewport size</dfn>:
			the viewport sized
			with dynamic consideration of any [=UA=] interfaces
			that are dynamically expanded and retracted.
			This allows authors to size content
			such that it can exactly fit within the viewport
			whether or not such interfaces are present.

			The sizes of the [=dynamic viewport-percentage units=]
			<em>are not stable</em>
			even while the viewport itself is unchanged.
			Using these units can cause content
			to resize e.g. while the user scrolls the page.
			Depending on usage,
			this can be disturbing to the user
			and/or costly in terms of performance.

			The UA is not required to animate the [=dynamic viewport-percentage units=]
			while expanding and retracting any relevant interfaces,
			and may instead calculate the units
			as if the relevant interface was fully expanded or retracted
			during the UI animation.
			(It is recommended that UAs assume the fully-retracted size
			for this duration.)
	</dl>

	Whether the expansion/retraction of a particular interface
	(A)
	changes the sizes of all of the [=viewport-percentage lengths=]
	(and the [=initial containing block=])
	simultaneously
	or (B)
	contributes to the differences between
	the [=large viewport size=] and [=small viewport size=]
	is largely UA-dependent.
	However:

	* Changes in interface that happen as a result of scrolling
		or other frequent page interactions that would disturb the user
		if they resulted in substantial layout changes
		must be categorized as the latter (B).

	* Changes in interface that have a sufficiently steady state
		that re-laying out the document into the adjusted space
		would be beneficial to the user
		must be categorized as the former (A).

	* Additionally,
		UAs may have some dynamically-shown interfaces
		that intentionally overlay content
		and do not cause any shifts in layout--
		and therefore have no effect on any of the [=viewport-percentage lengths=].
		(Typically on-screen keyboards will fit into this category.)

	In all cases,
	if the value of 'overflow' or 'scrollbar-gutter' on the [=root element=] in either axis
	would cause scrollbars to appear (or space to be reserved for them) unconditionally
	(for example, ''overflow: scroll'', but not ''overflow: auto''),
	the [=computed values=] of the [=viewport-percentage lengths=] in that axis
	are reduced in accordance with the [=initial containing block=].
	Otherwise,
	and always in the case of [=media queries=],
	the [=viewport-percentage lengths=] are sized
	assuming that scrollbars do not exist
	(even if this diverges from the [=initial containing block=]).

	Note: The value of 'overflow' on [=the body element=]
	can sometimes affect the presence of scrollbars on the [=root element=].
	This <em>does not</em> affect the size of viewport units, however.

<h5 id="viewport-relative-units" class="no-toc">
The Various Viewport-relative Units</h5>

	The [=viewport-percentage length=] units are:

	<dl export dfn-type=value dfn-for="<length>">
		<dt><dfn id="vw">vw</dfn>
		<dt><dfn id="svw">svw</dfn>
		<dt><dfn id="lvw">lvw</dfn>
		<dt><dfn id="dvw">dvw</dfn>
		<dd>
			Equal to 1% of the width of the
			[=large viewport size=],
			[=small viewport size=],
			[=large viewport size=],
			and [=dynamic viewport size=],
			respectively.

			<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 id="vh">vh</dfn>
		<dt><dfn id="svh">svh</dfn>
		<dt><dfn id="lvh">lvh</dfn>
		<dt><dfn id="dvh">dvh</dfn>
		<dd>
			Equal to 1% of the height of the
			[=large viewport size=],
			[=small viewport size=],
			[=large viewport size=],
			and [=dynamic viewport size=],
			respectively.

		<dt><dfn id=vi>vi</dfn>
		<dt><dfn id=svi>svi</dfn>
		<dt><dfn id=lvi>lvi</dfn>
		<dt><dfn id=dvi>dvi</dfn>
		<dd>
			Equal to 1% of the size of the
			[=large viewport size=],
			[=small viewport size=],
			[=large viewport size=],
			and [=dynamic viewport size=]
			(respectively)
			in the box’s [=inline axis=].

		<dt><dfn id=vb>vb</dfn>
		<dt><dfn id=svb>svb</dfn>
		<dt><dfn id=lvb>lvb</dfn>
		<dt><dfn id=dvb>dvb</dfn>
		<dd>
			Equal to 1% of the size of the initial containing block
			[=large viewport size=],
			[=small viewport size=],
			[=large viewport size=],
			and [=dynamic viewport size=]
			(respectively)
			in the box’s [=block axis=].

		<dt><dfn id="vmin">vmin</dfn>
		<dt><dfn id="svmin">svmin</dfn>
		<dt><dfn id="lvmin">lvmin</dfn>
		<dt><dfn id="dvmin">dvmin</dfn>
		<dd>
			Equal to the smaller of ''*vw'' or ''*vh''.

		<dt><dfn id="vmax">vmax</dfn>
		<dt><dfn id="svmax">svmax</dfn>
		<dt><dfn id="lvmax">lvmax</dfn>
		<dt><dfn id="dvmax">dvmax</dfn>
		<dd>
			Equal to the larger of ''*vw'' or ''*vh''.
	</dl>

	<wpt>
	css/css-values/vh-calc-support-pct.html
	css/css-values/vh-calc-support.html
	css/css-values/vh-em-inherit.html
	css/css-values/vh-inherit.html
	css/css-values/vh-interpolate-pct.html
	css/css-values/vh-interpolate-px.html
	css/css-values/vh-interpolate-vh.html
	css/css-values/vh-support.html
	css/css-values/vh-support-margin.html
	css/css-values/vh-support-transform-origin.html
	css/css-values/vh-support-transform-translate.html
	css/css-values/vh-zero-support.html
	css/css-values/viewport-relative-lengths-scaled-viewport.html
	css/css-values/viewport-unit-011.html
	css/css-values/viewport-units-css2-001.html
	</wpt>

	Note: The original (unprefixed) viewport units
	<a href="https://www.w3.org/TR/css-values-3/#viewport-relative-lengths">were defined</a>
	relative to the [=initial containing block=],
	which in [=continuous media=] always matched the (singular) viewport size.
	The dynamism of browser chrome shifting in and out during scrolling was invented later,
	and following Safari's lead, most UAs mapped these units to the larger size.
	Defining it this way is prettier in many cases,
	but can also block critical content (such as toolbars, headers, and footers) in others.
	It's therefore not entirely clear whether this was the best mapping,
	and thus earlier editions of this specifications
	allowed UAs to choose the mapping of these default units.
	However at this point the mapping to the [=large viewport-percentage units=]
	is presumed to be required for Web compatibility.

	In situations where there is no element
	or it hasn't yet been styled
	(such as when evaluating <a>media queries</a>),
	the ''*vi'' and ''*vb'' units use the initial value of the 'writing-mode' property
	to determine which axis they correspond to.

<!-- Big Text: px/etc

████▌  █     █    █ █████▌ █████▌  ███▌
█▌  █▌  █   █    ▐▌ █▌       █▌   █▌  █▌
█▌  █▌   █ █     █  █▌       █▌   █▌
████▌     █     ▐▌  ████     █▌   █▌
█▌       █ █    █   █▌       █▌   █▌
█▌      █   █  ▐▌   █▌       █▌   █▌  █▌
█▌     █     █ █    █████▌   █▌    ███▌
-->

<h3 id="absolute-lengths">
Absolute Lengths: the ''cm'', ''mm'', ''Q'', ''in'', ''pt'', ''pc'', ''px'' units</h3>

	The <dfn lt="absolute length | absolute length unit">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 export lt="physical unit">physical units</dfn> (''in'', ''cm'', ''mm'', ''pt'', ''pc'', ''Q'')
	and the <dfn export lt="visual angle unit | pixel unit">visual angle unit (pixel unit)</dfn> (''px''):

	<table class="data" export>
	<thead>
		<tr>
			<th>unit
			<th>name
			<th>equivalence
	<tbody dfn-type=value dfn-for="<length>">
		<tr>
			<th><dfn id="cm">cm</dfn>
			<td>centimeters
			<td>1cm = 96px/2.54
		<tr>
			<th><dfn id="mm">mm</dfn>
			<td>millimeters
			<td>1mm = 1/10th of 1cm
		<tr>
			<th><dfn id="Q">Q</dfn>
			<td>quarter-millimeters
			<td>1Q = 1/40th of 1cm
		<tr>
			<th><dfn id="in">in</dfn>
			<td>inches
			<td>1in = 2.54cm = 96px
		<tr>
			<th><dfn id="pc">pc</dfn>
			<td>picas
			<td>1pc = 1/6th of 1in
		<tr>
			<th><dfn id="pt">pt</dfn>
			<td>points
			<td>1pt = 1/72nd of 1in
		<tr>
			<th><dfn id="px" lt="px">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>

	Note: Lengths in publishing contexts
	are sometimes written like <code>2p3</code>,
	indicating a length of 2 picas and 3 points.
	These can be written in CSS as ''calc(2pc + 3pt)''
	(see [[#calc-func]]).

	All of the absolute length units are <a>compatible</a>,
	and ''px'' is their <a>canonical unit</a>.

	For a CSS device, these dimensions are <dfn lt="anchor unit | anchor">anchored</dfn> either

	<ol type=i>
		<li>by relating the <a>physical units</a> to their physical measurements, or
		<li>by relating the <a>pixel unit</a> to the <a>reference pixel</a>.
	</ol>

	For print media at typical viewing distances,
	the [=anchor unit=] should be one of the [=physical units=] (inches, centimeters, etc).
	For screen media (including high-resolution devices),
	low-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: 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: This definition of the [=pixel unit=] and the [=physical units=]
	differs from the earlier editions of CSS1 and CSS2.
	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 unfortunate change
	was made because too much existing content relies on the assumption of 96dpi,
	and breaking that assumption broke the content.)

	Note: Units are [=ASCII case-insensitive=] and serialize as lowercase, for example 1Q serializes as 1q.

	<wpt>
	css/css-values/absolute-length-units-001.html
	css/css-values/q-unit-case-insensitivity-001.html
	css/css-values/q-unit-case-insensitivity-002.html
	css/CSS2/values/units-001.xht
	css/CSS2/values/units-006.xht
	css/CSS2/values/units-008.xht
	css/CSS2/values/units-009.xht
	</wpt>

	The <dfn export>reference pixel</dfn> is the visual angle of one pixel on a device with a [=device pixel=] density of 96dpi
	and a distance from the reader of an arm's length.
	For a nominal arm's length of 28 inches,
	the visual angle is therefore about 0.0213 degrees.
	For reading at arm's length,
	1px thus corresponds to about 0.26&nbsp;mm (1/96&nbsp;inch).

	The image below illustrates the effect of viewing distance on the size of a reference pixel:
	a reading distance of 71&nbsp;cm (28&nbsp;inches)
	results in a reference pixel of 0.26&nbsp;mm,
	while a reading distance of 3.5&nbsp;m (12&nbsp;feet)
	results in a reference pixel of 1.3&nbsp;mm.

	<figure>
		<img src="images/pixel1.png" width="500" height="360"
		     alt="This diagram illustrates how the definition of a pixel
		          depends on the users distance from the viewing surface
		          (paper or screen).
		          The image depicts the user looking at two planes,
		          one 28 inches (71 cm) from the user,
		          the second 140 inches (3.5 m) from the user.
		          An expanding cone is projected from the user's eye onto each plane.
		          Where the cone strikes the first plane,
		          the projected pixel is 0.26 mm high.
		          Where the cone strikes the second plane,
		          the projected pixel is 1.4 mm high.">
		<figcaption>
			Showing that pixels must become larger if the viewing distance increases
		</figcaption>
	</figure>

	This second image illustrates the effect of a device's resolution on the pixel unit:
	an area of 1px by 1px is covered by a single dot in a low-resolution device
	(e.g. a typical computer display),
	while the same area is covered by 16 dots in a higher resolution device
	(such as a printer).

	<figure>
		<img src="images/pixel2.png" width="412" height="321"
		     alt="This diagram illustrates the relationship between
		          the reference pixel and device pixels (called “dots” below).
		          The image depicts
		          a high resolution (large dot density) laser printer output on the left
		          and a low resolution monitor screen on the right.
		          For the laser printer, one square reference pixel is implemented by 16 dots.
		          For the monitor screen, one square reference pixel is implemented by a single dot.">
		<figcaption>
			Showing that more device pixels (dots) are needed
			to cover a 1px by 1px area on a high-resolution device
			than on a lower-resolution one
			(of the same approximate viewing distance)
		</figcaption>
	</figure>

	<wpt>
	css/css-values/absolute-length-units-001.html
	</wpt>

	A <dfn export>device pixel</dfn> is the smallest unit of area on the device output
	capable of displaying its full range of colors.
	For typical color screens, it's a square or somewhat rectangular region
	containing a red, green, and blue subpixel.
	Many non-traditional outputs exist that can blur this definition,
	such as by displaying some colors at higher resolutions.
	Such devices still expose some equivalent notion of "device pixel",
	however.

<h2 id="other-units">
Other Quantities</h2>

<!-- Big Text: angle

 ███▌  █    █▌  ███▌  █▌    █████▌
▐█ ▐█  █▌   █▌ █▌  █▌ █▌    █▌
█▌  █▌ ██▌  █▌ █▌     █▌    █▌
█▌  █▌ █▌▐█ █▌ █▌ ██▌ █▌    ████
█████▌ █▌  ██▌ █▌  █▌ █▌    █▌
█▌  █▌ █▌   █▌ █▌  █▌ █▌    █▌
█▌  █▌ █▌   ▐▌  ███▌  █████ █████▌
-->

<h3 id="angles">
Angle Units: the <<angle>> type and ''deg'', ''grad'', ''rad'', ''turn'' units</h3>

	Angle values are <<dimension>>s denoted by <dfn id="angle-value">&lt;angle></dfn>.
	The angle unit identifiers are:

	<dl export dfn-type=value dfn-for="<angle>">
		<dt><dfn id="deg">deg</dfn>
		<dd>
			Degrees. There are 360 degrees in a full circle.

		<dt><dfn id="grad">grad</dfn>
		<dd>
			Gradians, also known as "gons" or "grades".
			There are 400 gradians in a full circle.

		<dt><dfn id="rad">rad</dfn>
		<dd>
			Radians. There are 2&pi; radians in a full circle.

		<dt><dfn id="turn">turn</dfn>
		<dd>
			Turns. There is 1 turn in a full circle.
	</dl>

	For example, a right angle is ''90deg'' or ''100grad'' or ''0.25turn'' or
	approximately ''1.57rad''.

	All <<angle>> units are <a>compatible</a>,
	and ''deg'' is their <a>canonical unit</a>.

	<div class="note">
		By convention,
		when an angle denotes a direction in CSS,
		it is typically interpreted as a <dfn export>bearing angle</dfn>,
		where 0deg is "up" or "north" on the screen,
		and larger angles are more clockwise
		(so 90deg is "right" or "east").

		For example, in the ''linear-gradient()'' function,
		the <<angle>> that determines the direction of the gradient
		is interpreted as a bearing angle.
	</div>

	Note: For legacy reasons,
	some uses of <<angle>> allow a bare ''0'' to mean ''0deg''.
	This is not true in general, however,
	and will not occur in future uses of the <<angle>> type.

	<wpt>
	css/css-values/angle-units-001.html
	css/css-values/angle-units-002.html
	css/css-values/angle-units-003.html
	css/css-values/angle-units-004.html
	css/css-values/angle-units-005.html
	css/css-values/calc-angle-values.html
	</wpt>

<!-- Big Text: time

█████▌ ████ █     █ █████▌
  █▌    ▐▌  ██   ██ █▌
  █▌    ▐▌  █▌█ █▐█ █▌
  █▌    ▐▌  █▌ █ ▐█ ████
  █▌    ▐▌  █▌   ▐█ █▌
  █▌    ▐▌  █▌   ▐█ █▌
  █▌   ████ █▌   ▐█ █████▌
-->

<h3 id="time">
Duration Units: the <<time>> type and ''s'', ''ms'' units</h3>

	Time values are <a>dimensions</a> denoted by <dfn id="time-value">&lt;time></dfn>.
	The time unit identifiers are:

	<dl export dfn-type=value dfn-for="<time>">
		<dt><dfn id="s">s</dfn>
		<dd>Seconds.
		<dt><dfn id="ms">ms</dfn>
		<dd>Milliseconds. There are 1000 milliseconds in a second.
	</dl>

	All <<time>> units are <a>compatible</a>,
	and ''s'' is their <a>canonical unit</a>.

	Properties may restrict the time value to some range.
	If the value is outside the allowed range,
	the declaration is invalid and must be <a href="https://www.w3.org/TR/CSS2/conform.html#ignore">ignored</a>.

	<wpt>
	css/css-values/calc-time-values.html
	css/css-transitions/transition-delay-001.html
	css/css-transitions/transition-duration-001.html
	</wpt>

<!-- Big Text: frequency

█████▌ ████▌  █████▌  ███▌  █▌  █▌ █████▌ █    █▌  ███▌  █   ▐▌
█▌     █▌  █▌ █▌     █▌  █▌ █▌  █▌ █▌     █▌   █▌ █▌  █▌ ▐▌  █
█▌     █▌  █▌ █▌     █▌  █▌ █▌  █▌ █▌     ██▌  █▌ █▌      █ ▐▌
████   ████▌  ████   █▌  █▌ █▌  █▌ ████   █▌▐█ █▌ █▌      ▐▌█
█▌     █▌▐█   █▌     █▌▐ █▌ █▌  █▌ █▌     █▌  ██▌ █▌       █▌
█▌     █▌ ▐█  █▌     █▌ ▐▌  █▌  █▌ █▌     █▌   █▌ █▌  █▌   █▌
█▌     █▌  █▌ █████▌  ██▌ ▌  ███▌  █████▌ █▌   ▐▌  ███▌    █▌
-->

<h3 id="frequency">
Frequency Units: the <<frequency>> type and ''Hz'', ''kHz'' units</h3>

	Frequency values are <a>dimensions</a> denoted by <dfn id="frequency-value">&lt;frequency></dfn>.
	The frequency unit identifiers are:

	<dl export dfn-type=value dfn-for="<frequency>">
		<dt><dfn id="Hz">Hz</dfn>
		<dd>Hertz. It represents the number of occurrences per second.
		<dt><dfn id="kHz">kHz</dfn>
		<dd>KiloHertz. A kiloHertz is 1000 Hertz.
	</dl>

	For example, when representing sound pitches, 200Hz (or 200hz)
	is a bass sound, and 6kHz (or 6khz) is a treble sound.

	All <<frequency>> units are <a>compatible</a>,
	and ''hz'' is their <a>canonical unit</a>.

	Note: Units are [=ASCII case-insensitive=] and serialize as lowercase, for example 1Hz serializes as 1hz.

<!-- Big Text: reso

████▌  █████▌  ███▌   ███▌
█▌  █▌ █▌     █▌  █▌ █▌  █▌
█▌  █▌ █▌     █▌     █▌  █▌
████▌  ████    ███▌  █▌  █▌
█▌▐█   █▌         █▌ █▌  █▌
█▌ ▐█  █▌     █▌  █▌ █▌  █▌
█▌  █▌ █████▌  ███▌   ███▌
-->

<h3 id="resolution">
Resolution Units: the <<resolution>> type and ''<resolution>/dpi'', ''<resolution>/dpcm'', ''<resolution>/dppx'' units</h3>

	Resolution units are <a>dimensions</a> denoted by <dfn id="resolution-value">&lt;resolution></dfn>.
	The resolution unit identifiers are:

	<dl export dfn-type=value dfn-for="<resolution>">
		<dt><dfn id="dpi">dpi</dfn>
		<dd>Dots per inch.

		<dt><dfn id="dpcm">dpcm</dfn>
		<dd>Dots per centimeter.

		<dt><dfn id="dppx">dppx</dfn>
		<dt><dfn id="x">x</dfn>
		<dd>Dots per ''px'' unit.
	</dl>

	The <<resolution>> unit represents the size of a single "dot" in a graphical representation
	by indicating how many of these dots fit in a CSS ''in'', ''cm'', or ''px''.
	For uses, see e.g. the  ''resolution'' media query in [[MEDIAQ]]
	or the 'image-resolution' property defined in [[CSS3-IMAGES]].

	All <<resolution>> units are <a>compatible</a>,
	and ''<resolution>/dppx'' is their <a>canonical unit</a>.

	The allowed range of <<resolution>> values
	<em>always</em> excludes negative values,
	in addition to any explicit ranges that might be specified.

	<p class="note">Note that due to the 1:96 fixed ratio of CSS ''in'' to CSS ''px'',
	''1dppx'' is equivalent to ''96dpi''.
	This corresponds to the default resolution of images displayed in CSS:
	see 'image-resolution'.

	<div class="example">
		The following @media rule uses Media Queries [[MEDIAQ]]
		to assign some special style rules to devices that use two or more device pixels per CSS ''px'' unit:

		<pre>@media (min-resolution: 2dppx) { ... }</pre>
	</div>


<h2 id="defined-elsewhere">
Data Types Defined Elsewhere</h2>

	Some data types are defined in their own modules.
	This example talks about some of the most common ones
	used across several specifications.

<!-- Big Text: color

 ███▌   ███▌  █▌     ███▌  ████▌
█▌  █▌ █▌  █▌ █▌    █▌  █▌ █▌  █▌
█▌     █▌  █▌ █▌    █▌  █▌ █▌  █▌
█▌     █▌  █▌ █▌    █▌  █▌ ████▌
█▌     █▌  █▌ █▌    █▌  █▌ █▌▐█
█▌  █▌ █▌  █▌ █▌    █▌  █▌ █▌ ▐█
 ███▌   ███▌  █████  ███▌  █▌  █▌
-->

<h3 id="colors">
Colors: the <<color>> type</h3>

	The <<color>> data type is defined in [[!CSS-COLOR-4]].
	UAs must interpret <<color>> as defined therein.

<h4 id="combine-colors">
Combination of <<color>></h4>

	<a>Interpolation</a> of <<color>> is defined in
	[[css-color-4#interpolation]].
	Interpolation is done between premultiplied colors,
	as defined in
	[[css-color-4#interpolation-alpha]].

	The <<color>> type is <a>not additive</a>.

	Note: the CSS WG is interested to 
	<a href="https://github.com/w3c/csswg-drafts/issues/new">hear</a>
	use-cases for addition of <<color>>,
	and may consider making <<color>> additive in the future.


<!-- Big Text: image

████ █     █  ███▌   ███▌  █████▌
 ▐▌  ██   ██ ▐█ ▐█  █▌  █▌ █▌
 ▐▌  █▌█ █▐█ █▌  █▌ █▌     █▌
 ▐▌  █▌ █ ▐█ █▌  █▌ █▌ ██▌ ████
 ▐▌  █▌   ▐█ █████▌ █▌  █▌ █▌
 ▐▌  █▌   ▐█ █▌  █▌ █▌  █▌ █▌
████ █▌   ▐█ █▌  █▌  ███▌  █████▌
-->

<h3 id="images">
Images: the <<image>> type</h3>

	The <<image>> data type is defined in [[!CSS3-IMAGES]].
	UAs that support CSS Images Level 3 or its successor
	must interpret <<image>> as defined therein.
	UAs that do not yet support CSS Images Level 3
	must interpret <<image>> as <<url>>.

<h4 id="combine-images">
Combination of <<image>></h4>

	Note: Interpolation of <<image>> is defined in [[css-images-3#interpolation]].

	Images are <a>not additive</a>.

<!-- Big Text: position

████▌   ███▌   ███▌  ████ █████▌ ████  ███▌  █    █▌
█▌  █▌ █▌  █▌ █▌  █▌  ▐▌    █▌    ▐▌  █▌  █▌ █▌   █▌
█▌  █▌ █▌  █▌ █▌      ▐▌    █▌    ▐▌  █▌  █▌ ██▌  █▌
████▌  █▌  █▌  ███▌   ▐▌    █▌    ▐▌  █▌  █▌ █▌▐█ █▌
█▌     █▌  █▌     █▌  ▐▌    █▌    ▐▌  █▌  █▌ █▌  ██▌
█▌     █▌  █▌ █▌  █▌  ▐▌    █▌    ▐▌  █▌  █▌ █▌   █▌
█▌      ███▌   ███▌  ████   █▌   ████  ███▌  █▌   ▐▌
-->

<h3 id="position">
2D Positioning: the <<position>> type</h3>

	The <dfn><<position>></dfn> value specifies the position of a object area (e.g. background image)
	inside a positioning area (e.g. background positioning area).
	It is computed and interpreted as specified for 'background-position'. [[!CSS3-BACKGROUND]]

	<pre class=prod>
		<<position>> = [
		  [ left | center | right | top | bottom | <<length-percentage>> ]
		|
		  [ left | center | right ] && [ top | center | bottom ]
		|
		  [ left | center | right | <<length-percentage>> ]
		  [ top | center | bottom | <<length-percentage>> ]
		|
		  [ [ left | right ] <<length-percentage>> ] &&
		  [ [ top | bottom ] <<length-percentage>> ]
		]
	</pre>

	Note: The 'background-position' property also accepts a three-value syntax.
	This has been disallowed generically because it creates parsing ambiguities
	when combined with other length or percentage components in a property value.

<h4 id="position-parsing">
Parsing <<position>></h4>

	When specified in a grammar alongside other keywords, <<length>>s, or <<percentage>>s,
	<<position>> is <em>greedily</em> parsed;
	it consumes as many components as possible.

	<div class=example>
		For example,
		'transform-origin' defines a 3D position
		as (effectively) ''<<position>> <<length>>?''.
		A value such as ''left 50px''
		will be parsed as a 2-value <<position>>,
		with an omitted z-component;
		on the other hand,
		a value such as ''top 50px''
		will be parsed as a single-value <<position>>
		followed by a <<length>>.
	</div>

<h4 id="position-serialization">
Serializing <<position>></h4>

	When serializing the [=specified value=] of a <<position>>:

	<dl class=switch>
		<dt>If only one component is specified:
		<dd>
			* The implied <a value spec="css-backgrounds-3">center</a> keyword is added,
				and a 2-component value is serialized.

		<dt>If two components are specified:
		<dd>
			* Keywords are serialized as keywords.
			* <<length-percentage>>s are serialized as <<length-percentage>>s.
			* Components are serialized horizontal first, then vertical.

		<dt>If four components are specified:
		<dd>
			* Keywords and offsets are both serialized.
			* Components are serialized horizontal first, then vertical.
	</dl>

	Note: <<position>> values are never serialized as a single value,
	even when a single value would produce the same behavior,
	to avoid causing parsing ambiguities in some grammars
	where a <<position>> is placed next to a <<length>>,
	such as 'transform-origin'.

	Note: [=Computed values=] are always serialized as two offsets (without keywords)
	because the [=computed value=] does not preserve syntactic distinctions.


<h4 id="combine-positions">
Combination of <<position>></h4>

	<a>Interpolation</a> of <<position>> is defined as
	the independent interpolation of each component (x, y)
	normalized as an offset from the top left corner
	as a <<length-percentage>>.

	<a>Addition</a> of <<position>> is likewise defined as
	the independent <a>addition</a> each component (x, y)
	normalized as an offset from the top left corner
	as a <<length-percentage>>.


<!-- Big Text: funcs

█████▌ █▌  █▌ █    █▌  ███▌   ███▌
█▌     █▌  █▌ █▌   █▌ █▌  █▌ █▌  █▌
█▌     █▌  █▌ ██▌  █▌ █▌     █▌
████   █▌  █▌ █▌▐█ █▌ █▌      ███▌
█▌     █▌  █▌ █▌  ██▌ █▌         █▌
█▌     █▌  █▌ █▌   █▌ █▌  █▌ █▌  █▌
█▌      ███▌  █▌   ▐▌  ███▌   ███▌
-->

<h2 id="functional-notations">
Functional Notations</h2>

	A <dfn export>functional notation</dfn> is a type of component value
	that can represent more complex types or invoke special processing.
	The syntax starts with the name of the function
	immediately followed by a left parenthesis
	(i.e. a <<function-token>>)
	followed by the argument(s) to the notation
	followed by a right parenthesis.
	Like keywords, function names are [=ASCII case-insensitive=].
	<a href="https://www.w3.org/TR/css-syntax/#whitespace">White space</a> is allowed, but optional,
	immediately inside the parentheses.
	Functions can take multiple arguments,
	which are formatted similarly to a CSS property value.
	See [[#component-functions]].

	Note: Some legacy <a>functional notations</a>, such as ''rgba()'', use commas unnecessarily,
	but generally commas are only used to separate items in a list,
	or pieces of a grammar that would be ambiguous otherwise.
	If a comma is used to separate arguments,
	<a href="https://www.w3.org/TR/css-syntax/#whitespace">white space</a> is optional before and after the comma.

	<div class="example">
		<pre>
		background: url(http://www.example.org/image);
		color: rgb(100, 200, 50 );
		content: counter(list-item) ". ";
		width: calc(50% - 2em);
		</pre>
	</div>

	The [=math functions=] are defined below.
	Other [=functional notations=] are defined in their own modules;
	for example the <<color>> functions are defined in [[CSS-COLOR-4]] and [[CSS-COLOR-5]].

<h3 id="fuctional-serialization">
Serialization of Functional Notations</h3>

	<div algorithm="serialize a functional notation">
		Unless otherwise specified,
		to <dfn export>serialize a functional notation</dfn>:

		1. Let |s| be a string containing
			the function's name in lowercase,
			followed by “(” (U+0028 LEFT PARENTHESIS).

		2. Append to |s|
			the serializations of the arguments of the [=functional notation=]
			per their individual grammars,
			in the order the grammars are written in,
			joining space-separated tokens with a single space,
			and following each serialized comma, colon, semi-colon, or slash
			with a single space (U+0020 SPACE).
			When serializing the [=computed value=] or its derivatives
			(not [=specified values|specified=] or [=declared values|declared=] values),
			omit components when possible without changing the meaning.

		3. Append “)” (U+0029 RIGHT PARENTHESIS) to |s|.
	</div>

	ISSUE(9720): We are inconsistent in how we handled [=specified values=].

	<div class=example>
		For example, given a function like
		''LINEAR-GRADIENT( to bottom , red calc( 1em + 5% ) , green calc(130px / 2) , blue 100% )'':

		: as a [=specified value=]
		:: it will serialize as ''linear-gradient(to bottom, red calc(5% + 1em), green calc(65px), blue 100%)''
			* Function names and [=keywords=] become lowercase.
			* Whitespace is normalized:
				one space between most tokens, but no space
				after left parentheses/brackets,
				before right parentheses/brackets,
				or before commas
			* ''calc()'' arguments are simplified and sorted per [[#calc-serialize]]

		: as a [=computed value=]
		:: it will serialize as ''linear-gradient(red calc(5% + 16px), green calc(65px), blue)''

			* In addition to any [=specified value=] simplifications,
				any additional value [=computed value|computations=] are also applied,
				such as converting [=specified lengths=] to [=computed lengths=].
			* Values that match the default
				(e.g. ''to bottom'', the ''100%'' stop position on the final stop)
				are omitted entirely.
	</div>

<!-- Big Text: math

█     █  ███▌  █████▌ █▌  █▌
██   ██ ▐█ ▐█    █▌   █▌  █▌
█▌█ █▐█ █▌  █▌   █▌   █▌  █▌
█▌ █ ▐█ █▌  █▌   █▌   █████▌
█▌   ▐█ █████▌   █▌   █▌  █▌
█▌   ▐█ █▌  █▌   █▌   █▌  █▌
█▌   ▐█ █▌  █▌   █▌   █▌  █▌
-->

<h2 id="math" oldids="calc-notation" caniuse="calc">
Mathematical Expressions</h2>

	The <dfn export lt="math function">math functions</dfn>
	(''calc()'', ''clamp()'', ''sin()'',
	and others defined in this chapter)
	allow numeric CSS values
	to be written as mathematical expressions.

	A [=math function=] represents a numeric value,
	one of:

	* <<length>>,
	* <<frequency>>,
	* <<angle>>,
	* <<time>>,
	* <<flex>>,
	* <<resolution>>,
	* <<percentage>>,
	* <<number>>,
	* <<integer>>

	...or the <<length-percentage>>/etc mixed types,
	and can be used wherever such a value would be valid.

<!-- Big Text: calc()

 ███▌   ███▌  █▌     ███▌    ██ ██
█▌  █▌ ▐█ ▐█  █▌    █▌  █▌  █▌   ▐█
█▌     █▌  █▌ █▌    █▌     █▌     ▐█
█▌     █▌  █▌ █▌    █▌     █▌     ▐█
█▌     █████▌ █▌    █▌     █▌     ▐█
█▌  █▌ █▌  █▌ █▌    █▌  █▌  █▌   ▐█
 ███▌  █▌  █▌ █████  ███▌    ██ ██
-->

<h3 id=calc-func>
Basic Arithmetic: ''calc()''</h3>

	The <dfn>calc()</dfn> function is a [=math function=]
	that allows basic arithmetic to be performed on numerical values,
	using addition (<css>+</css>), subtraction (<css>-</css>), multiplication (<css>*</css>), division (<css>/</css>),
	and parentheses.

	A ''calc()'' function contains a single <dfn export for="calc()">calculation</dfn>,
	which is a sequence of values interspersed with operators,
	and possibly grouped by parentheses
	(matching the <<calc-sum>> grammar),
	which represents the result of evaluating the expression
	using standard operator precedence rules
	(<css>*</css> and <css>/</css> bind tighter than <css>+</css> and <css>-</css>,
	and operators are otherwise evaluated left-to-right).
	The ''calc()'' function represents the result of its contained [=calculation=].

	Components of a [=calculation=] can be literal values
	(such as ''5px''),
	other [=math functions=],
	or other expressions, such as ''var()'',
	that evaluate to a valid argument type (like <<length>>).

	<div class="example">

		[=Math functions=] can be used to combine value that use different units.
		In this example the author wants the <em>margin box</em> of each section
		to take up 1/3 of the space,
		so they start with <css>100%/3</css>,
		then subtract the element's borders and margins.
		('box-sizing' can automatically achieve this effect for borders and padding,
		but a [=math function=] is needed if you want to include margins.)

		<pre class=lang-css>
		section {
		  float: left;
		  margin: 1em; border: solid 1px;
		  width: calc(100% / 3 - 2 * 1em - 2 * 1px);
		}
		</pre>

		Similarly, in this example the gradient will show a color transition
		only in the first and last ''20px'' of the element:

		<pre class=lang-css>
		.fade {
			background-image: linear-gradient(silver 0%, white 20px,
			                                  white calc(100% - 20px), silver 100%);
		}
		</pre>
	</div>

	<div class="example">

		[=Math functions=] can also be useful just to express values
		in a more natural, readable fashion,
		rather than as an obscure decimal.
		For example, the following sets the 'font-size' so that exactly 35em fits within the viewport,
		ensuring that roughly the same amount of text always fills the screen no matter the screen size.

		<pre class=lang-css>
		:root {
			font-size: calc(100vw / 35);
		}
		</pre>

		Functionality-wise, this is identical to just writing ''font-size: 2.857vw'',
		but then the intent
		(that ''35em'' fills the viewport)
		is much less clear to someone reading the code;
		the later reader will have to reverse the math themselves
		to figure out that 2.857 is meant to approximate 100/35.
	</div>

	<div class="example">

		Standard mathematical precedence rules for the operators apply:
		''calc(2 + 3 * 4)'' is equal to ''14'',
		not ''20''.

		Parentheses can be used to manipulate precedence:
		''calc((2 + 3) * 4)'' is instead equal to ''20''.

		Parentheses and nesting additional ''calc()'' functions are equivalent;
		the preceding expression could equivalently have been written as
		''calc(calc(2 + 3) * 4)''.
		This can be useful when building up values piecemeal via ''var()'',
		such as in the following example:

		<pre class=lang-css>
		.aspect-ratio-box {
			--ar: calc(16 / 9);
			--w: calc(100% / 3);
			--h: calc(var(--w) / var(--ar));
			width: var(--w);
			height: var(--h);
		}
		</pre>

		Although '--ar' <em>could</em> have been written as simply
		''--ar: (16 / 9);'',
		'--w' is used both on its own (in 'width')
		and as a ''calc()'' component (in '--h'),
		so it has to be written as a full ''calc()'' function itself.
	</div>

	<wpt>
	css/css-values/calc-ch-ex-lang.html
	css/css-values/calc-in-color-001.html
	css/css-values/calc-in-font-feature-settings.html
	css/css-values/calc-rem-lang.html
	css/css-values/calc-rounding-001.html
	css/css-values/ex-calc-expression-001.html
	</wpt>


<!-- Big Text: min()

█     █ ████ █    █▌   ██ ██
██   ██  ▐▌  █▌   █▌  █▌   ▐█
█▌█ █▐█  ▐▌  ██▌  █▌ █▌     ▐█
█▌ █ ▐█  ▐▌  █▌▐█ █▌ █▌     ▐█
█▌   ▐█  ▐▌  █▌  ██▌ █▌     ▐█
█▌   ▐█  ▐▌  █▌   █▌  █▌   ▐█
█▌   ▐█ ████ █▌   ▐▌   ██ ██
-->

<h3 id=comp-func>
Comparison Functions: ''min()'', ''max()'', and ''clamp()''</h3>

	The comparison functions of ''min()'', ''max()'', and ''clamp()''
	compare multiple [=calculations=]
	and represent the value of one of them.

	The <dfn>min()</dfn> or <dfn>max()</dfn> functions
	contain one or more comma-separated [=calculations=],
	and represent the smallest (most negative) or largest (most positive) of them, respectively.

	The <dfn>clamp()</dfn> function takes three [=calculations=]--
	a minimum value, a central value, and a maximum value--
	and represents its central calculation,
	clamped according to its min and max calculations,
	favoring the min calculation if it conflicts with the max.
	(That is, given ''clamp(MIN, VAL, MAX)'',
	it represents exactly the same value as ''max(MIN, min(VAL, MAX))'').

	Either the min or max calculations
	(or even both)
	can instead be the keyword <dfn value for=clamp()>none</dfn>,
	which indicates the value is <em>not</em> clamped from that side.
	(That is, ''clamp(MIN, VAL, none)'' is equivalent to ''max(MIN, VAL)'',
	''clamp(none, VAL, MAX)'' is equivalent to ''min(VAL, MAX)'',
	and ''clamp(none, VAL, none)'' is equivalent to just ''calc(VAL)''.)

	For all three functions,
	the argument [=calculations=] can resolve to any <<number>>, <<dimension>>, or <<percentage>>,
	but must have a [=consistent type=]
	or else the function is invalid;
	the result's type will be the [=consistent type=].

	<div class="example">

		''min()'', ''max()'', and ''clamp()'' can be used to make sure a value doesn't exceed a "safe" limit:
		For example, "responsive type" that sets 'font-size' with viewport units
		might still want a minimum size to ensure readability:

		<pre class=lang-css>
		.type {
			/* Set font-size to 10x the average of vw and vh,
			   but don't let it go below 12px. */
			font-size: max(10 * (1vw + 1vh) / 2, 12px);
		}
		</pre>

		Note: Full math expressions are allowed in each of the arguments;
		there's no need to nest a ''calc()'' inside!
		You can also provide more than two arguments,
		if you have multiple constraints to apply.
	</div>

	<div class="example">
		An occasional point of confusion when using ''min()''/''max()''
		is that you use ''max()'' to impose a minimum value on something
		(that is, properties like 'min-width' effectively use ''max()''),
		and ''min()'' to impose a maximum value on something;
		it's easy to accidentally reach for the opposite function
		and try to use ''min()'' to add a minimum size.
		Using ''clamp()'' can make the code read more naturally,
		as the value is nestled between its minimum and maximum:

		<pre class=lang-css>
		.type {
			/* Force the font-size to stay between 12px and 100px */
			font-size: clamp(12px, 10 * (1vw + 1vh) / 2, 100px);
		}
		</pre>

		Or, if you only wanted to impose a minimum size,
		but allow the font-size to grow as large as it wants:

		<pre class=lang-css>
		.type {
			/* Force the font-size to be at least 12px */
			font-size: clamp(12px, 10 * (1vw + 1vh) / 2, none);
		}
		</pre>
	</div>


	<div class=note>
		Note that ''clamp()'',
		matching CSS conventions elsewhere,
		has its minimum value "win" over its maximum value
		if the two are in the "wrong order".
		That is, ''clamp(100px, ..., 50px)''
		will resolve to ''100px'',
		exceeding its stated "max" value.

		If alternate resolution mechanics are desired
		they can be achieved by combining ''clamp()'' with ''min()'' or ''max()'':

		: To have MAX win over MIN:
		::
			''clamp(min(MIN, MAX), VAL, MAX)''.
			If you want to avoid repeating the MAX calculation,
			you can just reverse the nesting of functions that ''clamp()'' is defined against--
			''min(MAX, max(MIN, VAL))''.

		: To have MAX and MIN "swap" when they're in the wrong order:
		::
			''clamp(min(MIN, MAX), VAL, max(MIN, MAX))''.
			Unfortunately, there's no easy way to do this without repeating the MIN and MAX terms.
	</div>

<!-- Big Text: round()

████▌   ███▌  █▌  █▌ █    █▌ ████▌    ██ ██
█▌  █▌ █▌  █▌ █▌  █▌ █▌   █▌ █▌  █▌  █▌   ▐█
█▌  █▌ █▌  █▌ █▌  █▌ ██▌  █▌ █▌  █▌ █▌     ▐█
████▌  █▌  █▌ █▌  █▌ █▌▐█ █▌ █▌  █▌ █▌     ▐█
█▌▐█   █▌  █▌ █▌  █▌ █▌  ██▌ █▌  █▌ █▌     ▐█
█▌ ▐█  █▌  █▌ █▌  █▌ █▌   █▌ █▌  █▌  █▌   ▐█
█▌  █▌  ███▌   ███▌  █▌   ▐▌ ████▌    ██ ██
-->
<h3 id=round-func>
Stepped Value Functions: ''round()'', ''mod()'', and ''rem()''</h3>

	The stepped-value functions,
	''round()'', ''mod()'', and ''rem()'',
	all transform a given value
	according to another "step value",
	in different ways.

	The <dfn lt="round()">round(<<rounding-strategy>>?, A, B?)</dfn> function
	contains an optional rounding strategy,
	and two [=calculations=] A and B,
	and returns the value of A,
	rounded according to the rounding strategy,
	to the nearest integer multiple of B either above or below A.
	The argument [=calculations=] can resolve to any <<number>>, <<dimension>>, or <<percentage>>,
	but must have a [=consistent type=]
	or else the function is invalid;
	the result's type will be the [=consistent type=].

	If A is exactly equal to an integer multiple of B,
	''round()'' resolves to A exactly
	(preserving whether A is 0⁻ or 0⁺, if relevant).
	Otherwise, there are two integer multiples of B that are potentially "closest" to A,
	|lower B| which is closer to −∞
	and |upper B| which is closer to +∞.
	The following <dfn><<rounding-strategy>></dfn>s dictate how to choose between them:

	<dl dfn-type=value dfn-for="<rounding-strategy>">
		: <dfn>nearest</dfn>
		:: Choose whichever of |lower B| and |upper B|
			that has the smallest absolute difference from A.
			If both have an equal difference
			(A is exactly between the two values),
			choose |upper B|.
		: <dfn>up</dfn>
		:: Choose |upper B|.
		: <dfn>down</dfn>
		:: Choose |lower B|.
		: <dfn>to-zero</dfn>
		:: Choose whichever of |lower B| and |upper B|
			that has the smallest absolute difference from 0.
		: <dfn>line-width</dfn>
		:: If B is omitted,
			A is [=snapped as a line width=].

			Otherwise round as for ''<rounding-strategy>/nearest'',
			except that if one of |lower B| or |upper B| is zero,
			the non-zero one is chosen,
			and the final result is [=snapped as a line width=].
	</dl>

	If |lower B| would be zero,
	it is specifically equal to 0⁺;
	if |upper B| would be zero,
	it is specifically equal to 0⁻.

	If <<rounding-strategy>> is omitted,
	it defaults to ''nearest''.
	(Aka [=rounding to the nearest integer=].)
	If <<rounding-strategy>> is ''<rounding-strategy>/line-width'',
	the [=CSSNumericValue/type=] of A
	must match <<length>>.

	If the [=CSSNumericValue/type=] of A
	matches <<number>>,
	then B may be omitted,
	and defaults to ''1''.
	If <<rounding-strategy>> is ''<rounding-strategy>/line-width'',
	B may also be omitted
	and has special behavior (defined above)
	essentially defaulting it to one device pixel.
	In all other cases,
	omitting B is invalid.

	Advisement: While ''round(line-width, ...)''
	attempts to ensure that non-zero values never round to zero,
	passing a sufficiently small A value
	might cause it to be represented as 0 internally anyway.
	Use caution when writing very small values;
	''round(line-width, 0.1px)'' is safer than ''round(line-width, 0.0001px)'',
	and the difference between the two is almost certainly nil in practice.

	Issue(5689): CSSOM needs to specify how it rounds,
	and it's probably good for CSS functions to round the same way by default.
	What behavior should be used?

	<div class=example>
		Unlike languages like JavaScript
		which have a natural "precision" to round to
		(integers),
		CSS values have no such precision
		because values can be written in many different compatible units.
		As such, the precision has to be given explicitly;
		to round a width to the nearest ''50px'',
		one can write ''round(var(--width), 50px)''.
	</div>

	Note: JavaScript and other programming languages
	sometimes separate out the rounding strategies into separate rounding functions.
	JS’s <code highlight=JS>Math.floor()</code>
	is equivalent to CSS's ''round(down, ...)'';
	JS’s <code highlight=JS>Math.ceil()</code>
	is equivalent to CSS's ''round(up, ...)'';
	JS’s <code highlight=JS>Math.trunc()</code>
	is equivalent to CSS's ''round(to-zero, ...)'';
	and JS’s <code highlight=JS>Math.round()</code>
	is equivalent to CSS's ''round(nearest, ...)'',
	or just ''round(...)''.

	Note: The <<rounding-strategy>> keywords
	are the same as the keywords in 'block-step-size'
	and have the same behavior.
	('block-step-size' just lacks ''to-zero'';
	since block sizes are always non-negative,
	''to-zero'' and ''down'' would be identical.)

	The modulus functions <dfn lt="mod()">mod(A, B)</dfn>
	and <dfn lt=rem()>rem(A, B)</dfn>
	similarly contain two [=calculations=] A and B,
	and return the difference between A
	and the nearest integer multiple of B either above or below A.
	The argument [=calculations=] can resolve to any <<number>>, <<dimension>>, or <<percentage>>,
	but must have the <em>same</em> [=determine the type of a calculation|type=],
	or else the function is invalid;
	the result will have the same [=CSSNumericValue/type=] as the arguments.

	The two functions are very similar,
	and in fact return identical results
	if both arguments are positive or both are negative:
	the value of the function is equal to the value of A
	shifted by the integer multiple of B
	that brings the value <dfn noexport>between zero and B</dfn>.
	(Specifically, the range includes zero
	and excludes B.
	More specifically, if B is positive the range starts at 0⁺,
	and if B is negative it starts at 0⁻.)

	<div class=example>
		For example, ''mod(18px, 5px)'' resolves to the value ''3px'',
		because subtracting ''5px * 3'' from ''18px'' yields ''3px'',
		which is the only such value between ''0px'' and ''5px''.

		Similarly, ''mod(-140deg, -90deg)'' resolves to the value ''-50deg'',
		because adding ''-90deg * 1'' to ''-140deg'' yields ''-50deg'',
		which is the only such value between ''0deg'' and ''-90deg''.

		Evaluating either of these examples with ''rem()'' yields the exact same results.
	</div>

	Their behavior diverges if the A value and the B step
	are on opposite sides of zero:
	''mod()'' (short for “modulus”)
	continues to choose the integer multiple of B
	that puts the value [=between zero and B=], as above
	(guaranteeing that the result will either be zero
	or share the sign of B, not A),
	while ''rem()'' (short for "remainder")
	chooses the integer multiple of B
	that puts the value [=between zero and B|between zero and -B=],
	avoiding changing the sign of the value.

	<div class=example>
		For example, ''mod(-18px, 5px)'' resolves to the value ''2px'':
		adding ''5px * 4'' to ''-18px'' yields ''2px'',
		which is between ''0px'' and ''5px''.

		On the other hand, ''rem(-18px, 5px)'' resolves to the value ''-3px'':
		adding ''5px * 3'' to ''-18px'' yields ''-3px'',
		which has the same sign as ''-18px''
		but is between ''0px'' and ''-5px''.

		Similarly, ''mod(140deg, -90deg)'' resolves to the value ''-40deg''
		(adding ''-90deg * 2'' to ''140deg'',
		bringing it to between ''0deg'' and ''-90deg''),
		but ''rem(140deg, -90deg)'' resolves to the value ''50deg''.
	</div>

	<details>
		<summary>When should I choose ''mod()'' vs ''rem()''?</summary>

		Typically, users of this operation
		are in control of the step value (B),
		and are modifying an unknown value A.
		As a result, it's <em>usually</em> more expected
		that the result is between 0 and B,
		regardless of A's sign,
		meaning ''mod()'' should be chosen.

		For example,
		if an author wants to know whether a length
		is an even or odd number of pixels,
		''mod(A, 2px)'' will return either ''0px'' or ''1px''
		(assuming the value is a whole number of pixels to begin with),
		regardless of the value of a.
		''rem(A, 2px)'', on the other hand,
		will return ''0px'' if A is an even number of pixels,
		but will return <em>either</em> ''1px'' or ''-1px''
		if it's odd,
		depending on whether A is positive or negative.

		The opposite situation does sometimes occur,
		however,
		and so ''rem()'' is provided to cater to that.
		As well, ''rem()'' is the behavior of JavaScript's <code highlight=js>%</code> operator,
		so if an exact match between CSS and JS code is desired,
		''rem()'' can be useful.
	</details>

	Note: ''mod()'' and ''rem()''
	can also be defined directly in terms of other functions:
	''mod(A, B)'' is equivalent to ''calc(A - sign(B)*round(down, A*sign(B), B))''
	(a hacky way to say "round(down) when B is positive, round(up) when B is negative),
	while ''rem(A, B)'' is equivalent to ''calc(A - round(to-zero, A, B))''.
	(These expressions don't always handle 0⁺ and 0⁻ correctly, though,
	because 0⁻ semantics aren't commutative for addition.)

<h4 id=round-infinities>
Argument Ranges</h4>

	In ''round(A, B)'',
	if B is 0,
	the result is NaN.
	If A and B are both infinite,
	the result is NaN.

	If A is infinite but B is finite,
	the result is the same infinity.

	If A is finite but B is infinite,
	the result depends on the <<rounding-strategy>>
	and the sign of A:

	: ''nearest''
	: ''to-zero''
	:: If A is positive or 0⁺, return 0⁺.
		Otherwise, return 0⁻.
	: ''up''
	:: If A is positive (not zero), return +∞.
		If A is 0⁺, return 0⁺.
		Otherwise, return 0⁻.
	: ''down''
	:: If A is negative (not zero), return −∞.
		If A is 0⁻, return 0⁻.
		Otherwise, return 0⁺.

	In ''mod(A, B)'' or ''rem(A, B)'',
	if B is 0,
	the result is NaN.
	If A is infinite,
	the result is NaN.

	In ''mod(A, B)'' only,
	if B is infinite
	and A has opposite sign to B
	(including an oppositely-signed zero),
	the result is NaN.

	Note: All other "infinite B" cases are valid,
	and just return A immediately.


<!--  Big Text: trig

█████▌ ████▌  ████  ███▌
  █▌   █▌  █▌  ▐▌  █▌  █▌
  █▌   █▌  █▌  ▐▌  █▌
  █▌   ████▌   ▐▌  █▌ ██▌
  █▌   █▌▐█    ▐▌  █▌  █▌
  █▌   █▌ ▐█   ▐▌  █▌  █▌
  █▌   █▌  █▌ ████  ███▌
-->

<h3 id=trig-funcs>
Trigonometric Functions: ''sin()'', ''cos()'', ''tan()'', ''asin()'', ''acos()'', ''atan()'', and ''atan2()''</h3>

	The trigonometric functions--
	''sin()'', ''cos()'', ''tan()'', ''asin()'', ''acos()'', ''atan()'', and ''atan2()''--
	compute the various basic trigonometric relationships.

	The <dfn lt="sin()">sin(A)</dfn>, <dfn lt="cos()">cos(A)</dfn>, and <dfn lt="tan()">tan(A)</dfn> functions
	all contain a single [=calculation=]
	which must resolve to either a <<number>>
	or an <<angle>>,
	and compute their corresponding function
	by interpreting the result of their argument as radians.
	(That is, ''sin(45deg)'', ''sin(.125turn)'', and ''sin(3.14159 / 4)''
	all represent the same value,
	approximately ''.707''.)
	They all represent a <<number>>,
	with the return type [=made consistent=]
	with the input [=calculation’s=] type.
	''sin()'' and ''cos()'' will always return a number between −1 and 1,
	while ''tan()'' can return any number between −∞ and +∞.
	(See [[#calc-type-checking]] for details on how [=math functions=] handle ∞.)

	The <dfn lt="asin()">asin(A)</dfn>, <dfn lt="acos()">acos(A)</dfn>, and <dfn lt="atan()">atan(A)</dfn> functions
	are the "arc" or "inverse" trigonometric functions,
	representing the inverse function to their corresponding "normal" trig functions.
	All of them contain a single [=calculation=]
	which must resolve to a <<number>>,
	and compute their corresponding function,
	interpreting their result as a number of radians,
	representing an <<angle>>
	with the return type [=made consistent=]
	with the input [=calculation’s=] type.
	The angle returned by ''asin()'' must be normalized to the range [''-90deg'', ''90deg''];
	the angle returned by ''acos()'' to the range [''0deg'', ''180deg''];
	and the angle returned by ''atan()'' to the range [''-90deg'', ''90deg''].

	The <dfn lt="atan2()">atan2(A, B)</dfn> function
	contains two comma-separated [=calculations=], A and B.
	A and B can resolve to any <<number>>, <<dimension>>, or <<percentage>>,
	but must have a [=consistent type=]
	or else the function is invalid.
	The function returns the <<angle>>
	between the positive X-axis and the point (B,A),
	with the return type [=made consistent=]
	with the input [=calculation’s=] type.
	The returned angle must be normalized to the interval (''-180deg'', ''180deg'']
	(that is, greater than ''-180deg'', and less than or equal to ''180deg'').

	Note: ''atan2(Y, X)'' is <em>generally</em> equivalent to ''atan(Y / X)'',
	but it gives a better answer when the point in question may include negative components.
	''atan2(1, -1)'', corresponding to the point (-1, 1),
	returns ''135deg'',
	distinct from ''atan2(-1, 1)'', corresponding to the point (1, -1),
	which returns ''-45deg''.
	In contrast, ''atan(1 / -1)'' and ''atan(-1 / 1)'' both return''-45deg'',
	because the internal calculation resolves to ''-1'' for both.


<h4 id="trig-infinities">
Argument Ranges</h4>

	In ''sin(A)'', ''cos(A)'', or ''tan(A)'',
	if A is infinite,
	the result is NaN.
	(See [[#calc-type-checking]] for details on how [=math functions=] handle NaN.)

	In ''sin(A)'' or ''tan(A)'',
	if A is 0⁻,
	the result is 0⁻.

	In ''tan(A)'', if A is one of the asymptote values
	(such as ''90deg'', ''270deg'', etc),
	the numeric result is [=implementation-defined=].
	If an implementation is capable of exactly representing these inputs,
	it <em>should</em> return
	+∞ for the asymptotes at <code>90deg + N*360deg</code>,
	and −∞ for the asymptotes at <code>-90deg + N*360deg</code>,
	but implementations are not required to be able to exactly represent these inputs
	(and if they can't, will return whatever the correct numeric answer is
	for the closest approximation to the input
	they are capable of representing).
	Authors <em>must not</em> rely on ''tan()'' returning any particular value
	for these inputs.

	<details class=note>
		<summary>Why are these [=implementation-defined=]?</summary>

		The tangent function is <em>discontinuous</em> at its asymptotes:
		it approaches infinity from one side
		<em>and</em> negative infinity from the other side,
		and isn't defined at the exact values of the asymptote.

		Further, whether or not the asymptotic values
		are exactly representable in implementations
		depends on how they internally store and manipulate angles;
		when written in degrees the values are simple (''90deg'', etc),
		but in radians the values are transcendental (''pi / 2'', etc)
		and cannot be exactly represented.
		So, even defining a specific behavior for these values is difficult;
		if an implementation uses radians internally,
		it would have to do some fuzzy matching
		to return the defined value
		when the input is <em>sufficiently close</em> to the asymptote.

		The other major language for the Web, JavaScript,
		exposes these functions as taking radians only,
		so it can't hit the exact asymptotes either
		(and this true for most other computer languages, too).
		Authors writing code in JS, then,
		can't rely on any specific behavior for these values either,
		and it's unlikely that their needs in CSS are significantly different.

		The suggested behavior for implementations that can exactly represent the asymptote values
		preserves round-tripping with the ''atan()'' function:
		''tan(atan(X))'' and ''atan(tan(X))''
		will both return (approximately) X
		for all possible X values,
		given this definition.
		It also means that within the supported output range of ''atan()'',
		the function is continuous.
	</details>

	In ''asin(A)'' or ''acos(A)'',
	if A is less than -1 or greater than 1,
	the result is NaN.

	In ''acos(A)'',
	if A is exactly 1,
	the result is 0.

	In ''asin(A)'' or ''atan(A)'',
	if A is 0⁻,
	the result is 0⁻.

	In ''atan(A)'',
	if A is +∞,
	the result is ''90deg'';
	if A is −∞,
	the result is ''-90deg''.

	In ''atan2(Y, X)'',
	the following table gives the results for all unusual argument combinations:

	<table class=data>
		<thead>
			<tr><td style="border:none" colspan=2><th colspan=6>X
			<tr><td style="border:none" colspan=2><th>−∞ <th>-finite <th>0⁻ <th>0⁺ <th>+finite <th>+∞
		</thead>
		<tr>
			<th rowspan=6 style="border-right:1px solid silver">Y
			<th style="border-right: black 2px solid">−∞
			<td>-135deg
			<td>-90deg
			<td>-90deg
			<td>-90deg
			<td>-90deg
			<td>-45deg
		<tr>
			<th>-finite
			<td>-180deg
			<td>(normal)
			<td>-90deg
			<td>-90deg
			<td>(normal)
			<td>0⁻deg
		<tr>
			<th>0⁻
			<td>-180deg
			<td>-180deg
			<td>-180deg
			<td>0⁻deg
			<td>0⁻deg
			<td>0⁻deg
		<tr>
			<th>0⁺
			<td>180deg
			<td>180deg
			<td>180deg
			<td>0⁺deg
			<td>0⁺deg
			<td>0⁺deg
		<tr>
			<th>+finite
			<td>180deg
			<td>(normal)
			<td>90deg
			<td>90deg
			<td>(normal)
			<td>0⁺deg
		<tr>
			<th>+∞
			<td>135deg
			<td>90deg
			<td>90deg
			<td>90deg
			<td>90deg
			<td>45deg
	</table>

	Note: All of these behaviors are intended to match the "standard" definitions of these functions
	as implemented by most programming languages,
	in particular as implemented in JS.

<!-- Big Text: pow/exp

████▌   ███▌  █▌    █▌    █ █████▌ █     █ ████▌
█▌  █▌ █▌  █▌ █▌    █▌   ▐▌ █▌      █   █  █▌  █▌
█▌  █▌ █▌  █▌ █▌    █▌   █  █▌       █ █   █▌  █▌
████▌  █▌  █▌ █▌    █▌  ▐▌  ████      █    ████▌
█▌     █▌  █▌ █▌ ▐  █▌  █   █▌       █ █   █▌
█▌     █▌  █▌ █▌ █▌ █▌ ▐▌   █▌      █   █  █▌
█▌      ███▌   ██ ▐█▌  █    █████▌ █     █ █▌
-->

<h3 id=exponent-funcs>
Exponential  Functions: ''pow()'', ''sqrt()'', ''hypot()'', ''log()'', ''exp()''</h3>

	The exponential functions--
	''pow()'', ''sqrt()'', ''hypot()'', ''log()'', and ''exp()''--
	compute various exponential functions with their arguments.

	The <dfn lt="pow()">pow(A, B)</dfn> function
	contains two comma-separated [=calculations=] A and B,
	both of which must resolve to <<number>>s,
	and returns the result of raising A to the power of B,
	returning the value as a <<number>>.
	The input [=calculations=]
	must have a [=consistent type=]
	or else the function is invalid;
	the result's type will be the [=consistent type=].

	The <dfn lt="sqrt()">sqrt(A)</dfn> function
	contains a single [=calculation=]
	which must resolve to a <<number>>,
	and returns the square root of the value
	as a <<number>>,
	with the return type [=made consistent=]
	with the input [=calculation’s=] type.
	(''sqrt(X)'' and ''pow(X, .5)'' are basically equivalent,
	differing only in some error-handling;
	''sqrt()'' is a common enough function
	that it is provided as a convenience.)

	The <dfn lt="hypot()">hypot(A, …)</dfn> function
	contains one or more comma-separated [=calculations=],
	and returns the length of an N-dimensional vector
	with components equal to each of the [=calculations=].
	(That is,
	the square root of the sum of the squares of its arguments.)
	The argument [=calculations=] can resolve to any <<number>>, <<dimension>>, or <<percentage>>,
	but must have a [=consistent type=]
	or else the function is invalid;
	the result's type will be the [=consistent type=].

	<details class=note>
		<summary>Why does ''hypot()'' allow dimensions (values with units), but ''pow()'' and ''sqrt()'' only work on numbers?</summary>

		You are allowed to write expressions like ''hypot(30px, 40px)'',
		which resolves to ''50px'',
		but you aren't allowed to write the expression
		''sqrt(pow(30px, 2) + pow(40px, 2))'',
		despite the two being equivalent in most mathematical systems.

		There are two reasons for this:
		numeric precision in the exponents,
		and clashing expectations from authors.

		First, numerical precision.
		For a [=CSSNumericValue/type=] to [=CSSNumericValue/match=] a CSS production like <<length>>,
		it needs to have a single unit with its exponent set to exactly 1.
		Theoretically, expressions like ''pow(pow(30px, 3), 1/3)'' should result in exactly that:
		the inner ''pow(30px, 3)'' would resolve to a value of 27000 with a [=CSSNumericValue/type=] of «[ "length" → 3 ]»
		(aka <<length>>³),
		and then the ''pow(X, 1/3)'' would cube-root the value back down to 30 and multiply the exponent by 1/3,
		giving «[ "length" → 1 ]»,
		which [=CSSNumericValue/matches=] <<length>>.

		In the realm of pure mathematics, that's guaranteed to work out;
		in the real-world of computers using binary floating-point arithmetic,
		in some cases the powers might not exactly cancel out,
		leaving you with an invalid [=math function=]
		for confusing, hard-to-track-down reasons.
		(For a JS example,
		evaluate <code>Math.pow(Math.pow(30, 10/3), .1+.1+.1)</code>;
		the result is not exactly 30,
		because <code>.1+.1+.1</code> is not exactly 3/10.
		Instead, <code>(10/3) * (.1 + .1 + .1)</code> is <em>slightly greater</em> than 1.)

		Requiring authors to cast their value down into a number,
		do all the math on the raw number,
		then finally send it back to the desired unit,
		while inconvenient,
		ensures that numerical precision won't bite anyone:
		''calc(pow(pow(30px / 1px, 3), 1/3) * 1px)'' is guaranteed to resolve to a <<length>>,
		with a value that, if not exactly 30, is at least very close to 30,
		even if numerical precision actually prevents the powers from exactly canceling.

		Second, clashing expectations.
		It's not uncommon for authors to expect ''pow(30px, 2)''
		to result in ''900px''
		(such as in <a href="https://github.com/sass/sass/issues/684">this Sass issue</a>);
		that is,
		just squaring the numerical value
		and leaving the unit alone.
		This, however, means the result is dependent on what unit you're expressing the argument in;
		if ''1em'' is ''16px'',
		then ''pow(1em, 2)'' would give ''1em'',
		while ''pow(16px, 2)'' would give ''256px'', or ''16em'',
		which are very different values for what should otherwise be identical input arguments!
		This sort of input dependency is troublesome for CSS,
		which generally allows values to be [=canonical unit|canonicalized=] freely;
		it also makes more complex expressions like ''pow(2em + 10px, 2)'' difficult to interpret.

		Again, requiring authors to cast their value down into a number
		and then back up again into the desired unit
		sidesteps these issues;
		''pow(30, 2)'' is indeed ''900'',
		and the author can interpret that however they wish.

		<hr>

		On the other hand, ''hypot()'' doesn't suffer from these problems.
		Numerical precision in units isn't a concern,
		as the inputs and output all have the same type.
		The result isn't unit-dependent, either,
		due to the nature of the operation;
		''hypot(3em, 4em)'' and ''hypot(48px, 64px)'' both result in the same length
		when ''1em'' equals ''16px'':
		''5em'' or ''80px''.
		Thus it's fine to let author use dimensions directly in ''hypot()''.
	</details>

	The <dfn lt="log()">log(A, B?)</dfn> function
	contains one or two [=calculations=]
	(representing the value to be logarithmed,
	and the base of the logarithm,
	defaulting to e),
	which must resolve to <<number>>s,
	and returns the logarithm base B of the value A,
	as a <<number>>
	with the return type [=made consistent=]
	with the input [=calculation’s=] type.

	The <dfn lt="exp()">exp(A)</dfn> function
	contains one [=calculation=]
	which must resolve to a <<number>>,
	and returns the same value as ''pow(e, A)''
	as a <<number>>
	with the return type [=made consistent=]
	with the input [=calculation’s=] type.

	<div class=example>
		The ''pow()'' function can be useful for strategies like <a href="https://www.modularscale.com/">CSS Modular Scale</a>,
		which relates all the font-sizes on a page to each other by a fixed ratio.

		These sizes can be easily written into custom properties like:

		<pre class=lang-css>
		:root {
			--h6: calc(1rem * pow(1.5, -1));
			--h5: calc(1rem * pow(1.5, 0));
			--h4: calc(1rem * pow(1.5, 1));
			--h3: calc(1rem * pow(1.5, 2));
			--h2: calc(1rem * pow(1.5, 3));
			--h1: calc(1rem * pow(1.5, 4));
		}
		</pre>

		...rather than writing out the values in pre-calculated numbers like ''5.0625rem''
		(what ''calc(1rem * pow(1.5, 4))'' resolves to)
		which have less clear provenance when encountered in a stylesheet.
	</div>

	<div class=example>
		With a single argument,
		''hypot()'' gives the absolute value of its input;
		''hypot(2em)'' and ''hypot(-2em)'' both resolve to ''2em''.

		With more arguments,
		it gives the size of the main diagonal of a box
		whose side lengths are given by the arguments.
		This can be useful for transform-related things,
		giving the distance that an element will actually travel
		when it's translated by a particular X, Y, and Z amount.

		For example, ''hypot(30px, 40px)'' resolves to ''50px'',
		which is indeed the distance between an element's starting and ending positions
		when it's translated by a ''translate(30px, 40px)'' transform.
		If an author wanted elements to get smaller as they moved further away from their starting point
		(drawing some sort of word cloud, for example),
		they could then use this distance in their scaling factor calculations.
	</div>

	<div class=example>
		With a single argument,
		''log()'' provides the “natural log” of its argument,
		or the log base e,
		same as JavaScript.

		If one instead wants log base 10
		(to, for example, count the number of digits in a value)
		or log base 2
		(counting the number of bits in a value),
		''log(X, 10)'' or ''log(X, 2)'' provide those values.
	</div>

<h4 id="exponent-infinities">
Argument Ranges</h4>

	In ''pow(A, B)'',
	if A is negative and finite,
	and B is finite,
	B must be an integer,
	or else the result is NaN.

	If A or B are infinite or 0,
	the following tables give the results:

	<table class=data style="table-layout:fixed">
		<thead>
			<tr><td>
				<th>A is −∞
				<th>A is 0⁻
				<th>A is 0⁺
				<th>A is +∞
		</thead>
		<tr>
			<th>B is −finite
			<td>0⁻ if B is an odd integer, 0⁺ otherwise
			<td>−∞ if B is an odd integer, +∞ otherwise
			<td>+∞
			<td>0⁺
		<tr>
			<th>B is 0
			<td colspan=4>always 1
		<tr>
			<th>B is +finite
			<td>−∞ if B is an odd integer, +∞ otherwise
			<td>0⁻ if B is an odd integer, 0⁺ otherwise
			<td>0⁺
			<td>+∞
	</table>

	<table class=data>
		<thead>
			<tr><td>
				<th>A is < -1
				<th>A is -1
				<th>-1 < A < 1
				<th>A is 1
				<th>A is > 1
		</thead>
		<tr>
			<th>B is +∞
			<td>result is +∞
			<td>result is NaN
			<td>result is 0⁺
			<td>result is NaN
			<td>result is +∞
		<tr>
			<th>B is −∞
			<td>result is 0⁺
			<td>result is NaN
			<td>result is +∞
			<td>result is NaN
			<td>result is 0⁺
	</table>

	In ''sqrt(A)'',
	if A is +∞,
	the result is +∞.
	If A is 0⁻,
	the result is 0⁻.
	If A is less than 0,
	the result is NaN.

	In ''hypot(A, …)'',
	if any of the inputs are infinite,
	the result is +∞.

	In ''log(A, B)'',
	if B is 1 or negative,
	<span class='note'>
	B values <em>between</em> 0 and 1,
	or greater than 1,
	are valid.
	</span>
	the result is NaN.
	If A is negative,
	the result is NaN.
	If A is 0⁺ or 0⁻,
	the result is −∞.
	If A is 1,
	the result is 0⁺.
	If A is +∞,
	the result is +∞.

	In ''exp(A)'',
	if A is +∞,
	the result is +∞.
	If A is −∞,
	the result is 0⁺.

	(See [[#calc-type-checking]] for details on how [=math functions=] handle NaN and infinities.)

	<div class=note>
		All of these behaviors are intended to match the "standard" definitions of these functions
		as implemented by most programming languages,
		in particular as implemented in JS.

		The only divergences from the behavior of the equivalent JS functions
		are that NaN is "infectious" in <em>every</em> function,
		forcing the function to return NaN if any argument calculation is NaN.

		<details highlight=js>
			<summary>Details of the JS Behavior</summary>

			There are two cases in JS where a NaN is not "infectious"
			to the math function it finds itself in:

			* <code>Math.hypot(Infinity, NaN)</code> will return <code>Infinity</code>.
			* <code>Math.pow(NaN, 0)</code> will return <code>1</code>.

			The logic appears to be that,
			if you replace the NaN with <em>any</em> Number,
			the return value will be the same.
			However, this logic is not applied consistently to the <code>Math</code> functions:
			<code>Math.max(Infinity, NaN)</code> returns <code>NaN</code>, not <code>Infinity</code>;
			the same is true of <code>Math.min(-Infinity, NaN)</code>.

			Because this is an error corner case,
			JS isn't consistent on the matter,
			and NaN recognition/handling of [=calculations=]
			is likely done at a higher CSS level
			rather than in the internal math functions anyway,
			consistency in CSS was chosen to be more important,
			so all functions were defined to have "infectious" NaN.
		</details>
	</div>

<!--  Big Text: abs()

 ███▌  ████▌   ███▌    ██ ██
▐█ ▐█  █▌  █▌ █▌  █▌  █▌   ▐█
█▌  █▌ █▌  █▌ █▌     █▌     ▐█
█▌  █▌ █████   ███▌  █▌     ▐█
█████▌ █▌  █▌     █▌ █▌     ▐█
█▌  █▌ █▌  █▌ █▌  █▌  █▌   ▐█
█▌  █▌ ████▌   ███▌    ██ ██
-->

<h3 id='sign-funcs'>
Sign-Related Functions: ''abs()'', ''sign()''</h3>

	The sign-related functions--
	''abs()'' and ''sign()''--
	compute various functions related to the sign of their argument.

	The <dfn lt="abs()">abs(A)</dfn> function
	contains one [=calculation=] A,
	and returns the absolute value of A,
	as the same [=CSSNumericValue/type=] as the input:
	if A's numeric value is positive or 0⁺, just A again;
	otherwise ''-1 * A''.

	The <dfn lt="sign()">sign(A)</dfn> function
	contains one [=calculation=] A,
	and returns -1 if A's numeric value is negative,
	+1 if A's numeric value is positive,
	0⁺ if A's numeric value is 0⁺,
	and 0⁻ if A's numeric value is 0⁻.
	The return type is a <<number>>,
	[=made consistent=]
	with the input [=calculation’s=] type.

	Note: Both of these functions operate on the fully simplified/resolved form of their arguments,
	which may give unintuitive results at first glance.
	In particular,
	an expression like ''10%'' might be positive <em>or</em> negative once it's resolved,
	depending on what value it's resolved against.
	For example, in 'background-position' positive percentages
	resolve to a negative length,
	and vice versa,
	if the background image is larger than the background area.
	Thus ''sign(10%)'' might return ''1'' <em>or</em> ''-1'',
	depending on how the percentage is resolved!
	(Or even ''0'', if it's resolved against a zero length.)

<!-- Big Text: keywords

█▌  █▌ █████▌ █   ▐▌ █▌    █▌  ███▌  ████▌  ████▌   ███▌
█▌ █▌  █▌     ▐▌  █  █▌    █▌ █▌  █▌ █▌  █▌ █▌  █▌ █▌  █▌
█▌█▌   █▌      █ ▐▌  █▌    █▌ █▌  █▌ █▌  █▌ █▌  █▌ █▌
██     ████    ▐▌█   █▌    █▌ █▌  █▌ ████▌  █▌  █▌  ███▌
█▌█▌   █▌       █▌   █▌ ▐  █▌ █▌  █▌ █▌▐█   █▌  █▌     █▌
█▌ █▌  █▌       █▌   █▌ █▌ █▌ █▌  █▌ █▌ ▐█  █▌  █▌ █▌  █▌
█▌  █▌ █████▌   █▌    ██ ▐█▌   ███▌  █▌  █▌ ████▌   ███▌
-->

<h3 id='calc-keywords'>
Numeric Keywords</h3>

	Keywords in [=calculations=]
	provide access to values that are difficult or impossible to represent as literals.
	Each keyword defines its value,
	its [=determine the type of a calculation|type=],
	and when it can be resolved.

<h4 id='calc-constants'>
Numeric Constants: ''e'', ''pi''</h4>

	While the trigonometric and exponential functions
	handle many complex numeric operations,
	some reasonable calculations must be put together more manually,
	and many times these include well-known constants,
	such as <i>e</i> and <i>π</i>.

	Rather than require authors to manually type out
	several digits of these constants,
	a few of them are provided directly:

	<dl dfn-type=value dfn-for=calc()>
		: <dfn>e</dfn>
		:: the base of the natural logarithm,
			approximately equal to 2.7182818284590452354.

		: <dfn>pi</dfn>
		:: the ratio of a circle's circumference to its diameter,
			approximately equal to 3.1415926535897932.
	</dl>

	Both of these keywords are <<number>>s,
	and resolve at parse time.

	Note: These keywords are only usable within a calculation,
	such as ''calc(pow(e, pi) - pi)'', or ''min(pi, 5, e)''.
	If used outside of a calculation,
	they're treated like any other keyword:
	''animation-name: pi;'' refers to an animation named "pi";
	''line-height: e;'' is invalid
	(<em>not</em> similar to ''line-height: 2.7'',
	but ''line-height: calc(e);'' is).


<h4 id='calc-error-constants'>
Degenerate Numeric Constants: ''infinity'', <nobr>''-infinity''</nobr>, ''NaN''</h4>

	When a [=calculation=] or a subtree of a [=calculation=]
	becomes [=infinite=] or [=NaN=],
	representing it with a numeric value is no longer possible.
	A UA may have an
	<dfn export>implementation-defined limit for values approaching infinity</dfn>.

	To aid in serialization of these degenerate values,
	the following additional math constants are defined:

	<dl dfn-type=value dfn-for=calc()>
		: <dfn>infinity</dfn>
		:: the value positive infinity (+∞)

		: <dfn>-infinity</dfn>
		:: the value negative infinity (−∞)

		: <dfn>NaN</dfn>
		:: the value NaN
	</dl>

	All of these keywords are <<number>>s,
	and resolve at parse time.

	As usual for CSS keywords,
	these are [=ASCII case-insensitive=].
	<span class=note>
	Thus, ''calc(InFiNiTy)'' is perfectly valid.
	</span>
	However, ''NaN'' must be serialized with this canonical casing.

	Note: As these keywords are <<number>>s,
	to get an infinite length,
	for example,
	requires an expression like ''calc(infinity * 1px)''.

	Note: These constants are defined <em>mostly</em>
	to make serialization of infinite/NaN values simpler and more obvious,
	but <em>can</em> be used to indicate a "largest possible value",
	since an infinite value gets clamped to the allowed range.
	It's rare for this to be reasonable,
	but when it is,
	using ''infinity'' is clearer in its intent
	than just putting an enormous number in one's stylesheet.

<h4 id='calc-variables'>
Numeric Variables</h4>

	Other specifications can define additional keywords
	which are usable in [=calculations=]
	in certain contexts.
	For example, [=relative color=] syntax
	defines a number of color-channel keywords
	representing the value of each color channel as a <<number>>.

	Each specifications defining such keywords
	must define for each keyword:

	* its value
	* its [=determine the type of a calculation|type=] (<<number>>, <<length>>, etc)
	* when it resolves (parse time, computed-value time, or used-value time)

<!-- Big Text: syntax

 ███▌  █   ▐▌ █    █▌ █████▌  ███▌  █     █
█▌  █▌ ▐▌  █  █▌   █▌   █▌   ▐█ ▐█   █   █
█▌      █ ▐▌  ██▌  █▌   █▌   █▌  █▌   █ █
 ███▌   ▐▌█   █▌▐█ █▌   █▌   █▌  █▌    █
    █▌   █▌   █▌  ██▌   █▌   █████▌   █ █
█▌  █▌   █▌   █▌   █▌   █▌   █▌  █▌  █   █
 ███▌    █▌   █▌   ▐▌   █▌   █▌  █▌ █     █
-->

<h3 id='calc-syntax'>
Syntax</h3>

	The syntax of a [=math function=] is:

	<pre class='prod'>
	<<calc()>>  = calc( <<calc-sum>> )
	<<min()>>   = min( <<calc-sum>># )
	<<max()>>   = max( <<calc-sum>># )
	<<clamp()>> = clamp( [ <<calc-sum>> | none ], <<calc-sum>>, [ <<calc-sum>> | none ] )
	<<round()>> = round( <<rounding-strategy>>?, <<calc-sum>>, <<calc-sum>>? )
	<<mod()>>   = mod( <<calc-sum>>, <<calc-sum>> )
	<<rem()>>   = rem( <<calc-sum>>, <<calc-sum>> )
	<<sin()>>   = sin( <<calc-sum>> )
	<<cos()>>   = cos( <<calc-sum>> )
	<<tan()>>   = tan( <<calc-sum>> )
	<<asin()>>  = asin( <<calc-sum>> )
	<<acos()>>  = acos( <<calc-sum>> )
	<<atan()>>  = atan( <<calc-sum>> )
	<<atan2()>> = atan2( <<calc-sum>>, <<calc-sum>> )
	<<pow()>>   = pow( <<calc-sum>>, <<calc-sum>> )
	<<sqrt()>>  = sqrt( <<calc-sum>> )
	<<hypot()>> = hypot( <<calc-sum>># )
	<<log()>>   = log( <<calc-sum>>, <<calc-sum>>? )
	<<exp()>>   = exp( <<calc-sum>> )
	<<abs()>>   = abs( <<calc-sum>> )
	<<sign()>>  = sign( <<calc-sum>> )
	<dfn>&lt;calc-sum></dfn> = <<calc-product>> [ [ '+' | '-' ] <<calc-product>> ]*
	<dfn>&lt;calc-product></dfn> = <<calc-value>> [ [ '*' | / ] <<calc-value>> ]*
	<dfn>&lt;calc-value></dfn> = <<number>> | <<dimension>> | <<percentage>> |
	               <<calc-keyword>> | ( <<calc-sum>> )
	<dfn>&lt;calc-keyword></dfn> = e | pi | infinity | -infinity | NaN
	<<rounding-strategy>> = nearest | up | down | to-zero | line-width
	</pre>

	In some contexts, additional <<calc-keyword>> values
	can be defined to be valid.
	(For example, in [=relative color=] syntax,
	appropriate channel keywords are allowed.)

	In addition, [=whitespace=]
	is required on both sides of the <css>+</css> and <css>-</css> operators.
	(The <css>*</css> and <css>/</css> operators can be used without white space around them.)

	Several of the math functions above have additional constraints
	on what their <<calc-sum>> arguments can contain.
	Check the definitions of the individual functions for details.

	UAs must support [=calculations=] of at least 32 <<calc-value>> terms
	and at least 32 levels of nesting (parentheses and/or functions).
	For functions that support an arbitrary number of arguments (such as ''min()''),
	it must also support at least 32 arguments.
	If a [=calculation=] contains more than the supported number of terms, arguments, or nesting
	it must be treated as if it were invalid.

<!-- Big Text: types

█████▌ █   ▐▌ ████▌  █████▌  ███▌
  █▌   ▐▌  █  █▌  █▌ █▌     █▌  █▌
  █▌    █ ▐▌  █▌  █▌ █▌     █▌
  █▌    ▐▌█   ████▌  ████    ███▌
  █▌     █▌   █▌     █▌         █▌
  █▌     █▌   █▌     █▌     █▌  █▌
  █▌     █▌   █▌     █████▌  ███▌
-->

<h3 id='calc-type-checking'>
Type Checking</h3>

	A [=math function=] can be many possible types,
	such as <<length>>, <<number>>, etc.,
	depending on the [=calculations=] it contains,
	as defined below.
	It can be used anywhere a value of that type is allowed.

	<div class=example>
		For example, the 'width' property accepts <<length>> values,
		so a [=math function=] that resolves to a <<length>>,
		such as ''calc(5px + 1em)'',
		can be used in 'width'.
	</div>

	Additionally, [=math functions=] that resolve to <<number>>
	can be used in any place that only accepts <<integer>>;
	the value is [=rounded to the nearest integer=] as it resolves.

	Operators form sub-expressions, which gain types based on their arguments.

	Note: In previous versions of this specification,
	multiplication and division were limited in what arguments they could take,
	to avoid producing more complex intermediate results
	(such as ''1px * 1em'', which is <<length>>²)
	and to make division-by-zero detectable at parse time.
	This version now relaxes those restrictions.

	<div algorithm>
		To <dfn>determine the type of a [=calculation=]</dfn>:

		* At a <css>+</css> or <css>-</css> sub-expression,
			attempt to [=add two types|add the types=] of the left and right arguments.
			If this returns failure,
			the entire [=calculation’s=] type is failure.
			Otherwise, the sub-expression's [=CSSNumericValue/type=] is the returned type.

		* At a <css>*</css> sub-expression,
			[=multiply two types|multiply the types=] of the left and right arguments.
			The sub-expression's [=CSSNumericValue/type=] is the returned result.

		* At a <css>/</css> sub-expression,
			let |left type| be the result of finding the [=CSSNumericValue/types=] of its left argument,
			and |right type| be the result of finding the [=CSSNumericValue/types=] of its right argument
			and then [=invert a type|inverting=] it.

			The sub-expression's [=CSSNumericValue/type=] is the result of
			[=multiply two types|multiplying=] the |left type| and |right type|.

		* Anything else is a terminal value,
			whose [=CSSNumericValue/type=] is determined based on its CSS type.
			(Unless otherwise specified,
			the type's associated [=percent hint=] is null.)

			<dl class=switch>
				: <<number>>
				: <<integer>>
				:: the [=CSSNumericValue/type=] is «[ ]» (empty map)
				: <<length>>
				:: the [=CSSNumericValue/type=] is «[ "length" → 1 ]»
				: <<angle>>
				:: the [=CSSNumericValue/type=] is «[ "angle" → 1 ]»
				: <<time>>
				:: the [=CSSNumericValue/type=] is «[ "time" → 1 ]»
				: <<frequency>>
				:: the [=CSSNumericValue/type=] is «[ "frequency" → 1 ]»
				: <<resolution>>
				:: the [=CSSNumericValue/type=] is «[ "resolution" → 1 ]»
				: <<flex>>
				:: the [=CSSNumericValue/type=] is «[ "flex" → 1 ]»
				: <<calc-keyword>>
				:: the [=CSSNumericValue/type=] is as defined by the keyword
				: <<percentage>>
				::
					If, in the context in which the [=math function=]
					containing this [=calculation=] is placed,
					<<percentage>>s are resolved relative to another type of value
					(such as in 'width', where <<percentage>> is resolved against a <<length>>),
					and that other type is <em>not</em> <<number>>,
					the [=CSSNumericValue/type=] is determined as the other type,
					but with a [=percent hint=] set to that other type.

					Otherwise,
					the [=CSSNumericValue/type=] is «[ "percent" → 1 ]»,
					with a [=percent hint=] of "percent".
				: anything else
				:: The [=calculation’s=] type is failure.
			</dl>
	</div>

	<div algorithm>
		A value <dfn export for=CSS lt="contain a percentage|percentage-containing">contains a percentage</dfn>
		if its [=CSSNumericValue/type=] is «[ "percent" → 1 ]»,
		or its type's [=percent hint=] is non-null.
	</div>

	<div algorithm>
		Two or more calculations have a <dfn export for=CSS local-lt="consistent">consistent type</dfn>
		if [=add two types|adding the types=] doesn't result in failure.
		The [=consistent type=] is the result of the type addition.
	</div>

	<div algorithm>
		To <dfn export for=CSS lt="make a type consistent|make consistent|made consistent">make a type |base| consistent</dfn>
		with another type |input|:

		1. If both |base| and |input| have different non-null [=percent hints=],
			they can't be made consistent.
			Return failure.

		2. If |base| has a null [=percent hint=]
			set |base|’s [=percent hint=]
			to |input|’s [=percent hint=].

		3. Return |base|.
	</div>

	[=Math functions=] themselves have [=CSSNumericValue/types=],
	according to their contained [=calculations=]:

	: ''calc()''
	: ''abs()''
	:: The [=CSSNumericValue/type=] of its contained [=calculation=].

	: ''min()''
	: ''max()''
	: ''clamp()''
	: ''hypot()''
	: ''round()''
	: ''mod()''
	: ''rem()''
	:: The result of [=add two types|adding the types=]
		of its comma-separated [=calculations=].

	: ''asin()''
	: ''acos()''
	: ''atan()''
	: ''atan2()''
	:: «[ "angle" → 1 ]».

	: ''sign()''
	: ''sin()''
	: ''cos()''
	: ''tan()''
	: ''pow()''
	: ''sqrt()''
	: ''log()''
	: ''exp()''
	:: «[ ]» (empty map).

	For each of the above,
	if the [=CSSNumericValue/type=] is failure,
	the [=math function=] is invalid.

	A [=math function=] resolves to <<number>>, <<length>>, <<angle>>, <<time>>, <<frequency>>, <<resolution>>, <<flex>>, or <<percentage>>
	according to which of those productions its [=CSSNumericValue/type=] [=CSSNumericValue/matches=].
	(These categories are mutually exclusive.)
	If it can't [=CSSNumericValue/match=] any of these,
	the [=math function=] is invalid.

	Note: Algebraic simplifications do not affect the validity of a [=math function=] or its resolved type.
	For example, ''calc(5px - 5px + 10s)'' and ''calc(0 * 5px + 10s)'' are both invalid
	due to the attempt to add a length and a time.

	Note: Note that <<percentage>>s relative to <<number>>s,
	such as in 'opacity',
	are not <em>combinable</em> with those numbers--
	''opacity: calc(.25 + 25%)'' is invalid.
	Allowing this causes significant problems with "unit algebra"
	(allowing multiplication/division of <<dimension>>s),
	and in every case so far,
	doesn't provide any new functionality.
	(For example, ''opacity: 25%'' is identical to ''opacity: .25'';
	it's just a trivial syntax transform.)
	You can still perform other operations with them,
	such as ''opacity: calc(100% / 3);'',
	which is valid.

	Note: Because <<number-token>>s are always interpreted as <<number>>s or <<integer>>s,
	"unitless 0" <<length>>s aren't supported in [=math functions=].
	That is, ''width: calc(0 + 5px);'' is invalid,
	because it's trying to add a <<number>> to a <<length>>,
	even though both ''width: 0;''
	and ''width: 5px;''
	are valid.

	Note: Although there are a few properties in which a bare <<number>>
	becomes a <<length>> at used-value time
	(specifically, 'line-height' and 'tab-size'),
	<<number>>s never become "length-like" in ''calc()''.
	They always stay as <<number>>s.

	Note: In Quirks Mode [[QUIRKS]],
	some properties that would normally only accept <<length>>s
	are defined to also accept <<number>>s,
	interpreting them as ''px'' lengths.
	Like unitless zeroes,
	this has no effect on the parsing or behavior of [=math functions=],
	though a [=math function=] that resolves to a <<number>> value
	might become valid in Quirks Mode
	(and have its result interpreted as a ''px'' length).

<h4 id='calc-context'>
Calculation Contexts</h4>

	Numeric values can be interpreted in various <dfn export>calculation contexts</dfn>,
	depending on where they are used,
	which defines how <<percentage>> values resolve,
	etc.

	<p class=example>
		For example, in 'top', a <<percentage>> value
		is resolved against the size of the containing block,
		making it act as a <<length>>.
		A single property can define multiple [=calculation contexts=];
		for example, in 'background-size'
		one value resolves <<percentage>>s against the width of the [=background positioning area=]
		while the other resolves them against the height.

	[=Math functions=] always inherit the [=calculation context=] from wherever they're used.
	That is, in ''top: calc(25% + 50px)'',
	the <<percentage>> is resolved <em>as normal</em> for 'top',
	as if ''top: 25%'' were specified
	(and then has ''50px'' added to its value).

	Unless otherwise defined,
	all other functions <strong>do not inherit a [=calculation context=]</strong>,
	and instead define their own [=calculation contexts=]
	for their numeric arguments.
	For example, in ''top: anchor(25%)'',
	the <<percentage>> in the ''anchor()'' function
	is instead defined to resolve in a completely different manner
	(against the height of the default anchor element).

<h4 id='calc-ieee'>
Infinities, NaN, and Signed Zero</h4>

	[=Math functions=] follow IEEE-754 semantics,
	which means they recognize the concepts of
	positive and negative zero,
	positive and negative infinity,
	and NaN (not a number).

	However, these concepts are only retained within a [=calculation tree=];
	if a <dfn export>top-level calculation</dfn>
	(a [=math function=] not nested directly inside of another [=math function=])
	would result in one of these special values,
	they're instead "censored" into a standard representable value,
	as defined below.

	<dfn lt="signed zero|positive zero|negative zero" for=CSS export>Signed zeros</dfn>
	(indicated here as 0⁺ or 0⁻)
	can not be written directly in CSS;
	''0'', ''+0'' and ''-0'' all produce the standard "unsigned" zero,
	which is considered positive (0⁺)
	for the purposes of these rules.

	[=Signed zeroes=] are produced in the following ways:

	* Negative zero
		(0⁻)
		can be produced by a multiplication or division that produces zero
		with exactly one negative argument
		(such as ''-5 * 0'' or ''1 / -infinity'').
	* ''0⁻ + 0⁻''
		or ''0⁻ - 0⁺''
		produces 0⁻.
		All other additions or subtractions that would produce a zero
		produce 0⁺.
	* Multiplying or dividing 0⁻ with a positive number
		(including 0⁺)
		produces a negative result
		(either 0⁻ or −∞),
		while multiplying or dividing 0⁻ with a negative number
		produces a positive result.

		(In other words,
		multiplying or dividing with 0⁻
		follows standard sign rules.)
	* When comparing 0⁺ and 0⁻,
		0⁻ is less than 0⁺.
		For example, ''min(0⁺, 0⁻)'' must produce 0⁻,
		''max(0⁺, 0⁻)'' must produce 0⁺,
		and ''clamp(0⁺, 0⁻, 1)'' must produce 0⁺.
	* Certain argument combinations in [=math functions=]
		are defined to produce 0⁻
		(for example, ''round(-1, infinity)'').
		All other operations that produce a zero
		produce positive zero (0⁺).

	[=Signed zeroes=] do not escape a [=top-level calculation=];
	they're censored into the "unsigned" zero.

	<dfn lt="infinity|infinite|positive infinity|negative infinity" for=CSS export>Infinities</dfn>
	(indicated here as +∞ or −∞)
	can be written directly
	using the [[#calc-error-constants|math constants]]
	''infinity'' and ''-infinity'',
	or produced as a result of some calculations:

	* Dividing a value by zero produces either +∞ or −∞,
		according to the standard sign rules.
	* Adding or subtracting ±∞ to anything produces the appropriate infinity.
	* Multiplying any value by ±∞ produces the appropriate infinity.
	* Dividing any value by ±∞ produces zero.
	* Certain argument combinations in [=math functions=]
		are defined to produce [=infinities=]
		(for example, ''pow(0, -1)'' produces +∞).

	Note: The rules for producing [=NaN=], below,
	supersede the above rules for producing [=infinities=].

	[=Infinities=] do not escape a [=top-level calculation=];
	they're clamped to the minimum or maximum value allowed in the context,
	as defined in [[#calc-range]].

	<dfn for=CSS export>NaN</dfn>
	(short for "not a number")
	is the result of certain operations
	that don't have a well-defined value.
	It can be written directly
	using the [[#calc-error-constants|math constants]]
	''NaN'',
	or produced as a result of some calculations:

	* Dividing zero by zero,
		dividing ±∞ by ±∞,
		multiplying 0 by ±∞,
		adding +∞ to −∞,
		or subtracting two infinities of the same sign
		produces NaN.

		These rules override any other result,
		if there's a conflict.
		For example, ''0 / 0'' is NaN, not +∞.
	* Certain argument combinations in [=math functions=]
		are defined to produce [=NaN=]
		(for example, ''asin(2)'' produces NaN).
	* Any operation with at least one NaN argument produces NaN.

	[=NaN=] does not escape a [=top-level calculation=];
	it's censored into a zero value

	<div class=example>
		For example, ''calc(-5 * 0)'' produces an unsigned zero--
		the calculation resolves to 0⁻,
		but as it's a [=top-level calculation=],
		it's then censored to an unsigned zero.

		On the other hand, ''calc(1 / calc(-5 * 0))'' produces −∞,
		same as ''calc(1 / (-5 * 0))''--
		the inner calc resolves to 0⁻,
		and as it's not a [=top-level calculation=],
		it passes it up unchanged to the outer calc to produce −∞.
		If it was censored into an unsigned zero,
		it would instead produce +∞.
	</div>

<!--  Big Text: internal

████ █    █▌ █████▌ █████▌ ████▌  █    █▌  ███▌  █▌
 ▐▌  █▌   █▌   █▌   █▌     █▌  █▌ █▌   █▌ ▐█ ▐█  █▌
 ▐▌  ██▌  █▌   █▌   █▌     █▌  █▌ ██▌  █▌ █▌  █▌ █▌
 ▐▌  █▌▐█ █▌   █▌   ████   ████▌  █▌▐█ █▌ █▌  █▌ █▌
 ▐▌  █▌  ██▌   █▌   █▌     █▌▐█   █▌  ██▌ █████▌ █▌
 ▐▌  █▌   █▌   █▌   █▌     █▌ ▐█  █▌   █▌ █▌  █▌ █▌
████ █▌   ▐▌   █▌   █████▌ █▌  █▌ █▌   ▐▌ █▌  █▌ █████
-->

<h3 id='calc-internal'>
Internal Representation</h3>

	The [=internal representation=] of a [=math function=]
	is a <dfn export>calculation tree</dfn>:
	a tree where the branch nodes are <dfn export for="calculation tree">operator nodes</dfn>
	corresponding either to [=math functions=]
	(such as Min, Cos, Sqrt, etc)
	or to operators in a [=calculation=]
	(Sum, Product, Negate, and Invert, the <dfn for="calculation tree">calc-operator nodes</dfn>),
	and the leaf nodes
	are either numeric values
	(such as numbers, dimensions, and percentages)
	or non-[=math functions=] that resolve to a numeric type.

	[=Math functions=] are turned into [=calculation trees=]
	depending on the function:

	<dl class=switch>
		: calc()
		:: The [=internal representation=] of a ''calc()'' function
			is the result of [=parsing a calculation=] from its argument.
		: any other [=math function=]
		:: The [=internal representation=]
			is an [=operator node=] with the same name as the function,
			whose children are the result of [=parsing a calculation=]
			from each of the function's arguments,
			in the order they appear.
	</dl>

	<div algorithm>
		To <dfn export lt="parse a calculation|parsing a calculation">parse a calculation</dfn>,
		given a [=calculation=] |values|
		represented as a list of [=component values=],
		and returning a [=calculation tree=]:

		1. Discard any <<whitespace-token>>s from |values|.

		2. An item in |values| is an “operator”
			if it's a <<delim-token>> with the value "+", "-", "*", or "/".
			Otherwise, it's a “value”.

		3. Collect children into Product and Invert nodes.

			For every consecutive run of value items in |values|
			separated by "*" or "/" operators:

			1. For each "/" operator in the run,
				replace its right-hand value item |rhs|
				with an Invert node containing |rhs| as its child.

			2. Replace the entire run with a Product node
				containing the value items of the run as its children.

		4. Collect children into Sum and Negate nodes.

			1. For each "-" operator item in |values|,
				replace its right-hand value item |rhs|
				with a Negate node containing |rhs| as its child.

			2. If |values| has only one item,
				and it is a Product node
				or a parenthesized [=simple block=],
				replace |values| with that item.

				Otherwise,
				replace |values| with a Sum node
				containing the value items of |values| as its children.


		5. At this point |values| is
			a tree of Sum, Product, Negate, and Invert nodes,
			with other types of values at the leaf nodes.
			Process the leaf nodes.

			For every leaf node |leaf| in |values|:

			1. If |leaf| is a parenthesized [=simple block=],
				replace |leaf|
				with the result of [=parsing a calculation=] from |leaf|’s contents.

			2. If |leaf| is a [=math function=],
				replace |leaf| with the [=internal representation=] of that math function.

		6. Return the result of [=simplifying a calculation tree=] from |values|.
	</div>


<!-- Big Text: simpl

 ███▌  ████ █     █ ████▌  █▌
█▌  █▌  ▐▌  ██   ██ █▌  █▌ █▌
█▌      ▐▌  █▌█ █▐█ █▌  █▌ █▌
 ███▌   ▐▌  █▌ █ ▐█ ████▌  █▌
    █▌  ▐▌  █▌   ▐█ █▌     █▌
█▌  █▌  ▐▌  █▌   ▐█ █▌     █▌
 ███▌  ████ █▌   ▐█ █▌     █████
-->

<h4 id='calc-simplification'>
Simplification</h4>

	[=Internal representations=] of [=math functions=] are eagerly simplified to the extent possible,
	using standard algebraic simplifications
	(distributing multiplication over sums,
	combining similar units,
	etc.).

	When used in non-property contexts
	(such as in ''@font-face'' descriptors, for example),
	[=math functions=] are simplified
	as if they were [=specified values=].

	<div algorithm>
		To <dfn export local-lt="simplify" lt="simplify a calculation tree|simplifying a calculation tree">simplify a calculation tree</dfn> |root|:

		1. If |root| is a numeric value:
			1. If |root| is a percentage that will be resolved against another value,
				and there is enough information available to resolve it,
				do so,
				and express the resulting numeric value
				in the appropriate [=canonical unit=].
				Return the value.

			2. If |root| is a dimension
				that is not expressed in its [=canonical unit=],
				and there is enough information available to convert it to the [=canonical unit=],
				do so,
				and return the value.

			3. If |root| is a <<calc-keyword>> that can be resolved,
				return what it resolves to,
				[=simplified=].

			4. Otherwise, return |root|.

		2. If |root| is any other leaf node
			(not an operator node):

			1. If there is enough information available to determine its numeric value,
				return its value,
				expressed in the value's [=canonical unit=].
			2. Otherwise, return |root|.

		3. At this point, |root| is an [=operator node=].
			[=Simplify=] all the [=calculation=] children of |root|.

		4. If |root| is an [=operator node=]
			that's not one of the [=calc-operator nodes=],
			and all of its [=calculation=] children are numeric values
			with enough information to compute the operation |root| represents,
			return the result of running |root|'s operation
			using its children,
			expressed in the result's [=canonical unit=].

			<div class=note>

				If a percentage is left at this point,
				it will <em>usually</em> block simplification of the node,
				since it needs to be resolved against another value
				using information not currently available.
				(Otherwise, it would have been converted to a different value in an earlier step.)
				This includes operations such as "min",
				since percentages might resolve against a negative basis,
				and thus end up with an opposite comparative relationship
				than the raw percentage value would seem to indicate.

				However, "raw" percentages--
				ones which do not resolve against another value,
				such as in 'opacity'--
				might not block simplification.
			</div>


		5. If |root| is a Min or Max node,
			attempt to <em>partially</em> simplify it:

			1. [=list/For each=] node |child| of |root|’s children:

				If |child| is a numeric value
				with enough information to compare magnitudes with another child of the same unit
				(see note in previous step),
				and there are other children of |root|
				that are numeric values with the same unit,
				combine all such children
				with the appropriate operator per |root|,
				and replace |child| with the result,
				removing all other child nodes involved.

			2. If |root| has only one child,
				return the child.

				Otherwise, return |root|.

		6. If |root| is a Negate node:

			1. If |root|'s child is a numeric value,
				return an equivalent numeric value,
				but with the value negated
				(0 - value).
			2. If |root|'s child is a Negate node,
				return the child's child.
			3. If |root|'s child is a Sum node:

				1. Let |negated grandchildren| be an empty list

				2. For each |grandchild| of the child's children:

					1. If |grandchild| is a numeric value,
						create an equivalent numeric value,
						but with the value negated
						(0 - value),
						and append the result to |negated grandchildren|.

					2. If |grandchild| is a Negate node
						append |grandchild|'s child to |negated grandchildren|

					3. Otherwise,
						create a Negate node with |grandchild| as its child,
						and append the result to |negated grandchildren|

				3. Return a Sum node with |negated grandchildren| as its children

			4. Return |root|.

		7. If |root| is an Invert node:

			1. If |root|'s child is a number
				(not a percentage or dimension)
				return the reciprocal of the child's value.
			2. If |root|'s child is an Invert node,
				return the child's child.
			3. Return |root|.

		8. If |root| is a Sum node:

			1. For each of |root|'s children
				that are Sum nodes,
				replace them with their children.

			2. For each set of |root|'s children
				that are numeric values with identical units,
				remove those children
				and replace them with a single numeric value
				containing the sum of the removed nodes,
				and with the same unit.

				(E.g. combine numbers, combine percentages,
				combine px values, etc.)

			3. If |root| has only a single child at this point,
				return the child.
				Otherwise, return |root|.

			Note: Zero-valued terms cannot be simply removed from a Sum;
			they can only be combined with other values that have identical units.
			(This is because the mere presence of a unit, even with a zero value,
			can sometimes imply a change in behavior.)

		9. If |root| is a Product node:

			1. For each of |root|'s children
				that are Product nodes,
				replace them with their children.

			2. If |root| has multiple children that are numbers
				(not percentages or dimensions),
				remove them and replace them with a single number
				containing the product of the removed nodes.

			3. If |root| contains only two children,
				one of which is a number
				(not a percentage or dimension)
				and the other of which is a Sum
				whose children are all numeric values,
				multiply all of the Sum's children by the number,
				then return the Sum.

			4. If |root| contains only numeric values
				and/or Invert nodes containing numeric values,
				and [=multiply two types|multiplying the types=]
				of all the children
				(noting that the type of an Invert node
				is the [=invert a type|inverse=] of its child's type)
				results in a type that [=CSSNumericValue/matches=]
				any of the types that a [=math function=] can resolve to,
				return the result of multiplying all the values of the children
				(noting that the value of an Invert node
				is the reciprocal of its child's value),
				expressed in the result's [=canonical unit=].

			5. Return |root|.

		10. Return |root|.

	</div>


<!-- Big Text: computed

 ███▌   ███▌  █     █ ████▌  █▌  █▌ █████▌ █████▌ ████▌
█▌  █▌ █▌  █▌ ██   ██ █▌  █▌ █▌  █▌   █▌   █▌     █▌  █▌
█▌     █▌  █▌ █▌█ █▐█ █▌  █▌ █▌  █▌   █▌   █▌     █▌  █▌
█▌     █▌  █▌ █▌ █ ▐█ ████▌  █▌  █▌   █▌   ████   █▌  █▌
█▌     █▌  █▌ █▌   ▐█ █▌     █▌  █▌   █▌   █▌     █▌  █▌
█▌  █▌ █▌  █▌ █▌   ▐█ █▌     █▌  █▌   █▌   █▌     █▌  █▌
 ███▌   ███▌  █▌   ▐█ █▌      ███▌    █▌   █████▌ ████▌
-->

<h3 id='calc-computed-value'>
Computed Value</h3>

	The [=computed value=] of a [=math function=]
	is its [=calculation tree=] [=simplified=],
	using all the information available at [=computed value=] time.
	(Such as the ''em'' to ''px'' ratio,
	how to resolve percentages in some properties,
	etc.)

	Where percentages are not resolved at computed-value time,
	they are not resolved in [=math functions=],
	e.g. ''calc(100% - 100% + 1px)'' resolves to ''calc(0% + 1px)'',
	not to ''1px''.
	If there are special rules for computing percentages in a value
	(e.g. <a href="https://www.w3.org/TR/CSS2/visudet.html#the-height-property">the <css>height</css> property</a>),
	they apply whenever a [=math function=] contains percentages.

	The [=calculation tree=] is again simplified at [=used value=] time;
	with [=used value=] time information,
	a [=math function=] always simplifies down to a single numeric value.

	<div class='example'>
		For example,
		whereas 'font-size' computes percentage values at <a>computed value</a> time
		so that <a>font-relative length</a> units can be computed,
		'background-position' has layout-dependent behavior for percentage values,
		and thus does not resolve percentages until used-value time.

		Due to this, 'background-position' computation preserves the percentage in a ''calc()''
		whereas 'font-size' will compute such expressions directly into a length.
	</div>

	Given the complexities of width and height calculations on table cells and table elements,
	math expressions mixing both percentages and non-zero lengths for widths and heights on
	table columns, table column groups, table rows, table row groups, and table cells
	in both auto and fixed layout tables
	MUST be treated as if ''width/auto'' had been specified.


<!-- Big Text: range

████▌   ███▌  █    █▌  ███▌  █████▌
█▌  █▌ ▐█ ▐█  █▌   █▌ █▌  █▌ █▌
█▌  █▌ █▌  █▌ ██▌  █▌ █▌     █▌
████▌  █▌  █▌ █▌▐█ █▌ █▌ ██▌ ████
█▌▐█   █████▌ █▌  ██▌ █▌  █▌ █▌
█▌ ▐█  █▌  █▌ █▌   █▌ █▌  █▌ █▌
█▌  █▌ █▌  █▌ █▌   ▐▌  ███▌  █████▌
-->

<h3 id='calc-range'>
Range Checking</h3>

	Parse-time range-checking of values is not performed within [=math functions=],
	and therefore out-of-range values do not cause the declaration to become invalid.
	However, the value resulting from a [=top-level calculation=]
	must be clamped to the range allowed in the target context.
	Clamping is performed on <a>computed values</a> to the extent possible,
	and also on <a>used values</a>
	if computation was unable to sufficiently simplify the expression
	to allow range-checking.
	(Clamping is not performed on <a>specified values</a>.)

	Note: This requires all contexts accepting ''calc()''
	to define any range restrictions as closed (not open) interval endpoints:
	"greater than or equal to 0px", not "greater than 0px" or "positive lengths".

	Note: While CSS intentionally leaves numeric precision/range UA-defined,
	extremely large values (including, notably, ±∞)
	will clamp to the minimum/maximum value allowed.
	Even properties that can explicitly represent infinity as a keyword value,
	such as 'animation-iteration-count',
	will end up clamping ±∞,
	as [=math functions=] can't resolve to keyword values;
	the <em>numeric</em> part of the property's syntax still has an implicit minimum/maximum value.

	Additionally, if a [=math function=] that resolves to <<number>>
	is used somewhere that only accepts <<integer>>,
	the [=computed value=] and [=used value=] are [=rounded to the nearest integer=],
	in the same manner as clamping, above.

	<div class=example>
		Since widths smaller than 0px are not allowed,
		these three declarations are equivalent:

		<pre>
		width: calc(5px - 10px);
		width: calc(-5px);
		width: 0px;
		</pre>

		Note however that ''width: -5px'' is not equivalent to ''width: calc(-5px)''!
		Out-of-range values <em>outside</em> ''calc()'' are syntactically invalid,
		and cause the entire declaration to be dropped.
	</div>

	<wpt>
	css/css-values/calc-integer.html
	css/css-values/calc-z-index-fractions-001.html
	</wpt>


<!-- Big Text: serial

 ███▌  █████▌ ████▌  ████  ███▌  █▌
█▌  █▌ █▌     █▌  █▌  ▐▌  ▐█ ▐█  █▌
█▌     █▌     █▌  █▌  ▐▌  █▌  █▌ █▌
 ███▌  ████   ████▌   ▐▌  █▌  █▌ █▌
    █▌ █▌     █▌▐█    ▐▌  █████▌ █▌
█▌  █▌ █▌     █▌ ▐█   ▐▌  █▌  █▌ █▌
 ███▌  █████▌ █▌  █▌ ████ █▌  █▌ █████
-->

<h3 id='calc-serialize'>
Serialization</h3>

	<div algorithm>
		To <dfn export>serialize a math function</dfn> |fn|:

		1. If the root of the [=calculation tree=] |fn| represents
			is a numeric value
			(number, percentage, or dimension),
			and the serialization being produced is of a [=computed value=] or later,
			then clamp the value to the range allowed for its context
			(if necessary),
			then serialize the value as normal
			and return the result.

		2. If |fn| represents an infinite or NaN value:
			1. Let |s| be the [=string=] "calc(".
			2. Serialize the keyword ''infinity'', ''-infinity'', or ''NaN'',
				as appropriate to represent the value,
				and append it to |s|.
			3. If |fn|’s [=CSSNumericValue/type=] is anything other than «[ ]»
				(empty, representing a <<number>>),
				append " * " to |s|.
				Create a numeric value
				in the [=canonical unit=] for |fn|'s [=CSSNumericValue/type=]
				(such as ''px'' for <<length>>),
				with a value of 1.
				Serialize this numeric value
				and append it to |s|.
			4. Append ")" to |s|, then return it.

		3. If the [=calculation tree’s=] root node is a numeric value,
			or a [=calc-operator node=],
			let |s| be a string initially containing "calc(".

			Otherwise,
			let |s| be a string initially containing the name of the root node,
			lowercased
			(such as "sin" or "max"),
			followed by a "(" (open parenthesis).

		4. For each child of the root node,
			[=serialize the calculation tree=].
			If a result of this serialization starts with a "(" (open parenthesis)
			and ends with a ")" (close parenthesis),
			remove those characters from the result.
			[=string/Concatenate=] all of the results
			using ", " (comma followed by space),
			then append the result to |s|.

		5. Append ")" (close parenthesis) to |s|.

		6. Return |s|.
	</div>

	<div algorithm>
		To <dfn export lt="serialize a calculation tree|serialize the calculation tree|serializing a calculation tree|serializing the calculation tree">serialize a calculation tree</dfn>:

		1. Let |root| be the root node
			of the [=calculation tree=].

		2. If |root| is a numeric value,
			or a non-[=math function=],
			serialize |root| per the normal rules for it
			and return the result.

		3. If |root| is anything but
			a Sum,
			Negate,
			Product,
			or Invert node,
			[=serialize a math function=]
			for the function corresponding to the node type,
			treating the node's children as the function's comma-separated [=calculation=] arguments,
			and return the result.

		4. If |root| is a Negate node:

			1. Let |s| be a [=string=]
				initially containing "(-1 * ".

			2. [=serialize a calculation tree|Serialize=] |root|'s child,
				and append it to |s|.

			3. Append ")" to |s|,
				then return it.

		5. If |root| is an Invert node:

			1. Let |s| be a [=string=]
				initially containing "(1 / ".

			2. [=serialize a calculation tree|Serialize=] |root|'s child,
				and append it to |s|.

			3. Append ")" to |s|,
				then return it.

		6. If |root| is a Sum node:

			1. Let |s| be a [=string=]
				initially containing "(".

			2. [=sort a calculation's children|Sort root's children=].

			3. [=serialize a calculation tree|Serialize=] |root|'s first child,
				and append it to |s|.

			4. [=list/For each=] |child| of |root| beyond the first:

				1. If |child| is a Negate node,
					append " - " to |s|,
					then [=serialize a calculation tree|serialize=] the Negate's child
					and append the result to |s|.

				2. If |child| is a negative numeric value,
					append " - " to |s|,
					then serialize the negation of |child| as normal
					and append the result to |s|.

				3. Otherwise,
					append " + " to |s|,
					then [=serialize a calculation tree|serialize=] |child|
					and append the result to |s|.

			5. Append ")" to |s|
				and return it.

		7. If |root| is a Product node:

			1. Let |s| be a [=string=]
				initially containing "(".

			2. [=sort a calculation's children|Sort root's children=].

			3. [=serialize a calculation tree|Serialize=] |root|'s first child,
				and append it to |s|.

			4. [=list/For each=] |child| of |root| beyond the first:

				1. If |child| is an Invert node,
					append " / " to |s|,
					then [=serialize a calculation tree|serialize=] the Invert's child
					and append the result to |s|.

				2. Otherwise,
					append " * " to |s|,
					then [=serialize a calculation tree|serialize=] |child|
					and append the result to |s|.

			5. Append ")" to |s|
				and return it.
	</div>

	<div algorithm>
		To <dfn>sort a calculation's children</dfn> |nodes|:

		1. Let |ret| be an empty list.

		2. If |nodes| contains a number,
			remove it from |nodes| and append it to |ret|.

		3. If |nodes| contains a percentage,
			remove it from |nodes| and append it to |ret|.

		4. If |nodes| contains any dimensions,
			remove them from |nodes|,
			sort them by their units,
			ordered [=ASCII case-insensitively=],
			and append them to |ret|.

		5. If |nodes| still contains any items,
			append them to |ret| in the same order.

		6. Return |ret|.
	</div>

	<wpt>
	css/css-values/calc-rgb-percent-001.html
	css/css-values/calc-serialization.html
	css/css-values/calc-serialization-002.html
	css/css-values/getComputedStyle-border-radius-001.html
	css/css-values/getComputedStyle-border-radius-003.html
	css/css-values/calc-background-position-003.html
	</wpt>

	<wpt>
	css/css-values/calc-nesting-002.html
	</wpt>

	<div class="example">
		For example, ''calc(20px + 30px)'' would serialize as ''calc(50px)'' as a specified value,
		or as ''50px'' as a computed value.

		A value like ''calc(20px + 0%)'' would serialize as ''calc(0% + 20px)'',
		maintaining both terms in the serialized value.
		(It's important to maintain zero-valued terms,
		so the ''calc()'' doesn't suddenly "change shape" in the middle of a transition
		when one of the values happens to have a zero value temporarily.
		This also removes the need to "pick a unit" when all the terms are zero.)

		A value like ''calc(20px + 2em)'' would serialize as ''calc(2em + 20px)'' as a specified value
		(maintaining both units as they're incompatible at specified-value time,
		but sorting them alphabetically),
		or as something like ''52px'' as a computed value
		(''em'' values are converted to absolute lengths at computed-value time,
		so assuming ''1em'' = ''16px'',
		they combine into ''52px'',
		which then drops the ''calc()'' wrapper.)
	</div>

	When used in non-property contexts
	(such as in ''@font-face'' descriptors, for example),
	[=math functions=] are simplified
	as if they were [=specified values=].

	See [[!CSSOM]] for further information on serialization.

<h3 id='combine-math'>
Combination of Math Functions</h3>

	[=Interpolation=] of [=math functions=],
	with each other
	or with numeric values and other numeric-valued functions,
	is defined as
	V<sub>result</sub> = calc((1 - p) * V<sub>A</sub> + p * V<sub>B</sub>).
	([=simplify a calculation tree|Simplification=] of the value might then reduce the expression
	to a smaller, simpler form.)

	[=Addition=] of [=math functions=],
	with each other
	or with numeric values and other numeric-valued functions,
	is defined as
	V<sub>result</sub> = calc(V<sub>A</sub> + V<sub>B</sub>).
	([=simplify a calculation tree|Simplification=] of the value might then reduce the expression
	to a smaller, simpler form.)


<!--
<h2 id="limits">
Appendix A: Recommended Minimum Ranges and Precision of Computed Values</h2>

	For unrestricted values, the recommended minimum range and precision
	of computed values
	is given in the table below.

	<table class="data">
	<thead>
		<tr>
			<th>Type
			<th>Recommended Minimum Precision
			<th>Recommended Minimum Maximum (Absolute Value)
	<tbody>
		<tr>
			<th><<integer>>
			<td>1
			<td>2<sup>23</sup>&minus;1
		<tr>
			<th><<number>>
			<td>0.01
				<small>(within the range -100 &lt; <var>x</var> &lt; 100)</small>
			<td>2<sup>17</sup>&minus;1
		<tr>
			<th><<percentage>>
			<td>0.01%
				<small>(within the range -100 &lt; <var>x</var> &lt; 100)</small>
			<td>(2<sup>17</sup>&minus;1)%
		<tr>
			<th><<length>>
			<td>0.1px
			<td>(2<sup>23</sup>&minus;1)px
		<tr>
			<th><<angle>>
			<td>0.1deg
			<td>(2<sup>23</sup>&minus;1)deg
		<tr>
			<th><<time>>
			<td>1ms
			<td>(2<sup>23</sup>&minus;1)ms
		<tr>
			<th><<frequency>>
			<td>0.01Hz
			<td>(2<sup>17</sup>&minus;1)Hz
	</table>

	Values outside the supported range must be clamped into the supported range.
	Values specified with an unsupported amount of precision must be rounded
	to the closest supported value when parsed;
	except that values that are not equal to, but would round to,
	either zero or the boundary of a closed range,
	should be rounded away from that value rather than to it.

	<div class="example">
		For example, in a UA that only supports a precision of 0.01,
		an 'opacity' value of ''0.9999'' would round to ''0.99'', not ''1.0'',
		and would therefore cause the element to create a stacking context.
		Similarly, a ''flex-grow'' value of ''0.001'' would round to ''0.01'',
		not ''0'', and would therefore be flexible.
	</div>


	When arithmetic is performed with numeric types
	(for example, in the ''calc()'' expression),
	if the result is unsupported
	it must also be clamped/rounded as necessary.
	<span class="note">
		Note this means that rounding errors <em>may</em> accumulate.
	</span>
-->

<!-- Big Text: lists

█▌    ████  ███▌  █████▌  ███▌
█▌     ▐▌  █▌  █▌   █▌   █▌  █▌
█▌     ▐▌  █▌       █▌   █▌
█▌     ▐▌   ███▌    █▌    ███▌
█▌     ▐▌      █▌   █▌       █▌
█▌     ▐▌  █▌  █▌   █▌   █▌  █▌
█████ ████  ███▌    █▌    ███▌
-->

<h2 id="linked-properties">
Appendix A: Coordinating List-Valued Properties</h2>

	Some list-valued properties have coordinated effects:
	each item in their value list applies to a distinct effect,
	and corresponding entries in each property's list
	all refer to the same effect.
	Often the coordinating values can also be specified together
	as a single entry in a list-valued [=shorthand property=].

	A typical example is the list-valued 'background-*' properties,
	which can specify <a href="https://www.w3.org/TR/css-backgrounds-3/#layering">multiple background image layers</a>.
	For each property controlling how the image is sized, tiled, placed, etc.,
	the <var>N</var>th item in its list describes some effect that applies
	to the <var>N</var>th background image.

	A <dfn export lt="coordinating list property | coordinating list property group">coordinating list property group</dfn> creates
	a <dfn export>coordinated value list</dfn>,
	which has, for each entry,
	a value from each property in the group;
	these are used together to define a single effect,
	such as a background image layer
	or an animation.
	The [=used value|used=] [=coordinated value list=] is assembled as follows:

	* The length of the [=coordinated value list=] is determined by
		the number of items specified in one particular [=coordinating list property=],
		the <dfn export>coordinating list base property</dfn>.
		(In the case of backgrounds, this is the 'background-image' property.)

	* The <var>N</var>th value of the [=coordinated value list=] is constructed
		by collecting the <var>N</var>th [=use value=] of each [=coordinating list property=]

	* If a [=coordinating list property=] has too many values specified,
		excess values at the end of its list are not [=used value|used=].

	* If a [=coordinating list property=] has too few values specified,
		its value list is repeated to add more [=used values=].

	* The [=computed values=] of the [=coordinating list properties=]
		are not affected by such truncation or repetition.

	<div class=note>
		A shorthand that represents a [=coordinated value list=]
		as a single list collecting corresponding values into each item
		cannot represent [=coordinating list property=] longhands
		that have varying list lengths in their values.
		Thus, if any longhands have mismatched list lengths
		(excepting any longhands that have their initial value,
		and thus can be omitted from the shorthand syntax),
		the CSSOM representation of the shorthand's value will return the empty string.

		<p class=example>In the 'background' shorthand,
		the first value in the list combines the first values from 'background-image', 'background-position, 'background-attachment', etc;
		the second value combines the second values; and so on.
		This syntax can only represent its longhands when they have equal-length lists
		(or are their initial value);
		if the longhands are individually set to different lengths,
		the CSSOM representation of 'background' is just <code>""</code> (the empty string).
	</div>

<h2 id='iana'>
Appendix B: IANA Considerations</h2>


<!-- Big Text: about:url

 ███▌  ████▌   ███▌  █▌  █▌ █████▌  █▌  █▌  █▌ ████▌  █▌
▐█ ▐█  █▌  █▌ █▌  █▌ █▌  █▌   █▌   ███▌ █▌  █▌ █▌  █▌ █▌
█▌  █▌ █▌  █▌ █▌  █▌ █▌  █▌   █▌    █▌  █▌  █▌ █▌  █▌ █▌
█▌  █▌ █████  █▌  █▌ █▌  █▌   █▌        █▌  █▌ ████▌  █▌
█████▌ █▌  █▌ █▌  █▌ █▌  █▌   █▌    █▌  █▌  █▌ █▌▐█   █▌
█▌  █▌ █▌  █▌ █▌  █▌ █▌  █▌   █▌   ███▌ █▌  █▌ █▌ ▐█  █▌
█▌  █▌ ████▌   ███▌   ███▌    █▌    █▌   ███▌  █▌  █▌ █████
-->

<h3 id='about-invalid'>
Registration for the <code>about:invalid</code> URL scheme</h3>

	This sections defines and registers the <code>about:invalid</code> URL,
	in accordance with the registration procedure defined in [[RFC6694]].


	The official record of this registration can be found at <a href="http://www.iana.org/assignments/about-uri-tokens/about-uri-tokens.xhtml">http://www.iana.org/assignments/about-uri-tokens/about-uri-tokens.xhtml</a>.

	<table class="data longlastcol">
		<tr>
			<th>Registered Token
			<td><code>invalid</code>
		<tr>
			<th>Intended Usage
			<td>
				The <code>about:invalid</code> URL references a non-existent document with a generic error condition.
				It can be used when a URL is necessary, but the default value shouldn't be resolvable as any type of document.
		<tr>
			<th>Contact/Change controller
			<td>CSS WG &lt;<a href="mailto:www-style@w3.org">www-style@w3.org</a>> (on behalf of W3C)
		<tr>
			<th>Specification
			<td><a href="https://www.w3.org/TR/css3-values/">CSS Values and Units Module Level 3</a>
	</table>


<!-- Big Text: quirks

 ███▌  █▌  █▌ ████ ████▌  █▌  █▌  ███▌
█▌  █▌ █▌  █▌  ▐▌  █▌  █▌ █▌ █▌  █▌  █▌
█▌  █▌ █▌  █▌  ▐▌  █▌  █▌ █▌█▌   █▌
█▌  █▌ █▌  █▌  ▐▌  ████▌  ██      ███▌
█▌▐ █▌ █▌  █▌  ▐▌  █▌▐█   █▌█▌       █▌
█▌ ▐▌  █▌  █▌  ▐▌  █▌ ▐█  █▌ █▌  █▌  █▌
 ██▌ ▌  ███▌  ████ █▌  █▌ █▌  █▌  ███▌
-->

<h2 id="deprecated-quirky-length">
Appendix C: Quirky Lengths</h2>

	When CSS is being parsed in [=quirks mode=],
	<dfn type><<quirky-length>></dfn> is a type of <<length>>
	that is only valid in certain properties:

	* 'background-position'
	* 'border-spacing'
	* 'border-top-width'
	* 'border-right-width'
	* 'border-bottom-width'
	* 'border-left-width'
	* 'border-width'
	* 'bottom'
	* 'clip'
	* 'font-size'
	* 'height'
	* 'left'
	* 'letter-spacing'
	* 'margin-right'
	* 'margin-left'
	* 'margin-top'
	* 'margin-bottom'
	* 'margin'
	* 'max-height'
	* 'max-width'
	* 'min-height'
	* 'min-width'
	* 'padding-top'
	* 'padding-right'
	* 'padding-bottom'
	* 'padding-left'
	* 'padding'
	* 'right'
	* 'text-indent'
	* 'top'
	* 'vertical-align'
	* 'width'
	* 'word-spacing'

	It is <em>not</em> valid in properties that include or reference these properties,
	such as the 'background' shorthand,
	or inside [=functional notations=] such as ''calc()'',
	except that they must be allowed in ''rect()'' in the 'clip' property.

	Additionally, while <<quirky-length>> must be valid as a <<length>>
	when parsing the affected properties in the ''@supports'' rule,
	it is <em>not</em> valid for those properties
	when used in the {{CSS/supports(conditionText)|CSS.supports()}} method.

	A <<quirky-length>> is syntactically identical to a <<number-token>>,
	and is interpreted as a ''px'' length with the same value.

	(In other words, Quirks Mode allows all ''px'' lengths in the affected properties
	to be written without a unit,
	similar to unitless zero lengths.)


<!-- Big Text: etc

█████▌ █████▌  ███▌
█▌       █▌   █▌  █▌
█▌       █▌   █▌
████     █▌   █▌
█▌       █▌   █▌
█▌       █▌   █▌  █▌
█████▌   █▌    ███▌
-->


<h2 class="no-num" id="acknowledgments">
Acknowledgments</h2>

	Firstly, the editors would like to thank
	all of the contributors to the <a href="http://www.w3.org/TR/css-values-3/#acknowledgments">previous level</a>
	of this module.

	Secondly, we would like to acknowledge
	Anthony Frehner,
	Emilio Cobos Álvarez,
	Guillaume Lebas,
	Koji Ishii,
	Noam Rosenthal,
	and
	Xidorn Quan
	for their comments and suggestions,
	which have improved Level 4.

<h2 class="no-num" id="changes">
Changes</h2>

<h3 class=no-num id="changes-recent">
Recent Changes</h3>

	(This is a subset of [[#additions-L3]].)

	Substantial changes since <a href="https://www.w3.org/TR/2024/WD-css-values-4-20240312/">12 March 2024 Working Draft</a>:
	* Adapt the [=snap as a line width=] algorithm to handle negative numbers.
		(<a href="https://github.com/w3c/csswg-drafts/issues/13795">Issue 13795</a>)

	ISSUE: Finish this list.

	Substantial changes since <a href="https://www.w3.org/TR/2023/WD-css-values-4-20231218/">18 December 2023 WD</a>:

	* Added the ''clamp()/none'' values to ''clamp()'',
		(<a href="https://github.com/w3c/csswg-drafts/issues/9713">Issue 9713</a>)
	* Generally fixed how type inference handles percentages.
		(<a href="https://github.com/w3c/csswg-drafts/issues/10017">Issue 10017</a>)
	* Restored dependency of [=viewport-percentage lengths=] on ''overflow: scroll''
		and added one on 'scrollbar-gutter'
		to make it possible for 100 of these units to actually match the [=initial containing block=].
		(<a href="https://github.com/w3c/csswg-drafts/issues/6026">Issue 6026</a>)
	* Allow B to be omitted in ''round()'' if the A's type is <<number>>.
		(<a href="https://github.com/w3c/csswg-drafts/issues/9668">Issue 9668</a>)

	Substantial changes since <a href="https://www.w3.org/TR/2023/WD-css-values-4-20231027/">27 October 2023 WD</a>:

	* Pinned the [=default viewport-percentage units=] to the [=large viewport-percentage units=]--
		despite violation of the “avoid dataloss by default principle”--
		given existing interoperability and presumed Web-compat restriction.
		(<a href="https://github.com/w3c/csswg-drafts/issues/6454">Issue 6452</a>)
	* Added an explicit definition for the [=CSS grammar production block=] convention.
		(<a href="https://github.com/w3c/csswg-drafts/issues/2921">Issue 2921</a>)
	* Clarified character encoding of percent-encoded URLs.
		(<a href="https://github.com/w3c/csswg-drafts/issues/9301">Issue 9301</a>)

	Substantial changes since <a href="https://www.w3.org/TR/2023/WD-css-values-4-20230406/">6 April 2023 WD</a>:

	* Punted ''mix()'' to [[css-values-5]].
		(<a href="https://github.com/w3c/csswg-drafts/issues/9343">Issue 9343</a>)
	* Color type defined to be non-additive.
		(<a href="https://github.com/w3c/csswg-drafts/issues/8576">Issue 8576</a>)
	* Non-property contexts treat [=math functions=] as specified values.
		(<a href="https://github.com/w3c/csswg-drafts/issues/7964">Issue 7964</a>)
	* Specified that URLs from CSS are always transmitted as UTF-8.
		(<a href="https://github.com/w3c/csswg-drafts/issues/9301">Issue 9301</a>)
	* Fixed [=addition=]/[=accumulation=] to use the *second* value,
		when the two values aren't additive/accumulative.
		(<a href="https://github.com/w3c/csswg-drafts/issues/9070">Issue 9070</a>)
	* Specified that [=font-relative lengths=]
		are always resolved against the parent element
		when used in a 'font-*' property.
		(<a href="https://github.com/w3c/csswg-drafts/issues/8169">Issue 8169</a>)
	* Simplify away single-argument ''min()'' and ''max()'' functions.
		(<a href="https://github.com/w3c/csswg-drafts/issues/9559">Issue 9559</a>)

	Substantial changes since <a href="https://www.w3.org/TR/2022/WD-css-values-4-20221019/">19 October 2022 WD</a>:
	<ul>
		<li>Added [[#component-functions]] to formally define the way that [=functional notation=] syntaxes are defined.
			(<a href="https://github.com/w3c/csswg-drafts/issues/2921">Issue 2921</a>)
		<li>Added algorithm for [=snap as a line width=],
			to reflect the interoperable rules for rendering consistent stroke widths.
			(<a href="https://github.com/w3c/csswg-drafts/issues/5210">Issue 5210</a>)
		<li>Clarified grammar and [=computed value=] of ''mix()''.
			(<a href="https://github.com/w3c/csswg-drafts/issues/8096">Issue 8096</a>)
		<li>Undefined the behavior of ''tan()'' at the asymptote values.
			(<a href="https://github.com/w3c/csswg-drafts/issues/8527">Issue 8527</a>)
		<li>Specified that negative <<resolution>> values are out-of-range by definition.
			(<a href="https://github.com/w3c/csswg-drafts/issues/8532">Issue 8532</a>)
		<li>Clarified that fully omitted ''mix()'' arguments are valid.
			(<a href="https://github.com/w3c/csswg-drafts/issues/8556">Issue 8556</a>)
		<li>Clarified that range clamping happens specifically to [=top-level calculations=]
			(rather than the unclear term "expressions").
			(<a href="https://github.com/w3c/csswg-drafts/issues/8158">Issue 8158</a>)
		<li>Added formal definitions for <<url()>> and <<src()>> (in addition to <<url>>).
		<li>Rephrased fragment-only URLs in terms of tree-scoped references.
			(<a href="https://github.com/w3c/csswg-drafts/issues/3320">Issue 3320</a>)
	</ul>

	Substantial changes since <a href="https://www.w3.org/TR/2021/WD-css-values-4-20211216/">16 December 2021 WD</a>:

	<ul>
		<li>Changed resolution of a ''url()'' with the [=local url flag=]
			to reference the current [=node tree=] (regardless of document base URL modifications).
			(<a href="https://github.com/w3c/csswg-drafts/issues/3320">Issue 3320</a>)
		<li>Switched censoring of ''NaN'' that escapes a [=math function=] from infinity to zero.
			(<a href="https://github.com/w3c/csswg-drafts/issues/7067">Issue 7067</a>)
		<li>Added [[#linked-properties]] to allow this property pattern to be easily referenced.
			(<a href="https://github.com/w3c/csswg-drafts/issues/7164">Issue 7164</a>)
		<li>Restricted ''mix()'' to be the sole value of a declaration.
			(<a href="https://github.com/w3c/csswg-drafts/issues/6700">Issue 6700</a>)
		<li>Updated to match latest Fetch terminology.
			(<a href="https://github.com/whatwg/fetch/pull/1413">Fetch PR 1413</a>,
			<a href="https://github.com/w3c/csswg-drafts/pull/7160">CSS PR 7160</a>)
		<li>Clarified that the [=font-relative lengths=] are calculated without text shaping.
		<li>Defined serialization of empty urls to be <code>url("")</code>.
			(<a href="https://github.com/w3c/csswg-drafts/issues/6447">Issue 6447</a>)
		<li>Defined serialization of <<position>> [=specified values=].
			(<a href="https://github.com/w3c/csswg-drafts/issues/2274">Issue 2274</a>)
		<li>Fixed definition of [=numbers=] to allow decimals in combination with scientific notation,
			as originally intended and as defined in [[CSS-SYNTAX-3]].
			(<a href="https://github.com/w3c/csswg-drafts/issues/7248">Issue 7248</a>)
		<li>Corrected various functions to return an empty map
			for their [=CSSNumericValue/type=] instead of «[ "number" → 1 ]».
			(<a href="https://github.com/w3c/csswg-drafts/issues/7486">Issue 7486</a>)
		<li>Clarified effect of special UA restrictions on 'line-height' on ''lh'' and ''rlh''.
			(<a href="https://github.com/w3c/csswg-drafts/issues/3257">Issue 3257</a>)
		<li>Defined <code>&lt;function()></code> notation to refer to functional notations.
			(<a href="https://github.com/w3c/csswg-drafts/issues/5728">Issue 5728</a>)
	</ul>

	Substantial changes since <a href="https://www.w3.org/TR/2021/WD-css-values-4-20211016/">16 October 2021 WD</a>:

	<ul>
		<li>Switched ''*vi'' and ''*vb'' units to resolve against the computed [=writing mode=] of the element itself.
			(<a href="https://github.com/w3c/csswg-drafts/issues/6873">Issue 6873</a>)
		<li>Added [[#url-processing]] to define integration with CORS, etc.
			(<a href="https://github.com/w3c/csswg-drafts/issues/562">Issue 562</a>)
		<li>Fixed the inverted assignment of [=viewport-percentage length=] behaviors
			to types of interface changes (A vs. B).
			<blockquote>
				<ul>
				<li>Changes in interface that happen as a result of scrolling
					or other frequent page interactions that would disturb the user
					if they resulted in substantial layout changes
					must be categorized as the <del>former (A)</del> <ins>latter (B)</ins>.
				<li>Changes in interface that have a sufficiently steady state
					that re-laying out the document into the adjusted space
					would be beneficial to the user
					must be categorized as the <del>latter (B)</del> <ins>former (A)</ins>.
				</ul>
			</blockquote>
		<li>Defined minimum number of ''calc()'' terms, arguments, and nesting as 32.
			(<a href="https://github.com/w3c/csswg-drafts/issues/3462">Issue 3462</a>)
		<li>Defined that ''mod(-0, infinity)'' returns ''NaN''.
			(<a href="https://github.com/w3c/csswg-drafts/issues/4723">Issue 4723</a>)
		<li>Deferred ''toggle()'' and ''attr()'' to Level 5.
	</ul>

	Changes since <a href="https://www.w3.org/TR/2021/WD-css-values-4-20210930/">30 September 2021 WD</a>:

	<ul>
		<li>Added  ''rex'', ''rcap'', ''rch'', and ''ric'' units.
		<li>Switched ''toggle()'' to use semicolons, matching with ''mix()''.
			(<a href="https://github.com/w3c/csswg-drafts/issues/6701">Issue 6701</a>)
		<li>Fixed some wording errors in the definition of ''calc()''.
			(<a href="https://github.com/w3c/csswg-drafts/issues/6506">Issue 6506</a>)
		<li>Imported definition of <<quirky-length>> from [[QUIRKS]].
			(<a href="https://github.com/w3c/csswg-drafts/issues/6100">Issue 6100</a>)
	</ul>

	Changes since <a href="https://www.w3.org/TR/2021/WD-css-values-4-20210715/">7 July 2021 WD</a>:

	<ul>
		<li>Added ''mix()'' notation for representing interpolated values.
		<li>Defined generically the computation of
			<<integer>>, <<number>>, <<percentage>>, and <<length>>.
		<li>Clarified that only non-zero lengths create a percentage+length mix
			that switches table cells to ''width/auto'' sizing.
	</ul>

	Changes since <a href="https://www.w3.org/TR/2020/WD-css-values-4-20201111/">11 November 2020 WD</a>:

	<ul>
		<li>Updated interpolation of colors to reference [[CSS-COLOR-4]] instead of [[CSS-COLOR-3]].
		<li>Added the ''svh'', ''svw'', ''svi'', ''svb'', ''svmin'', and ''svmax'' [=small viewport-percentage units=];
			''lvh'', ''lvw'', ''lvi'', ''lvb'', ''lvmin'', and ''lvmax'' [=large viewport-percentage units=];
			and ''dvh'', ''dvw'', ''dvi'', ''dvb'', ''dvmin'', and ''dvmax'' [=dynamic viewport-percentage units=].
			(<a href="https://github.com/w3c/csswg-drafts/issues/4329">Issue 4329</a> and
			<a href="https://github.com/w3c/csswg-drafts/issues/6113">Issue 6113</a>)
		<li>Clamped excessively large <<angle>> values to multiples of ''360deg''.
			(<a href="https://github.com/w3c/csswg-drafts/issues/6105">Issue 6105</a>)
		<li>Added back [[#combining-range|rules on range-checking combined values]]
			lost during move from the <a href="https://www.w3.org/TR/css-transitions-1/">CSS Transitions</a> specification.
			(<a href="https://github.com/w3c/csswg-drafts/issues/6097">Issue 6097</a>)
		<li>Specified that UA-imposed minimum font sizes apply to the used 'font-size'
			and not to resolution of [=font-relative lengths=].
			(<a href="https://github.com/w3c/csswg-drafts/issues/5858">Issue 5858</a>)
		<li>Clarified how ''min()'' and ''max()'' percentages can partially simplify.
			(<a href="https://github.com/w3c/csswg-drafts/issues/6298">Issue 6293</a>)
	</ul>

<h3 class=no-num id="additions-L3">
Additions Since Level 3</h3>

	Changes since <a href="http://www.w3.org/TR/css-values-3/">CSS Values and Units Level 3</a>:

	<ul>
		<li>Explicitly undefined numeric precision/range.
		<li>Added rules for interpolation per value type,
			and their clarified computed values.
		<li>Updated interpolation of colors to reference [[CSS-COLOR-4]].
	</ul>

	Additions since <a href="http://www.w3.org/TR/css-values-3/">CSS Values and Units Level 3</a>:

	<ul>
		<li>Defined the <<dashed-ident>> type.
		<li>Defined the <<ratio>> type.
		<li>Added ''src()'' to the <<url>> type.
		<li>Added the ''vi'', ''vb'', ''ic'', ''cap'', ''lh'' and ''rlh'' length units.
		<li>Added the ''svh'', ''svw'', ''svi'', ''svb'', ''svmin'', and ''svmax'' [=small viewport-percentage units=]
			and ''dvh'', ''dvw'', ''dvi'', ''dvb'', ''dvmin'', and ''dvmax'' [=dynamic viewport-percentage units=].
		<li>Added the ''x'' alias to ''dppx''.
		<li>Added ''min()'', ''max()'', and ''clamp()''
			[[#comp-func|comparison functions]].
		<li>Added ''round()'', ''mod()'', ''rem()'', ''sin()'', ''cos()'', ''tan()'', ''asin()'', ''acos()'', ''atan()'', ''atan2()'', ''pow()'', ''sqrt()'', ''hypot()'', ''log()'', ''exp()'', ''abs()'', ''sign()''
			math functions.
		<li>Added ''e'', ''pi'', ''infinity'', ''-infinity'', ''NaN''
			constants for use in ''calc()''.
		<li>Added [[#calc-type-checking|unit algebra]] to ''calc()'',
			allowing multiplication and division of [=dimensions=].
		<li>A non-integer in a calc() automatically rounds to the nearest integer
			when used where an <<integer>> is required.
		<li>Defined [[#calc-serialize|serialization]] of [=math functions=].
		<li>Added a genericized definition of [=coordinating list property groups=],
			to make it easier to reference the coordinating behavior of the 'background' properties.
	</ul>

<h2 class="no-num" id="security">
Security Considerations</h2>

	This specification presents no new security considerations.

	This specification defines the ''url()'' and ''src()'' functions (<<url>>),
	which allow CSS to make network requests.
	Depending on what features they are used in,
	these can potentially expose whether or not the user has access to resources on a network,
	and expose information about their contents
	(such as the rules within a style sheet, the size of an image, the metrics of a font).
	They can also allow exfiltrating data via URL.

<h2 class="no-num" id="privacy">
Privacy Considerations</h2>

	This specification defines units that expose the user's screen size
	(the [=viewport-percentage lengths=]),
	default font size,
	and potentially some information about
	which fonts are available on the user's system
	(the [=font-relative lengths=]).

	This specification defines the ''url()'' and ''src()'' functions (<<url>>),
	which allow CSS to make network requests.
	Depending on what features they are used in,
	these can potentially expose whether or not the user has access to resources on a network,
	and expose information about their contents
	(such as the rules within a style sheet, the size of an image, the metrics of a font).
	They can also allow exfiltrating data via URL.
