8000 csswg-drafts/css3-values/Overview.html at 168c97e401567c4b531823eeccb684be68b751c6 · w3c/csswg-drafts · GitHub
Skip to content

Latest commit

 

History

History
2008 lines (1485 loc) · 71.2 KB

File metadata and controls

2008 lines (1485 loc) · 71.2 KB
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang=en>
<head><meta content="text/html; charset=iso-8859-1" http-equiv=Content-Type>
<title>CSS3 Values and Units</title>
<style type="text/css">
.issue { color: red }
table { border-collapse: collapse; border: 1px solid black; margin: 1em 0 }
th, td { border: 1px solid black; padding: 0.2em; text-align: left }
tt.declaration { white-space: nowrap }
.del { text-decoration: line-through}
.say { font-style: italic }
</style>
<link href="../default.css" rel=stylesheet type="text/css">
<link href="http://www.w3.org/StyleSheets/TR/W3C-ED.css" rel=stylesheet
type="text/css">
<body>
<div class=head> <!--begin-logo-->
<p><a href="http://www.w3.org/"><img alt=W3C height=48
src="http://www.w3.org/Icons/w3c_home" width=72></a> <!--end-logo-->
<h1 id=css3-template>CSS3 Values and Units</h1>
<h2 class="no-num no-toc" id=longstatus-date>Editor's Draft 21 February
2009</h2>
<dl>
<dt>This version:
<dd><a
href="http://www.w3.org/TR/2009/ED-css3-values-20090221">http://www.w3.org/TR/2009/ED-css3-values-20090221</a>
<dt>Latest version:
<dd><a
href="http://www.w3.org/TR/css3-values">http://www.w3.org/TR/css3-values</a>
<dt>Previous version:
<dd><a
href="http://www.w3.org/TR/2005/WD-css3-values-20050726">http://www.w3.org/TR/2005/WD-css3-values-20050726</a>
<dt>Editors:
<dd>H&aring;kon Wium Lie, Opera Software &lt;howcome@opera.com&gt;
<dd>Chris Lilley, W3C &lt;chris@w3.org&gt;
</dl>
<!--begin-copyright-->
<p class=copyright><a
href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright"
rel=license>Copyright</a> &copy; 2009 <a
href="http://www.w3.org/"><acronym title="World Wide Web
Consortium">W3C</acronym></a><sup>&reg;</sup> (<a
href="http://www.csail.mit.edu/"><acronym title="Massachusetts Institute
of Technology">MIT</acronym></a>, <a
href="http://www.ercim.org/"><acronym title="European Research Consortium
for Informatics and Mathematics">ERCIM</acronym></a>, <a
href="http://www.keio.ac.jp/">Keio</a>), All Rights Reserved. W3C <a
href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>,
<a
href="http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a>
and <a
href="http://www.w3.org/Consortium/Legal/copyright-documents">document
use</a> rules apply.</p>
<!--end-copyright-->
<hr title="Separator for header">
</div>
<h2 class="no-num no-toc" id=abstract>Abstract</h2>
<p>This CSS3 module describes the various values and units that CSS
properties accept. Also, it describes how values are computed from
"specified" through "computed" and "used" into "actual" values. The main
purpose of this module is to define common values and units in one
specification which can be referred to by other modules. As such, it does
not make sense to claim conformance with this module alone.
<h2 class="no-num no-toc" id=status>Status of this document</h2>
<!--begin-status-->
<p>This is a public copy of the editors' draft. It is provided for
discussion only and may change at any moment. Its publication here does
not imply endorsement of its contents by W3C. Don't cite this document
other than as work in progress.
<p>The (<a
href="http://lists.w3.org/Archives/Public/www-style/">archived</a>) public
mailing list <a href="mailto:www-style@w3.org">www-style@w3.org</a> (see
<a href="http://www.w3.org/Mail/Request">instructions</a>) is preferred
for discussion of this specification. When sending e-mail, please put the
text &#8220;css3-values&#8221; in the subject, preferably like this:
&#8220;[<!---->css3-values<!---->] <em>&hellip;summary of
comment&hellip;</em>&#8221;
<p>This document was produced by the <a href="/Style/CSS/members">CSS
Working Group</a> (part of the <a href="/Style/">Style Activity</a>).
<p>This document was produced by a group operating under the <a
href="/Consortium/Patent-Policy-20040205/">5 February 2004 W3C Patent
Policy</a>. W3C maintains a <a href="/2004/01/pp-impl/32061/status"
rel=disclosure>public list of any patent disclosures</a> made in
connection with the deliverables of the group; that page also includes
instructions for disclosing a patent. An individual who has actual
knowledge of a patent which the individual believes contains <a
href="/Consortium/Patent-Policy-20040205/#def-essential">Essential
Claim(s)</a> must disclose the information in accordance with <a
href="/Consortium/Patent-Policy-20040205/#sec-Disclosure">section 6 of the
W3C Patent Policy</a>.</p>
<!--end-status-->
<p>All features described in this specification that also exist in CSS 2.1
<a href="#CSS21" rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a> are intended
to be backwards compatible. In case of conflict between this draft and
CSS&nbsp;2.1 <a href="#CSS21"
rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>, CSS&nbsp;2.1 probably
represents the intention of the CSS WG better than this draft (other than
on values and units that are new to CSS3).
<p>This is a draft of a <a href="http://www.w3.org/TR/css3-roadmap/">module
of CSS level 3</a>. It will probably be bundled with some other modules
before it becomes a <a href="http://www.w3.org/TR/#About">W3C
Recommendation</a>.
<h2 class="no-num no-toc" id=contents>Table of contents</h2>
<!--begin-toc-->
<ul class=toc>
<li><a href="#dependencies-on-other-modules"><span class=secno>1
</span>Dependencies on other modules</a>
<li><a href="#introduction"><span class=secno>2 </span>Introduction</a>
<li><a href="#value-definitions"><span class=secno>3 </span>Value
definitions</a>
<li><a href="#syntax-and-terminology"><span class=secno>4 </span>Syntax
and terminology</a>
<ul class=toc>
<li><a href="#integers"><span class=secno>4.1 </span>Integers</a>
<li><a href="#numbers"><span class=secno>4.2 </span>Numbers</a>
<li><a href="#numbers-with-unit-identifiers"><span class=secno>4.3
</span>Numbers with unit identifiers</a>
<li><a href="#identifiers"><span class=secno>4.4 </span>Identifiers</a>
<li><a href="#strings"><span class=secno>4.5 </span>Strings</a>
<li><a href="#functional-notation"><span class=secno>4.6
</span>Functional notation</a>
</ul>
<li><a href="#keywords"><span class=secno>5 </span>Keywords</a>
<li><a href="#generic-data-types"><span class=secno>6 </span>Generic data
types</a>
<ul class=toc>
<li><a href="#ltintegergt"><span class=secno>6.1
</span>&lt;integer&gt;</a>
<li><a href="#ltnumbergt"><span class=secno>6.2
</span>&lt;number&gt;</a>
<li><a href="#ltlengthgt-"><span class=secno>6.3 </span>&lt;length&gt;
</a>
<ul class=toc>
<li><a href="#absolute-length-units-cm-mm.-in-pt-pc"><span
class=secno>6.3.1 </span>Absolute length units: cm, mm. in, pt,
pc</a>
<li><a href="#relative-length-units"><span class=secno>6.3.2
</span>Relative length units</a>
<ul class=toc>
<li><a href="#the-em-unit"><span class=secno>6.3.2.1. </span>The
&lsquo;<code class=property>em</code>&rsquo; unit</a>
<li><a href="#the-ex-unit"><span class=secno>6.3.2.2. </span>The
&lsquo;<code class=property>ex</code>&rsquo; unit</a>
<li><a href="#the-px-unit"><span class=secno>6.3.2.3. </span>The
&lsquo;<code class=property>px</code>&rsquo; unit</a>
<li><a href="#the-rem-unit"><span class=secno>6.3.2.4. </span>The
&lsquo;<code class=property>rem</code>&rsquo; unit</a>
<li><a href="#the-vw-unit"><span class=secno>6.3.2.5. </span>The
&lsquo;<code class=property>vw</code>&rsquo; unit</a>
<li><a href="#the-vh-unit"><span class=secno>6.3.2.6. </span>The
&lsquo;<code class=property>vh</code>&rsquo; unit</a>
<li><a href="#the-vm-unit"><span class=secno>6.3.2.7. </span>The
&lsquo;<code class=property>vm</code>&rsquo; unit</a>
</ul>
<li><a href="#the-calc-function"><span class=secno>6.3.3 </span>The
&lsquo;<code class=property>calc</code>&rsquo; function</a>
</ul>
<li><a href="#ltstringgt"><span class=secno>6.4
</span>&lt;string&gt;</a>
<li><a href="#ltcolorgt"><span class=secno>6.5 </span>&lt;color&gt;</a>
<li><a href="#ltpercentagegt-"><span class=secno>6.6
</span>&lt;percentage&gt; </a>
<li><a href="#ltanglegt-"><span class=secno>6.7 </span>&lt;angle&gt;
</a>
<li><a href="#lttimegt"><span class=secno>6.8 </span>&lt;time&gt;</a>
<li><a href="#ltfrequencygt"><span class=secno>6.9
</span>&lt;frequency&gt;</a>
<li><a href="#ltattrgt"><span class=secno>6.10 </span>&lt;attr&gt;</a>
<li><a href="#uris"><span class=secno>6.11 </span>&lt;url&gt;</a>
<li><a href="#ltimagegt"><span class=secno>6.12 </span>&lt;image&gt;& 8096 lt;/a>
<li><a href="#ltfractiongt"><span class=secno>6.13
</span>&lt;fraction&gt;</a>
<ul class=toc>
<li><a href="#the-fr-unit"><span class=secno>6.13.1 </span>The
&lsquo;<code class=property>fr</code>&rsquo; unit</a>
</ul>
<li><a href="#ltgridgt"><span class=secno>6.14 </span>&lt;grid&gt;</a>
<ul class=toc>
<li><a href="#the-gr-unit"><span class=secno>6.14.1 </span>The
&lsquo;<code class=property>gr</code>&rsquo; unit</a>
</ul>
</ul>
<li><a href="#specified-computed-used-and-actual-value"><span
class=secno>7 </span>Specified, computed, used, and actual values</a>
<ul class=toc>
<li><a href="#finding-the-specified-value"><span class=secno>7.1
</span>Finding the specified value</a>
<li><a href="#finding-the-computed-value"><span class=secno>7.2
</span>Finding the computed value</a>
<li><a href="#finding-the-used-value"><span class=secno>7.3
</span>Finding the used value</a>
<li><a href="#finding-the-actual-value"><span class=secno>7.4
</span>Finding the actual value</a>
</ul>
<li class=no-num><a href="#acknowledgments">Acknowledgments</a>
<li class=no-num><a href="#references">References</a>
<ul class=toc>
<li class=no-num><a href="#normative-references">Normative
references</a>
<li class=no-num><a href="#other-references">Other references</a>
</ul>
<li class=no-num><a href="#index">Index</a>
</ul>
<!--end-toc-->
<h2 id=dependencies-on-other-modules><span class=secno>1
</span>Dependencies on other modules</h2>
<p>This CSS3 module depends on the following other CSS3 modules:
<ul>
<li><cite>Cascading and Inheritance</cite> <a href="#CSS3CASCADE"
rel=biblioentry>[CSS3CASCADE]<!--{{!CSS3CASCADE}}--></a>, which describes
how to find the <cite>resulting value</cite> from several competing
values. Also, it describes how to replace the "inherit" keyword with the
inherited value.
<li><cite>Syntax</cite> <a href="#CSS3SYN"
rel=biblioentry>[CSS3SYN]<!--{{!CSS3SYN}}--></a>, which describes the
syntax of values at the lexical level.
<li><cite>Color</cite> <a href="#CSS3COLOR"
rel=biblioentry>[CSS3COLOR]<!--{{!CSS3COLOR}}--></a>, which defines
additional values used for some properties that control color of text,
borders, etc
<li><cite>Fonts</cite> <a href="#CSS3FONT"
rel=biblioentry>[CSS3FONT]<!--{{!CSS3FONT}}--></a>, which describes
additional values used for font-related properties
</ul>
<h2 id=introduction><span class=secno>2 </span>Introduction</h2>
<p>By setting property values on elements in a document, style sheets
express the appearance of the document. In order to express rich designs,
a wide range of values and associated units are necessary. This
specifiction describes the various types of values and units that can be
used in CSS style sheets.
<h2 id=value-definitions><span class=secno>3 </span>Value definitions</h2>
<p>Each CSS property has a value definition field in the property
description. The value definition describes what types of values the
property accepts. The syntax used in the value definitions field is <a
href="http://www.w3.org/TR/css3-syntax/#property-def-value">defined</a> in
<a href="#CSS3SYN" rel=biblioentry>[CSS3SYN]<!--{{!CSS3SYN}}--></a>.
<div class=example>
<p>Here are some sample properties with corresponding value definition
fields:
<table>
<tbody>
<tr>
<th>Property
<th>Value definition field
<tr>
<td>min-width
<td>&lt;length&gt; | &lt;percentage&gt; | inherit
<tr>
<td>outline-color
<td>&lt;color&gt; | invert | inherit
<tr>
<td>orphans
<td>&lt;integer&gt; | inherit
<tr>
<td>pitch
<td>&lt;frequency&gt; | x-low | low | medium | high | x-high | inherit
<tr>
<td>string-set
<td>[[ &lt;identifier> &lt;content-list>] [, &lt;identifier>
&lt;content-list>]* ] | none
</table>
</div>
<p>The value definition fields contain keywords, data types (which appear
between "<" and ">", and information on how they can be combined. Generic
data types (&lt;length&gt; being the most widely used) that can be used by
many properties are described in this specification, while more specific
data types (e.g., &lt;border-width&gt;) are described in the corresponding
modules.
<h2 id=syntax-and-terminology><span class=secno>4 </span>Syntax and
terminology</h2>
<p>The generic data types described in the next sections use some common
syntactic building blocks and terms that are described in this section.
<h3 id=integers><span class=secno>4.1 </span>Integers</h3>
<p>An <dfn id=integer-is-one-or-more-decimal-digits-0->integer<dfn> is one
or more decimal digits "0" to "9". Integers may be preceded by "-" or "+"
to indicate the sign. </dfn></dfn>
<div class=example>
<pre>
orphans: 3
</pre>
</div>
<h3 id=numbers><span class=secno>4.2 </span>Numbers</h3>
<p>A <dfn id=number>number</dfn> is either an integer, or zero or more
decimal digits followed by a dot (.) followed by one or more decimal
digits. Numbers may be preceded by "-" or "+" to indicate the sign.
<div class=example>
<pre>
line-height: 1.2
</pre>
</div>
<h3 id=numbers-with-unit-identifiers><span class=secno>4.3 </span>Numbers
with unit identifiers</h3>
<p>A <dfn id=number-with-a-unit-identifier-is-a-numbe>number with a unit
identifier<dfn> is a number immediately followed by a unit identifier.
</dfn></dfn>
<div class=example>
<pre>
border-left: -1.2em
</pre>
</div>
<h3 id=identifiers><span class=secno>4.4 </span>Identifiers</h3>
<p>An <dfn id=identifer>identifer</dfn> is an seqence of characters.
Identifiers cannot start with a digit, and there are other restrictions <a
href="#CSS3SYN" rel=biblioentry>[CSS3SYN]<!--{{!CSS3SYN}}--></a> on what
characters an identifier can contain. Identifiers must not be quoted.
<div class=example>
<pre>
pitch-range: inherit;
counter-increment: header;
</pre>
</div>
<h3 id=strings><span class=secno>4.5 </span>Strings</h3>
<p>A <dfn id=string>string</dfn> is a sequence of characters enclosed by
double quotes or single quotes. Double quotes cannot occur inside double
quotes, unless escaped (as &lsquo;<code class=css>\"</code>&rsquo; or as
&lsquo;<code class=css>\22</code>&rsquo;). Analogously for single quotes
("\'" or "\27").<!--"-->
<div class=example>
<pre>
content: "this is a &lsquo;<code class=property><a href="#string">string</a></code>&rsquo;";
content: "this is a \"string\"";
content: &lsquo;<code class=css>this is a "string"</code>&rsquo;;
content: &lsquo;<code class=css>this is a \</code>&rsquo;string\'';
</pre>
</div>
<p>A string cannot directly contain a <span class=index
id=newline>newline</span>. 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). See the <span
class=property>&lsquo;<code class=property>content</code>&rsquo;</span>
property for an example.
<p>It is possible to break strings over several lines, for esthetic 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):</p>
<pre>
a[title="a not s\
o very long title"] {/*...*/}
a[title="a not so very long title"] {/*...*/}
</pre>
</div>
<h3 id=functional-notation><span class=secno>4.6 </span>Functional notation</h3>
<p>Some values use a <dfn id=functional-notation0>functional notation</dfn>
to type values and to and lump values together. The syntax starts with the
name of the function followed by a left parenthesis followed by optional
whitespace followed by the argument(s) to the functions followed by
optional whitespace followed by a right parenthesis. If a function takes
more than one argument, the arguments are separated by a comma
(&lsquo;<code class=css>,</code>&rsquo;) with optional whitespace before
and after the comma.
<div class=example> background: url(http://www.example.org/image); color:
rgb(100, 200, 50 );</div>
<p>Some properties accept space- or comma-separated lists of values. A
value that is composed of several values with spaces or commas between
them, is called a <dfn id=compound-value>compound value</dfn>. A value
that is not a compound value is a <dfn id=simple-value>simple value</dfn>.
<h2 id=keywords><span class=secno>5 </span>Keywords</h2>
<p>In the value definition fields, keywords appear literally. Keywords are
identifiers.
<div class=example>
<p>For example, here is the value definition for the &lsquo;<code
class=property>border-collapse</code>&rsquo; property:</p>
<pre>
Value:&nbsp;collapse | separate
</pre>
<p>And here is an example of its use:</p>
<pre>
table { border-collapse: separate }
</pre>
</div>
<p>All CSS3 properties accept the keyword values <span
class=css>&lsquo;<code class=property>inherit</code>&rsquo;</span> and
<span class=css>&lsquo;<code class=property>initial</code>&rsquo;</span>,
as described in <a href="#CSS3CASCADE"
rel=biblioentry>[CSS3CASCADE]<!--{{!CSS3CASCADE}}--></a>.
<p class=issue>Would it be useful to have a &lsquo;<code
class=property>default</code>&rsquo; value, defined to be equivalent to
<span class=css>&lsquo;<code class=property>inherit</code>&rsquo;</span>
for properties that are inherited by default and equivalent to <span
class=css>&lsquo;<code class=property>initial</code>&rsquo;</span> for
properties that are not inherited by default? This might be easier for
authors to use than <span class=css>&lsquo;<code
class=property>initial</code>&rsquo;</span> and <span
class=css>&lsquo;<code class=property>inherit</code>&rsquo;</span> since
it wouldn't require thinking about whether a property is inherited by
default or not (which isn't obvious for some properties, such as
text-decoration and visibility).
<h2 id=generic-data-types><span class=secno>6 </span>Generic data types</h2>
<h3 id=ltintegergt><span class=secno>6.1 </span>&lt;integer&gt;</h3>
<p>Integer values are denoted by <dfn id=ltintegergt0>&lt;integer&gt;</dfn>
in the value definitions. Properties may restrict the integer value to
some range. If the value is outside the allowed range, the declaration is
ignored.
<h3 id=ltnumbergt><span class=secno>6.2 </span>&lt;number&gt;</h3>
<p>Number values are denoted by <dfn id=ltnumbergt0>&lt;number&gt;</dfn> in
the value definitions. Properties may restrict the number value to some
range. If the value is outside the allowed range, the declaration is
ignored.
<h3 id=ltlengthgt-><span class=secno>6.3 </span>&lt;length&gt;</h3>
<p>Lengths are denoted by <dfn id=ltlengthgt>&lt;length&gt;</dfn> in the
property definitions. Lengths refer to horizontal or vertical
measurements. Lengths are numbers with a unit identifier. After the
&lsquo;<code class=css>0</code>&rsquo; length, the unit identifier is
optional.
<p>Some properties allow negative length values, but this may complicate
the formatting and there may be implementation-specific limits. If a
negative length value is allowed but cannot be supported, it should be
converted to the nearest value that can be supported.
<p>There are several types of length units. <dfn
id=relative-length-units0>Relative length units</dfn> specify a length
relative to other lengths, while <dfn id=absolute-length-units>absolute
length units</dfn> express fixed lengths.
<h4 id=absolute-length-units-cm-mm.-in-pt-pc><span class=secno>6.3.1
</span>Absolute length units: cm, mm. in, pt, pc</h4>
<p>Absolute length units are useful when the physical properties of the
output medium are known. The absolute units are:
<table>
<tbody>
<tr>
<th>unit
<th>definition
<tr>
<td><span class=css>cm</span>
<td>centimeters
<tr>
<td><span class=css>mm</span>
<td>millimeters
<tr>
<td><span class=css>in</span>
<td>inches; 1 inch is equal to 2.54 centimeters.
<tr>
<td><span class=css>pt</span>
<td>points; 1pt is equal to 1/72 inch.
<tr>
<td><span class=css>pc</span>
<td>picas; 1 pica is equal to 12 points.
</table>
<div class=example>
<pre>
h1 { margin: 0.5in } /* inches */
h2 { line-height: 3cm } /* centimeters */
h3 { word-spacing: 4mm } /* millimeters */
h4 { font-size: 12pt } /* points */
h4 { font-size: 1pc } /* picas */</pre>
</div>
<p>In cases where the specified length cannot be supported, user agents
must approximate it in the actual value.
<h4 id=relative-length-units><span class=secno>6.3.2 </span>Relative length
units</h4>
<p>Relative units are:
<table>
<tbody>
<tr>
<th& 133E gt;unit
<th>relative to
<tr>
<td><span class=css>em</span>
<td>the font size of the element (or, to the parent element's font size
if set on the <span class=property>&lsquo;<code
class=property>font-size</code>&rsquo;</span> property)
<tr>
<td><span class=css>ex</span>
<td>the <em><a href="#ex">x-height</a></em> of the element's font
<tr>
<td><span class=css>px</span>
<td>viewing device
<tr>
<td><span class=css>rem</span>
<td>the font size of the root element
<tr>
<td><span class=css>vw</span>
<td>the viewport's width
<tr>
<td><span class=css>vh</span>
<td>the viewport's height
<tr>
<td><span class=css>vm</span>
<td>the viewport's height or width, whichever is smaller of the two
<tr>
<td><span class=css>ch<span></span></span>
<td>The width of the "0" (ZERO, U+0030) glyph found in the font for the
font size used to render. If the "0" glyph is not found in the font,
the average character width may be used. <span class=issue>How is the
"average character width" found?</span>
</table>
<h5 id=the-em-unit><span class=secno>6.3.2.1. </span>The &lsquo;<code
class=property>em</code>&rsquo; unit</h5>
<p>The <dfn id=em title="em (unit)">em</dfn> unit is equal to the computed
value of the &lsquo;<code class=property>font-size</code>&rsquo; property
of the element on which it is used. The exception is when "em" occurs in
the value of the &lsquo;<code class=property>font-size</code>&rsquo;
property itself, in which case it refers to the font size of the parent
element.
<p>When specified on the &lsquo;<code
class=property>font-size</code>&rsquo; property of the root element, the
&lsquo;<code class=css>em</code>&rsquo; units refer to the property's
<em>initial value</em>.
<p>The rule:
<pre class=example>
h1 { line-height: 1.2em }
</pre>
<p>means that the line height of <code>h1</code> elements will be 20%
greater than the font size of the elements. On the other hand:
<pre class=example>
h1 { font-size: 1.2em }
</pre>
<p>means that the font size of <code>h1</code> elements will be 20% greater
than the font size inherited by <code>h1</code> elements.
<div class=example>
<pre>
h1 { margin: 0.5em } /* em */
h1 { margin: 1ex } /* ex */
p { font-size: 12px } /* px */
</pre>
</div>
<h5 id=the-ex-unit><span class=secno>6.3.2.2. </span>The &lsquo;<code
class=property>ex</code>&rsquo; unit</h5>
<p>The <dfn id=ex title="x-height|ex (unit)">ex</dfn> unit is defined by
the font's x-height. The x-height is so called because it is often equal
to the height of the lowercase "x". However, an &lsquo;<code
class=css>ex</code>&rsquo; is defined even for fonts that do not contain
an "x". <span class=issue>Should we say that ex is 0.5em if no better
value exists?</span>
<p>When specified on the &lsquo;<code
class=property>font-size</code>&rsquo; property of the root element, the
&lsquo;<code class=css>ex</code>&rsquo; units refer to the property's
<em>initial value</em>.
<h5 id=the-px-unit><span class=secno>6.3.2.3. </span>The &lsquo;<code
class=property>px</code>&rsquo; unit</h5>
<p>The pixel unit, <dfn id=px title="pixel unit|px (pixel)">px</dfn> is
relative to the resolution of the viewing device. For example, the viewing
device can be a computer display or a printer. Normally, the pixel unit
refers to physical pixels of the viewing device. However, if the pixel
density of the output device is very different from that of a typical
computer display, the user agent should rescale pixel values. It is
recommended that the <dfn id=reference-pixel>reference pixel</dfn> be the
visual angle of one pixel on a device with a 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.
<p>For reading at arm's length, 1px thus corresponds to about 0.26mm
(1/96&nbsp;inch). When printed on a laser printer, meant for reading at a
little less than arm's length (55&nbsp;cm, 21&nbsp;inches), 1px is about
0.21mm. On a 300 dots-per-inch (dpi) printer, that may be rounded up to 3
dots (0.25&nbsp;mm); on a 600&nbsp;dpi printer, it can be rounded to 5
dots.
<p>The two images below illustrate the effect of viewing distance on the
size of a pixel and the effect of a device's resolution. In the first
image, a reading distance of 71cm (28&nbsp;inch) results in a px of
0.26mm, while a reading distance of 3.5m (12&nbsp;feet) requires a px of
1.3mm.
<div class=figure>
<p><img alt="Showing that pixels must become larger if the viewing
distance increases" src=pixel1></p>
</div>
<p>In the second image, an area of 1px by 1px is covered by a single dot in
a low-resolution device (a computer screen), while the same area is
covered by 16 dots in a higher resolution device (such as a 400&nbsp;dpi
laser printer).
<div class=figure>
<p><img alt="Showing that more device pixels (dots) are needed to cover a
1px by 1px area on a high-resolution device than on a low-res one"
src=pixel2></p>
</div>
<h5 id=the-rem-unit><span class=secno>6.3.2.4. </span>The &lsquo;<code
class=property>rem</code>&rsquo; unit</h5>
<p>The <dfn id=rem title="root em|rem (unit)">rem</dfn> unit ("root em") is
relative to the computed value of &lsquo;<code
class=property>font-size</code>&rsquo; on the root element.
<p>When specified on the &lsquo;<code
class=property>font-size</code>&rsquo; property of the root element, the
&lsquo;<code class=css>rem</code>&rsquo; units refer to the property's
<em>initial value</em>.
<h5 id=the-vw-unit><span class=secno>6.3.2.5. </span>The &lsquo;<code
class=property>vw</code>&rsquo; unit</h5>
<p>The <dfn id=vw title="vw (unit)">vw</dfn> unit is relative to the
viewport's width. The viewport's width is equal to 100 &lsquo;<code
class=property>vw</code>&rsquo; units.
<div class=example>
<p style=display:none>Example:
<pre>
h1 { font-size: 8vw }
</pre>
</div>
<p>If the width of the viewport is 200mm, the font size of <code
class=html>h1</code> elements will be 16mm ((8&times;200)/100). When the
width of the viewport is changed (for example, when the browser window is
enlarged), lengths specifed in the &lsquo;<code
class=property>vh</code>&rsquo; unit is scaled propertionally.
<h5 id=the-vh-unit><span class=secno>6.3.2.6. </span>The &lsquo;<code
class=property>vh</code>&rsquo; unit</h5>
<p>The <dfn id=vh title="vh (unit)">vh</dfn> unit is relative to the
viewport's height. The viewport's width is equal to 100 &lsquo;<code
class=property>vh</code>&rsquo; units. When the height of the viewport is
changed (for example, when the browser window is enlarged), lengths
specifed in the &lsquo;<code class=property>vh</code>&rsquo; unit are
scaled proportionally.
<h5 id=the-vm-unit><span class=secno>6.3.2.7. </span>The &lsquo;<code
class=property>vm</code>&rsquo; unit</h5>
<p>The <dfn id=vm title="vm (unit)">vm</dfn> unit is relative to the
viewport's height or width, whichever of the two is smaller. The minimum
of the viewport's width/height is equivalent to 100 &lsquo;<code
class=css>vm</code>&rsquo; units. When the height or width of the viewport
is changed, lengths specified in the &lsquo;<code
class=property>vm</code>&rsquo; unit are scaled proportionally.
<h4 id=the-calc-function><span class=secno>6.3.3 </span>The &lsquo;<code
class=property>calc</code>&rsquo; function</h4>
<p>The <dfn id=calcltexpressiongt>calc(&lt;expression&gt;)</dfn> function
can be used wherever length values are allowed, with the syntax given
below. <!--
The expression within the parethesis is computed at the same time as &lsquo;<code class=property>em</code>&rsquo; lengths are
computed
-->
<div class=example>
<pre>
section {
float: left;
margin: 1em; border: solid 1px;
width: calc(100%/3 - 2*1em - 2*1px);
}
</pre>
</div>
<div class=example>
<pre>
p {
margin: calc(1rem - 2px) calc(1rem - 1px);
border: solid transparent; border-width: 2px 1px;
}
</pre>
</div>
<p>The simple expression language of the &lsquo;<code
class=css>calc()</code>&rsquo; function supports five arithmetic operators
(+ and - have lowest precedence, *, /, and &lsquo;<code
class=property>mod</code>&rsquo; have highest precedence) and parentheses.
<p>A value is ignored if a division by zero or other mathemathical errors
occur in the calculation.
<div class=example>
<p>In this example, the second declaration will be ignored due to a
division by zero.
<pre>
p {
margin: 1em;
margin: calc(1em-2px) calc(1em/0)
}
</pre>
</div>
<p class=issue>Issue: At a later date new operators such as min/max,
conditionals, new constants, division by length units etc. may be added.
<p>The expression language is defined by &lsquo;<code
class=property>length-expression</code>&rsquo; below:
<pre>
&lt;length> := calc( &lt;length-expression> ) | &lt;atomic-length>
&lt;length-expression> := &lt;length-additive-expression>
&lt;length-additive-expression> :=
&lt;length-multiplicative-expression> |
&lt;length-additive-expression> S* &lsquo;<code class=css>+</code>&rsquo; S* &lt;length-multiplicative-expression> |
&lt;length-additive-expression> S* &lsquo;<code class=property>-</code>&rsquo; S* &lt;length-multiplicative-expression>
&lt;length-multiplicative-expression>
&lt;length-term> |
&lt;length-multiplicative-expression> S* &lsquo;<code class=css>*</code>&rsquo; S* &lt;number-term> |
&lt;number-multiplicative-expression> S* &lsquo;<code class=css>*</code>&rsquo; S* &lt;length-term> |
&lt;length-multiplicative-expression> S* &lsquo;<code class=css>/</code>&rsquo; S* &lt;number-term> |
&lt;length-multiplicative-expression> S* &lsquo;<code class=property>mod</code>&rsquo; S* &lt;number-term>
&lt;length-term> := &lsquo;<code class=css>(</code>&rsquo; &lt;length-expression> &lsquo;<code class=css>)</code>&rsquo; | &a 6D50 mp;lt;atomic-length>
&lt;number-additive-expression> :=
&lt;number-multiplicative-expression> |
&lt;number-additive-expression> S* &lsquo;<code class=css>+</code>&rsquo; S* &lt;number-multiplicative-expression> |
&lt;number-additive-expression> S* &lsquo;<code class=property>-</code>&rsquo; S* &lt;number-multiplicative-expression>
&lt;number-multiplicative-expression> :=
&lt;number-term> |
&lt;length-multiplicative-expression> S* &lsquo;<code class=css>/</code>&rsquo; S* &lt;length-term> |
&lt;length-multiplicative-expression> S* &lsquo;<code class=property>mod</code>&rsquo; S* &lt;length-term>
&lt;number-term> := &lsquo;<code class=css>(</code>&rsquo; &lt;number-additive-expression> &lsquo;<code class=css>)</code>&rsquo; | &lt;number>
&lt;atomic-length> := &lt;number>&lt;length-unit>
</pre>
<div class=note>Note that &lsquo;<code class=property>mod</code>&rsquo; is
used instead of &lsquo;<code class=css>%</code>&rsquo; for modulus since
it is very easy to get confused about whether &lsquo;<code
class=css>%</code>&rsquo; is acting as a unit or an operator. At least
with &lsquo;<code class=property>mod</code>&rsquo; it always causes a
parse error &mdash; invalid unit &mdash; in the otherwise ambiguous cases.
</div>
<h3 id=ltstringgt><span class=secno>6.4 </span>&lt;string&gt;</h3>
<p>Strings are denoted by <dfn id=ltstringgt0>&lt;string&gt;</dfn> in the
value definitions.
<h3 id=ltcolorgt><span class=secno>6.5 </span>&lt;color&gt;</h3>
<p><em>This section is not normative. The CSS3 Color module <a
href="#CSS3COLOR" rel=biblioentry>[CSS3COLOR]<!--{{!CSS3COLOR}}--></a>
defines the CSS3 color values. </em>
<p>Color values are denoted by <dfn id=ltcolorgt0>&lt;color&gt;</dfn> in
the value definitions.
<p>A <dfn id=color>color</dfn> value can either be a keyword, a numerical
specification in a functional notation, or a numerical RGB specification
in a hexadecimal notation. The hexadecimal notation is special shorthand
format that allows compact color descriptions.
<div class=example>
<pre>
em { color: #F00 }
span.issue { color: red }
* { color: hsl(120, 75%, 75%) }
</pre>
</div>
<h3 id=ltpercentagegt-><span class=secno>6.6 </span>&lt;percentage&gt;</h3>
<p>The format of a percentage value, denoted by <dfn id=ltpercentagegt
title="&lt;percentage&gt;::definition of">&lt;percentage&gt;</dfn>, is a
<a class=index href="#ltnumbergt0" id=ltnumbergt1>&lt;number&gt;</a>
immediately followed by &lsquo;<code class=css>%</code>&rsquo;.
<p>Percentage values are always relative to another value, for example a
length. Each property that allows percentages also defines the value to
which the percentage refers. The value may be that of another property for
the same element, a property for an ancestor element, or a value of the
formatting context (e.g., the width of a <em>containing block</em>). When
a percentage value is set for a property of the <em>root</em> element and
the percentage is defined as referring to the inherited value of some
property, the resultant value is the percentage times the <em>initial
value</em> of that property.
<div class=example>
<p style=display:none>Example(s):</p>
<p>Since child elements (generally) inherit the <em>computed values</em>
of their parent, in the following example, the children of the P element
will inherit a value of 12pt for <span class=property>&lsquo;<code
class=property>line-height</code>&rsquo;</span>, not the percentage value
(120%):</p>
<pre>
p { font-size: 10pt }
p { line-height: 120% } /* 120% of &lsquo;<code class=property>font-size</code>&rsquo; */
</pre>
</div>
<p class=issue>Do we need a "non-negative percentage", e.g. for
"font-size"?
<h3 id=ltanglegt-><span class=secno>6.7 </span>&lt;angle&gt;</h3>
<p>Angle values (denoted by <dfn id=ltanglegt
title="&lt;angle&gt;::definition of">&lt;angle&gt;</dfn> in the text) are
used with aural cascading style sheets.
<p>Their format is a <a class=index href="#ltnumbergt0"
id=ltnumbergt2>&lt;number&gt;</a> immediately followed by an angle unit
identifier.
<p>Angle unit identifiers are:
<ul>
<li><dfn id=deg title="deg (degrees)">deg</dfn>: degrees
<li><dfn id=grad title="grad (grads)">grad</dfn>: grads
<li><dfn id=rad title="rad (radians)">rad</dfn>: radians
<li><dfn id=turn title=turn>turn</dfn>: turns
</ul>
<p>Angle values should be normalized to the range 0-360deg by the user
agent. For example, -10deg and 350deg are equivalent.
<p>For example, a right angle is &lsquo;<code class=css>90deg</code>&rsquo;
or &lsquo;<code class=css>100grad</code>&rsquo; or &lsquo;<code
class=css>1.570796326794897rad</code>&rsquo;.
<h3 id=lttimegt><span class=secno>6.8 </span>&lt;time&gt;</h3>