8000 csswg-drafts/css2/syndata.src at 161dfab53fe20d5b0c3a774617de908e98115b64 · w3c/csswg-drafts · GitHub
Skip to content

Latest commit

 

History

History
1132 lines (941 loc) · 43.5 KB

File metadata and controls

1132 lines (941 loc) · 43.5 KB
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/1998/REC-html40-19980424/loose.dtd">
<html lang="en">
<!-- $Id: syndata.src,v 2.74 2002-07-31 19:24:52 bbos Exp $ -->
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<TITLE>CSS&nbsp;2.1 syntax and basic data types</TITLE>
<style type="text/css">
span.colorsquare { float:left; width:5em; height:3em; text-align:center; padding:1.2em 0 .8em }
span.colorname { font-weight:bold }
div.colordiagram { width:25em; height:20em; margin:1em auto; font-family:Verdana,sans-serif; font-size:12px }
div.diagramrow { height:5em }
</style>
<!-- Changed by: Tantek Celik, 2002-06-13 -->
</HEAD>
<BODY>
<H1 align="center">CSS&nbsp;2.1 syntax and basic data types</H1>
<H2><a name="syntax">Syntax</a></H2>
<P>This section describes a grammar (and <span class="index-def"
title="forward-compatible parsing"><dfn>forward-compatible
parsing</dfn></span> rules) common to any version of CSS (including
CSS&nbsp;2.1). Future versions of CSS will adhere to this core syntax,
although they may add additional syntactic constraints.
<P>These descriptions are normative. They are also
complemented by the normative grammar rules presented in <a
href="grammar.html">Appendix D</a>.
<H3><a name="tokenization">Tokenization</a></H3>
<P>All levels of CSS -- level 1, level 2, and any future levels -- use
the same core syntax. This allows UAs to parse (though not completely
understand) style sheets written in levels of CSS that didn't exist at
the time the UAs were created. Designers can use this feature to
create style sheets that work with older user agents, while also
exercising the possibilities of the latest levels of CSS.
<P>At the lexical level, CSS style sheets consist of a sequence of tokens.
The list of tokens for CSS&nbsp;2.1 is as follows. The definitions use Lex-style
regular expressions. Octal codes refer to ISO 10646 ([[ISO10646]]). As in
Lex, in case of multiple matches, the longest match determines the token.
<TABLE>
<THEAD>
<TR><TH>Token <TH>Definition
</THEAD>
<TR><TD colspan=2><HR>
<TR><TD>IDENT <TD><code><var>{ident}</var></code>
<TR><TD>ATKEYWORD <TD><code>@<var>{ident}</var></code>
<TR><TD>STRING <TD><code><var>{string}</var></code>
<TR><TD>HASH <TD><code>#<var>{name}</var></code>
<TR><TD>NUMBER <TD><code><var>{num}</var></code>
<TR><TD>PERCENTAGE <TD><code><var>{num}</var>%</code>
<TR><TD>DIMENSION <TD><code><var>{num}{ident}</var></code>
<TR><TD>URI <TD><code>url\(<var>{w}{string}{w}</var>\)<br>
|url\(<var>{w}</var>([!#$%&amp;*-~]|<var>{nonascii}</var>|<var>{escape}</var>)*<var>{w}</var>\)</code>
<TR><TD>UNICODE-RANGE <TD><code>U\+[0-9A-F?]{1,6}(-[0-9A-F]{1,6})?</code>
<TR><TD>CDO <TD><code>&lt;!--</code>
<TR><TD>CDC <TD><code>--&gt;</code>
<TR><TD>; <TD><code>;</code>
<TR><TD>{ <TD><code>\{</code>
<TR><TD>} <TD><code>\}</code>
<TR><TD>( <TD><code>\(</code>
<TR><TD>) <TD><code>\)</code>
<TR><TD>[ <TD><code>\[</code>
<TR><TD>] <TD><code>\]</code>
<TR><TD>S <TD><code>[ \t\r\n\f]+</code>
<TR><TD>COMMENT <TD><code>\/\*[^*]*\*+([^/][^*]*\*+)*\/</code>
<TR><TD>FUNCTION <TD><code><var>{ident}</var>\(</code>
<TR><TD>INCLUDES <TD><code>~=</code>
<TR><TD>DASHMATCH <TD><code>|=</code>
<TR><TD>DELIM <TD><var>any other character not matched by
the above rules, and neither a single nor a double quote</var>
</TABLE>
<P>The macros in curly braces ({}) above are defined as follows:
<TABLE>
<THEAD>
<TR><TH>Macro <TH>Definition
</THEAD>
<TR><TD colspan=2><HR>
<TR><TD>ident <TD><code><var>{nmstart}{nmchar}*</var></code>
<TR><TD>name <TD><code><var>{nmchar}+</var></code>
<TR><TD>nmstart <TD><code>[_a-zA-Z]|<var>{nonascii}</var>|<var>{escape}</var></code>
<TR><TD>nonascii<TD><code>[^\0-\177]</code>
<TR><TD>unicode <TD><code>\\[0-9a-f]{1,6}[ \n\r\t\f]?</code>
<TR><TD>escape <TD><code><var>{unicode}</var>|\\[ -~\200-\4177777]</code>
<TR><TD>nmchar <TD><code>[_a-zA-Z0-9-]|<var>{nonascii}</var>|<var>{escape}</var></code>
<TR><TD>num <TD><code>[0-9]+|[0-9]*\.[0-9]+</code>
<TR><TD>string <TD><code><var>{string1}</var>|<var>{string2}</var></code>
<TR><TD>string1 <TD><code>\"([\t !#$%&amp;(-~]|\\{nl}|\'|<var>{nonascii}</var>|<var>{escape}</var>)*\"</code>
<TR><TD>string2 <TD><code>\'([\t !#$%&amp;(-~]|\\{nl}|\"|<var>{nonascii}</var>|<var>{escape}</var>)*\'</code>
<TR><TD>nl <TD><code>\n|\r\n|\r|\f</code>
<TR><TD>w <TD><code>[ \t\r\n\f]*</code>
</TABLE>
<P>Below is the core syntax for CSS. The sections that follow describe
how to use it. <a href="grammar.html">Appendix D</a> describes a
more restrictive grammar that is closer to the CSS level 2 language.
<PRE>
stylesheet : [ CDO | CDC | S | statement ]*;
statement : ruleset | at-rule;
at-rule : ATKEYWORD S* any* [ block | ';' S* ];
block : '{' S* [ any | block | ATKEYWORD S* | ';' ]* '}' S*;
ruleset : selector? '{' S* declaration? [ ';' S* declaration? ]* '}' S*;
selector : any+;
declaration : property ':' S* value;
property : IDENT S*;
value : [ any | block | ATKEYWORD S* ]+;
any : [ IDENT | NUMBER | PERCENTAGE | DIMENSION | STRING
| DELIM | URI | HASH | UNICODE-RANGE | INCLUDES
| FUNCTION any* ')' | DASHMATCH | '(' any* ')' | '[' any* ']' ] S*;
</PRE>
<P><a name="comment">COMMENT</a> tokens do not occur
in the grammar (to keep it readable), but any number of these tokens
may appear anywhere between other tokens.
<p>The token S in the grammar above stands for <A
name="whitespace">whitespace</a>. Only the characters "space" (Unicode
code 32), "tab" (9), "line feed" (10), "carriage return" (13), and
"form feed" (12) can occur in whitespace. Other space-like characters,
such as "em-space" (8195) and "ideographic space" (12288), are never
part of whitespace.
<H3><a name="keywords">Keywords</a></H3>
<!-- provide better explanation of where keywords appear:
media types, at-rules, etc. -IJ -->
<P>Keywords have the form of identifiers. Keywords must not be placed
between quotes ("..." or '...'). Thus,
<pre>
red
</pre>
<p>is a keyword, but
<pre>
"red"
</pre>
is not. (It is a <a href="#strings">string</a>.) Other illegal examples:
<div class="illegal-example"><P>
<pre>
width: "auto";
border: "none";
font-family: "serif";
background: "red";
</pre>
</div>
<H3>Characters and case</H3>
<P> The following rules always hold:</p>
<UL>
<LI> All CSS style sheets are <span class="index-inst" title="case
sensitivity">case-insensitive</span>, except for parts that are
not under the control of CSS. For example, the case-sensitivity of
values of the HTML attributes "id" and "class", of font names, and
of URIs lies outside the scope of this specification. Note in
particular that element names are case-insensitive in HTML, but
case-sensitive in XML.
<LI> In CSS&nbsp;2.1, <span class="index-def"
title="identifier|identifier, definition of"><a
name="value-def-identifier"><dfn>identifiers</dfn></a></span>
(including element names, classes, and IDs in <a
href="selector.html">selectors</a>) can contain only the
characters [A-Za-z0-9] and ISO 10646 characters 161 and higher,
plus the hyphen (-) and the underscore (_); they cannot start with a hyphen or a
digit. They can also contain escaped characters and any ISO 10646
character as a numeric code (see next item).
<span class="example">For instance, the identifier "B&amp;W?" may
be written as "B\&amp;W\?" or "B\26 W\3F".</span>
<P>Note that Unicode is code-by-code equivalent to ISO 10646 (see
[[UNICODE]] and [[ISO10646]]).
<LI> In CSS&nbsp;2.1, a backslash (\) character indicates three types of
<span class="index-def" title="backslash escapes">
<a name="escaped-characters">character escapes</a></span>.
<P>First, inside a <a href="#strings">string</a>, a backslash
followed by a newline is ignored (i.e., the string is deemed not
to contain either the backslash or the newline).
<P>Second, it cancels the meaning of special CSS characters.
Any character (except a hexadecimal digit) can be escaped
with a backslash to remove its special meaning.
For example, <samp>"\""</samp> is a string consisting of one
double quote. Style sheet preprocessors must not remove
these backslashes from a style sheet since that would
change the style sheet's meaning.
<P>Third, backslash escapes allow authors to refer to characters
they can't easily put in a document. In this case, the backslash
is followed by at most six hexadecimal digits (0..9A..F), which
stand for the ISO 10646 ([[ISO10646]]) character with
that number. If a digit or letter follows the hexadecimal number,
the end of the number needs to be made clear. There are two ways
to do that:
<ol>
<li>with a space (or other whitespace character): "\26 B" ("&amp;B").
In this case, user agents should treat a "CR/LF" pair
(13/10) as a single
whitespace character.
<li>by providing exactly 6 hexadecimal digits: "\000026B" ("&amp;B")
</ol>
<p>In fact, these two methods may be combined. Only one whitespace
character is ignored after a hexadecimal escape. Note that this means
that a "real" space after the escape sequence must itself either be
escaped or doubled.
<LI>Backslash escapes are always considered to be part of an <a
href="#value-def-identifier">identifier</a> or a string (i.e.,
"\7B" is not punctuation, even though "{" is, and "\32" is allowed
at the start of a class name, even though "2" is not).
</UL>
<H3>Statements</H3>
<P> A CSS style sheet, for any version of CSS, consists of a list of
<span class="index-inst" title="statements"><em>statements</em></span>
(see the grammar above). There are two kinds of statements: <span
class="index-inst" title="at-rules"><em>at-rules</em></span>
and <span class="index-inst" title="rule sets"><em>rule
sets.</em></span> There may be <a href="#whitespace">whitespace</a>
around the statements.
<P>In this specification, the expressions "immediately before" or
"immediately after" mean with no intervening whitespace or comments.
<!-- Should comments be defined as whitespace? -->
<H3><span class="index-def" title="at-rule">
<a name="at-rules">At-rules</a></span></H3>
<P> At-rules start with an <DFN>at-keyword</DFN>, an '@' character
followed immediately by an <a
href="#value-def-identifier">identifier</a> (for example, '@import',
'@page').
<P> An at-rule consists of everything up to and including the next
semicolon (;) or the next <a href="#block">block,</a> whichever comes
first. A CSS user agent that encounters an unrecognized at-rule must
<span class="index-inst" title="ignore"><a href="#ignore">ignore</a></span>
the whole of the at-rule and continue parsing after it.
<P>CSS&nbsp;2.1 user agents must <span class="index-inst" title="ignore"><a
href="#ignore">ignore</a></span> any <a
href="cascade.html#at-import">'@import'</a> rule that occurs inside a <a
href="#block">block</a> or that doesn't precede all rule sets.
<div class="illegal-example"><P>
Assume, for example, that a CSS&nbsp;2.1 parser encounters this style sheet:
<PRE>
@import "subs.css";
h1 { color: blue }
@import "list.css";
</PRE>
<P> The second '@import' is illegal according to CSS2. The CSS&nbsp;2.1 parser
<span class="index-inst" title="ignore"><a href="#ignore">ignores</a></span>
the whole at-rule, effectively reducing the style sheet to:
<PRE>
@import "subs.css";
h1 { color: blue }
</PRE>
</div>
<div class="illegal-example"><P>
In the following example, the second '@import' rule is invalid,
since it occurs inside a '@media' <a href="#block">block</a>.
<PRE>
@import "subs.css";
@media print {
@import "print-main.css";
body { font-size: 10pt }
}
h1 {color: blue }
</PRE>
</div>
<H3><a name="block">Blocks</a></H3>
<P> A <span class="index-inst" title="block"><em>block</em></span>
starts with a left curly brace ({) and ends with the matching right
curly brace (}). In between there may be any characters, except that
parentheses ((&nbsp;)), brackets ([&nbsp;]) and braces ({&nbsp;}) must
always occur in
matching pairs and may be nested. Single (') and double quotes (")
<!-- " --> must also occur in matching pairs, and characters between them
are parsed as a <span class="index-inst" title="string">string</span>.
See <a href="#tokenization">Tokenization</a> above for the definition
of a string.
<div class="illegal-example">
<P> Here is an example of a block. Note that the right brace between
the double quotes does not match the opening brace of the block, and that the
second single quote is an <a href="#escaped-characters">escaped
character</a>, and thus doesn't match the first single quote:
<PRE>
{ causta: "}" + ({7} * '\'') }
</PRE>
<P>Note that the above rule is not valid CSS&nbsp;2.1, but it is still
a block as defined above.
</div>
<H3>Rule sets, declaration blocks, and selectors</H3>
<P> A rule set (also called "rule") consists of a selector followed by
a declaration block.
<P> A <span class="index-def"
title="declaration-block"><dfn>declaration-block</dfn></span> (also
called a {}-block in the following text) starts with a left curly
brace ({) and ends with the matching right curly brace (}). In between
there must be a list of zero or more semicolon-separated (;)
declarations.
<P>The <span class="index-def"
title="selector"><em>selector</em></span> (see also the section on <a
href="selector.html">selectors</a>) consists of everything up to (but
not including) the first left curly brace ({). A selector always goes
together with a {}-block. When a user agent can't parse the selector (i.e., it
is not valid CSS&nbsp;2.1), it must <span class="index-inst" title="ignore"><a
href="#ignore">ignore</a></span> the {}-block as well.
<P>CSS&nbsp;2.1 gives a special meaning to the comma (,) in
selectors. However, since it is not known if the comma may acquire
other meanings in future versions of CSS, the whole statement should
be <span class="index-inst" title="ignore"><a
href="#ignore">ignored</a></span> if there is an error anywhere in the
selector, even though the rest of the selector may look reasonable in
CSS&nbsp;2.1.
<DIV class=illegal-example>
<P>For example, since the "&amp;" is not a valid token in a CSS&nbsp;2.1
selector, a CSS&nbsp;2.1 user agent must
<span class="index-inst" title="ignore"><a href="#ignore">ignore</a></span>
the whole second line, and not set the color of H3 to red:
<PRE>
h1, h2 {color: green }
h3, h4 &amp; h5 {color: red }
h6 {color: black }
</PRE>
</DIV>
<div class="example"><P>
<P>Here is a more complex example. The first two pairs of curly braces
are inside a string, and do not mark the end of the selector. This is
a valid CSS&nbsp;2.1 statement.
<PRE>
p[example="public class foo\
{\
private int x;\
\
foo(int x) {\
this.x = x;\
}\
\
}"] { color: red }
</PRE>
</div>
<H3><a name="declaration">Declarations</a> and <a
name="properties">properties</a></H3>
<P> A <span class="index-def"
title="declaration"><dfn>declaration</dfn></span> is either empty or
< 13C5 div id="LC385" class="react-file-line html-div" data-testid="code-cell" data-line-number="385" style="position:relative">consists of a <span class="index-inst"
title="property">property</span>, followed by a colon (:), followed by
a value. Around each of these there may be <a
href="#whitespace">whitespace</a>.
<p>Because of the way selectors work, multiple declarations for the
same selector may be organized into semicolon (;) separated
groups.</p>
<div class="example"><p>
Thus, the following rules:</p>
<pre>
h1 { font-weight: bold }
h1 { font-size: 12px }
h1 { line-height: 14px }
h1 { font-family: Helvetica }
h1 { font-variant: normal }
h1 { font-style: normal }
</pre>
<p>are equivalent to:</p>
<pre>
h1 {
font-weight: bold;
font-size: 12px;
line-height: 14px;
font-family: Helvetica;
font-variant: normal;
font-style: normal
}
</pre>
</div>
<P>A property is an <a
href="#value-def-identifier">identifier</a>. Any character may occur
in the value, but parentheses ("(&nbsp;)"), brackets ("[&nbsp;]"),
braces ("{&nbsp;}"), single
quotes (') and double quotes (") <!-- " --> must come in matching
pairs, and semicolons not in strings must be <a
href="#escaped-characters">escaped</a>. Parentheses, brackets, and
braces may be nested. Inside the quotes, characters are parsed as a
string.
<P>The syntax of <span class="index-def" title="value">values</span>
is specified separately for each property, but in any case, values are
built from identifiers, strings, numbers, lengths, percentages, URIs,
colors, angles, times, and frequencies.
<P>A user agent must <span class="index-inst" title="ignore"><a
href="#ignore">ignore</a></span> a declaration with an invalid property
name or an invalid value. Every CSS&nbsp;2.1 property has its own syntactic
and semantic restrictions on the values it accepts.
<div class="illegal-example"><P>
For example, assume a CSS&nbsp;2.1 parser encounters this style sheet:
<PRE>
h1 { color: red; font-style: 12pt } /* Invalid value: 12pt */
p { color: blue; font-vendor: any; /* Invalid prop.: font-vendor */
font-variant: small-caps }
em em { font-style: normal }
</PRE>
<P> The second declaration on the first line has an invalid value
'12pt'. The second declaration on the second line contains an
undefined property 'font-vendor'. The CSS&nbsp;2.1 parser will <span
class="index-inst" title="ignore"><a href="#ignore">ignore</a></span> these
declarations, effectively reducing the style sheet to:
<PRE class="example">
h1 { color: red; }
p { color: blue; font-variant: small-caps }
em em { font-style: normal }
</PRE>
</div>
<H3><a name="comments">Comments</a></H3>
<P><span class="index-inst" title="comments">Comments </span> begin
with the characters "/*" and end with the characters "*/". They may
occur anywhere between tokens,
and their contents have no influence on the rendering. Comments may
not be nested.
<P>CSS also allows the SGML comment delimiters ("&lt;!--" and
"--&gt;") in certain places, but they do not delimit CSS
comments. They are permitted so that style rules appearing in an HTML
source document (in the STYLE element) may be hidden from pre-HTML 3.2
user agents. See the HTML 4.0 specification ([[-HTML40]]) for more information.
<H2><a name="parsing-errors">Rules for handling parsing
errors</a></H2>
<P>In some cases, user agents must ignore part of an illegal style
sheet. This specification defines <span class="index-def"
title="ignore"><a name="ignore"><dfn>ignore</dfn></a></span> to mean
that the user agent parses the illegal part (in order to find its
beginning and end), but otherwise acts as if it had not been there.
<!-- How are "beginning" and "end" defined? -IJ -->
<P>To ensure that new properties and new values for existing
properties can be added in the future, user agents are required to
obey the following rules when they encounter the following
scenarios:</p>
<UL>
<LI><strong>Unknown properties.</strong> User agents must <span
class="index-inst" title="ignore"><a href="#ignore">ignore</a></span> a <a
href="syndata.html#declaration">declaration</a> with an unknown
property. For example, if the style sheet is:
<PRE class="illegal-example">
h1 { color: red; rotation: 70minutes }
</PRE>
<P> the user agent will treat this as if the style sheet had been
<PRE class="example">
h1 { color: red }
</PRE>
<LI><strong>Illegal values.</strong> User agents must ignore a
declaration with an illegal value. For example:
<PRE class="illegal-example">
img { float: left } /* correct CSS&nbsp;2.1 */
img { float: left here } /* "here" is not a value of 'float' */
img { background: "red" } /* keywords cannot be quoted in CSS&nbsp;2.1 */
img { border-width: 3 } /* a unit must be specified for length values */
</PRE>
A CSS&nbsp;2.1 parser would honor the first rule and
<span class="index-inst" title="ignore"><a href="#ignore">ignore</a></span>
the rest, as if the style sheet had been:
<PRE class="example">
img { float: left }
img { }
img { }
img { }
</PRE>
<P>A user agent conforming to a future CSS specification may accept one or
more of the other rules as well.</P>
<LI><strong>Invalid at-keywords.</strong> User agents must <span
class="index-inst" title="ignore"><a href="#ignore">ignore</a></span> an
invalid at-keyword together with everything following it, up to and
including the next semicolon (;) or block ({...}), whichever
comes first. For example, consider the following:
<PRE class="illegal-example">
@three-dee {
@background-lighting {
azimuth: 30deg;
elevation: 190deg;
}
h1 { color: red }
}
h1 { color: blue }
</PRE>
<P> The '@three-dee' at-rule is not part of CSS&nbsp;2.1. Therefore, the whole
at-rule (up to, and including, the third right curly brace) is <span
class="index-inst" title="ignore"><a href="#ignore">ignored.</a></span> A
CSS&nbsp;2.1 user agent <span class="index-inst" title="ignore"><a
href="#ignore">ignores</a></span> it, effectively reducing the style sheet
to:</P>
<PRE class="example">
h1 { color: blue }
</PRE>
</UL>
<H2><a name="values">Values</a></H2>
<H3>Integers and real numbers</H3>
<P>Some value types may have integer values (denoted by <span
class="index-def" title="&lt;integer&gt;::definition of"><a
name="value-def-integer" class="value-def">&lt;integer&gt;</a></span>)
or real number values (denoted by <span class="index-def"
title="&lt;number&gt;::definition of"><a name="value-def-number"
class="value-def">&lt;number&gt;</a></span>). Real numbers and
integers are specified in decimal notation only. An &lt;integer&gt;
consists of one or more digits "0" to "9". A &lt;number&gt; can either
be an &lt;integer&gt;, or it can be zero or more digits followed by a
dot (.) followed by one or more digits. Both integers and real numbers
may be preceded by a "-" or "+" to indicate the sign.
<P>Note that many properties that allow an integer or real number as a
value actually restrict the value to some range, often to a
non-negative value.
<H3><A NAME="length-units">Lengths</A></H3>
<P>Lengths refer to horizontal or vertical measurements.
<P> The format of a length value (denoted by <span class="index-def"
title="&lt;length&gt;::definition of"><a name="value-def-length"
class="value-def">&lt;length&gt;</a></span> in this specification) is
a <span
class="value-inst-number">&lt;number&gt;</span> (with or without a
decimal point) immediately followed by a unit identifier (e.g., px,
deg, etc.). After the '0' length, the unit identifier is optional.
<P> Some properties allow negative length values, but this may
complicate the formatting model and there may be
implementation-specific limits. If a negative length value cannot be
supported, it should be converted to the nearest value that can be
supported.
<P><a name="absrel-units">There are two types of length units:
relative and absolute.</a> <span class="index-def" title="relative
units"><em>Relative length</em></span> units specify a length relative
to another length property. Style sheets that use relative units will
more easily scale from one medium to another (e.g., from a computer
display to a laser printer).
<P>Relative units are:
<ul>
<li><strong>em</strong>: the <span class="propinst-font-size">'font-size'</span> of the relevant font
<li><strong>ex</strong>: the <span class="descinst">'x-height'</span> of the relevant font
<li><strong>px</strong>: pixels, relative to the viewing device
</ul>
<div class="example"><P>
<PRE>
h1 { margin: 0.5em } /* em */
h1 { margin: 1ex } /* ex */
p { font-size: 12px } /* px */
</PRE>
</div>
<P>The <span class="index-def" title="em (unit)|quad width"><a
name="em-width">'em'</a></span> unit is equal to the computed value of
the <span class="propinst-font-size">'font-size'</span> property of
the element on which it is used. The exception is when 'em' occurs in
the value of the 'font-size' property itself, in which case it refers
to the font size of the parent element. It may be used for vertical or
horizontal measurement. (This unit is also sometimes called the
quad-width in typographic texts.)
<p>The <span class="index-def" title="x-height|ex (unit)"><a
name="ex">'ex'</a></span> unit is defined by the font's <span
class="descinst-x-height">'x-height'</span>. 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 don't contain an "x".
<div class="example">
<P>The rule:
<PRE>
h1 { line-height: 1.2em }
</PRE>
<P>means that the line height of "h1" elements will be 20% greater
than the font size of the "h1" elements. On the other hand:
<PRE>
h1 { font-size: 1.2em }
</PRE>
<P>means that the font-size of "h1" elements will be 20% greater than
the font size inherited by "h1" elements.
</div>
<P>When specified for the root of the <a href="conform.html#doctree">
document tree</a> (e.g., "HTML" in HTML), 'em' and 'ex' refer to
the property's <a href="cascade.html#initial-value">initial value</a>.
<P><a name="pixel-units">Pixel units</a> are relative to the
resolution of the viewing device, i.e., most often a computer
display. 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 <span class="index-def"
title="reference pixel|pixel"><EM>reference pixel</EM></span> 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.26&nbsp;mm
(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.20&nbsp;mm. 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 71&nbsp;cm (28&nbsp;inch) results
in a px of 0.26&nbsp;mm, while a reading distance of 3.5&nbsp;m
(12&nbsp;feet) requires a px of 1.3&nbsp;mm. </p>
<div class="figure">
<p><img src="images/pixel1.png" alt="Showing that pixels must become
larger if the viewing distance increases"> </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).</p>
<div class="figure">
<P><img
src="images/pixel2.png" 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"></p>
</div>
<P>Child elements do not inherit the relative values specified for
their parent; they (generally) inherit the <a
href="cascade.html#computed-value">computed values</a>.</p>
<div class="example"><P>
In the following rules, the computed <span
class="propinst-text-indent">'text-indent'</span> value of "h1" elements
will be 36px, not 45px, if "h1" is a child of the "body" element.
<PRE>
body {
font-size: 12px;
text-indent: 3em; /* i.e., 36px */
}
h1 { font-size: 15px }
</PRE>
</div>
<P><span class="index-def" title="absolute length"><em> Absolute
length</em></span> units are only useful when the physical properties
of the output medium are known. The absolute units are:
<UL>
<LI><STRONG>in</STRONG>: inches -- 1 inch is equal to 2.54 centimeters.
<LI><STRONG>cm</STRONG>: centimeters
<LI><STRONG>mm</STRONG>: millimeters
<LI><STRONG>pt</STRONG>: points -- the points used by CSS&nbsp;2.1 are equal to 1/72th of an inch.
<LI><STRONG>pc</STRONG>: picas -- 1 pica is equal to 12 points.
</UL>
<div class="example"><P>
<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.
<H3> <A NAME="percentage-units">Percentages</A></H3>
<P> The format of a percentage value (denoted by <span
class="index-def" title="&lt;percentage&gt;::definition of"><a
name="value-def-percentage"
class="value-def">&lt;percentage&gt;</a></span> in this specification)
is a <span class="index-inst"
title="&lt;number&gt;"><span
class="value-inst-number">&lt;number&gt;</span></span> immediately
followed by '%'.
<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 <a
href="visuren.html#containing-block">containing block</a>). When a
percentage value is set for a property of the <a
href="conform.html#root">root</a> element and the percentage is
defined as referring to the inherited value of some property, the
resultant value is the percentage times the <a
href="cascade.html#initial-value">initial value</a> of that property.
<div class="example"><P>
Since child elements (generally) inherit the <a
href="cascade.html#computed-value">computed values</a> of their parent, in
the following example, the children of the P element will inherit a
value of 12px for <span
class="propinst-line-height">'line-height'</span>, not the percentage
value (120%):
<PRE>
p { font-size: 10px }
p { line-height: 120% } /* 120% of 'font-size' */
</PRE>
</div>
<H3><A NAME="uri">URL + URN = URI</A></H3>
<P><span class="index-def" title="Uniform Resource Locator (URL)|URL
(Uniform Resource Locator)">URLs</span> (Uniform Resource Locators,
see [[RFC1738]] and [[RFC1808]]) provide the address of a resource on
the Web. An expected new way of identifying resources is called <span
class="index-def" title="URN (Uniform Resource Name)|Uniform Resource
Name (URN)">URN</span> (Uniform Resource Name). Together they are
called <span class="index-def" title="Resource Identifier (URI)|URI
(Uniform Resource Identifier)">URIs</span> (Uniform Resource
Identifiers, see [[URI]]). This specification uses the term URI.
<P>URI values in this specification are denoted by <span
class="index-def" title="&lt;uri&gt;::definition of"><a
name="value-def-uri" class="value-def">&lt;uri&gt;</a></span>. The
functional notation used to designate URIs in property values is
"url()", as in:
<div class="example"><P>
<PRE>
body { background: url("http://www.bg.com/pinkish.png") }
</PRE>
</div>
<P> The format of a URI value is 'url(' followed by optional <a
href="#whitespace">whitespace</a> followed by an optional single quote
(') or double quote (") character followed by the URI
itself, followed by an optional single quote (') or double quote (")
character followed by optional whitespace followed by
')'. The two quote characters must be the same.
<div class="example"><P>An example without quotes:
<PRE>
li { list-style: url(http://www.redballs.com/redball.png) disc }
</PRE>
</div>
<P> Parentheses, commas, whitespace characters, single quotes (') and
double quotes (") appearing in a URI must be escaped with a
backslash: '\(', '\)', '\,'.
<P>Depending on the type of URI, it might also be possible to write
the above characters as URI-escapes (where "(" = %28, ")" = %29, etc.)
as described in [[URI]].
<P> In order to create modular style sheets that are not dependent on
the absolute location of a resource, authors may use relative URIs.
Relative URIs (as defined in [[RFC1808]]) are resolved to full URIs
using a base URI. RFC&nbsp;1808, section&nbsp;3, defines the normative
algorithm for this process. For CSS style sheets, the base URI is that
of the style sheet, not that of the source document.
<div class="example">
<P>For example, suppose the following rule:</p>
<PRE>
body { background: url("yellow") }
</PRE>
<P>is located in a style sheet designated by the URI:</p>
<PRE>http://www.myorg.org/style/basic.css</PRE>
<P>The background of the source document's BODY will be tiled with
whatever image is described by the resource designated
by the URI
<PRE>http://www.myorg.org/style/yellow</PRE>
</div>
<P>User agents may vary in how they handle URIs that designate
unavailable or inapplicable resources.
<H3><a name="color-units">Colors</a></H3>
A <span class="index-def" title="&lt;color&gt;::definition of"><a
name="value-def-color" class="value-def">&lt;color&gt;</a></span>
is either a keyword or a numerical RGB specification.
<P> The list of keyword color names is: aqua, black, blue, fuchsia,
gray, green, lime, maroon, navy, olive, orange, purple, red, silver, teal,
white, and yellow. These 17 colors have the following values:
</P>
<div class="colordiagram" id="TanteksColorDiagram20020613">
<div class="diagramrow">
<span class="colorsquare" style="background:maroon;color:white"><span class="colorname">maroon</span> #800000
</span><span class="colorsquare" style="background:red"><span class="colorname">red</span> #ff0000
</span><span class="colorsquare" style="background:orange"><span class="colorname">orange</span> #ffA500
</span><span class="colorsquare" style="background:yellow"><span class="colorname">yellow</span> #ffff00
</span><span class="colorsquare" style="background:olive;color:white"><span class="colorname">olive</span> #808000</span>
</div>
<div class="diagramrow">
<span class="colorsquare" style="background:purple;color:white"><span class="colorname">purple</span> #800080</span>
<span class="colorsquare" style="background:fuchsia"><span class="colorname">fuchsia</span> #ff00ff</span>
<span class="colorsquare" style="background:white"><span class="colorname">white</span> #ffffff</span>
<span class="colorsquare" style="background:lime"><span class="colorname">lime</span> #00ff00</span>
<span class="colorsquare" style="background:green;color:white"><span class="colorname">green</span> #008000</span>
</div>
<div class="diagramrow" style="padding:0 2.5em">
<span class="colorsquare" style="background:navy;color:white"><span class="colorname">navy</span> #000080</span>
<span class="colorsquare" style="background:blue"><span class="colorname">blue</span> #0000ff</span>
<span class="colorsquare" style="background:aqua"><span class="colorname">aqua</span> #00ffff</span>
<span class="colorsquare" style="background:teal;color:white"><span class="colorname">teal</span> #008080</span>
</div>
<div class="diagramrow" style="padding:0 5em">
<span class="colorsquare" style="background:black;color:white"><span class="colorname">black</span> #000000</span>
<span class="colorsquare" style="background:silver"><span class="colorname">silver</span> #c0c0c0</span>
<span class="colorsquare" style="background:gray;color:white"><span class="colorname">gray</span> #808080</span>
</div>
</div>
<P>
In addition to these color keywords, users may specify
keywords that correspond to the colors used by certain objects in the
user's environment. Please consult the section on <a
href="./ui.html#system-colors">system colors</a> for more information.
</P>
<div class="example"><P>
<PRE>
body {color: black; background: white }
h1 { color: maroon }
h2 { color: olive }
</PRE>
</div>
<P>The RGB color model is used in numerical color
specifications. These examples all specify the same color:
<div class="example"><P>
<PRE>
em { color: #f00 } /* #rgb */
em { color: #ff0000 } /* #rrggbb */
em { color: rgb(255,0,0) }
em { color: rgb(100%, 0%, 0%) }
</PRE>
</div>
<P> The format of an RGB value in hexadecimal notation is a '#'
immediately followed by either three or six hexadecimal
characters. The three-digit RGB notation (#rgb) is converted into
six-digit form (#rrggbb) by replicating digits, not by adding
zeros. For example, #fb0 expands to #ffbb00. This ensures that
white (#ffffff) can be specified with the short notation (#fff) and
removes any dependencies on the color depth of the display.
<P> The format of an RGB value in the functional notation is 'rgb('
followed by a comma-separated list of three numerical values (either
three integer values or three percentage values) followed by ')'.
The integer value 255 corresponds to 100%, and to F or FF in the
hexadecimal notation: rgb(255,255,255) = rgb(100%,100%,100%) =
#FFF. <a href="#whitespace">Whitespace</a> characters are allowed
around the numerical values.
<P>All RGB colors are specified in the sRGB color space (see
[[SRGB]]). User agents may vary in the fidelity with which they
represent these colors, but using sRGB provides an unambiguous and
objectively measurable definition of what the color should be, which
can be related to international standards (see [[COLORIMETRY]]).
<P>Conforming user agents may limit their color-displaying efforts to
performing a gamma-correction on them. sRGB specifies a display gamma
of 2.2 under specified viewing conditions. User agents should adjust the
colors given in CSS such that, in combination with an output device's
"natural" display gamma, an effective display gamma of 2.2 is
produced. See the section on <a
href="colors.html#gamma-correction">gamma correction</a> for further
details. Note that only colors specified in CSS are affected; e.g.,
images are expected to carry their own color information.
<P>Values outside the device gamut should be clipped: the red, green,
and blue values must be changed to fall within the range supported by
the device. For a typical CRT monitor, whose device gamut is the same
as sRGB, the three rules below are equivalent:
<div class="example"><P>
<PRE>
em { color: rgb(255,0,0) } /* integer range 0 - 255 */
em { color: rgb(300,0,0) } /* clipped to rgb(255,0,0) */
em { color: rgb(255,-10,0) } /* clipped to rgb(255,0,0) */
em { color: rgb(110%, 0%, 0%) } /* clipped to rgb(100%,0%,0%) */
</PRE>
</div>
<p>Other devices, such as printers, have different gamuts to sRGB;
some colors outside the 0..255 sRGB range will be representable
(inside the device gamut), while other colors inside the 0..255 sRGB
range will be outside the device gamut and will thus be clipped.
</p>
<h3><a name="strings">Strings</a></H3>
<P><span class="index-def" title="&lt;string&gt;, definition of"><a
name="value-def-string">Strings</a></span> can either be written
with double quotes or with single quotes. Double quotes cannot occur
inside double quotes, unless escaped (as '\"' or as
'\22'). Analogously for single quotes ("\'" or "\27").
<div class="example"><P>
<pre>
"this is a 'string'"
"this is a \"string\""
'this is a "string"'
'this is a \'string\''
</pre>
</div>
<P>A string cannot directly contain a <span class="index-inst"
title="newline">newline</span>. To include a newline in a string, use
the escape "\A" (hexadecimal A is the line feed character in Unicode,
but represents the generic notion of "newline" in CSS). See the <span
class="propinst-content">'content'</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 (\). For instance, the following two
selectors are exactly the same: