8000 csswg-drafts/css-syntax/Overview.bs at 5c1e1fce995c589ab07b48cd95b4fca98f68c3f3 · w3c/csswg-drafts · GitHub
Skip to content

Latest commit

 

History

History
3466 lines (2760 loc) · 110 KB

File metadata and controls

3466 lines (2760 loc) · 110 KB
<h1>CSS Syntax Module Level 3</h1>
<pre class='metadata'>
Shortname: css-syntax
Level: 3
Status: ED
Group: csswg
ED: http://dev.w3.org/csswg/css-syntax/
TR: http://www.w3.org/TR/css-syntax-3/
Previous Version: http://www.w3.org/TR/2014/CR-css-syntax-3-20140220/
Previous Version: http://www.w3.org/TR/2013/WD-css-syntax-3-20131105/
Previous Version: http://www.w3.org/TR/2013/WD-css-syntax-3-20130919/
Editor: Tab Atkins Jr., Google, http://xanthir.com/contact/
Editor: Simon Sapin, Mozilla, http://exyr.org/about/
Abstract: This module describes, in general terms, the basic structure and syntax of CSS stylesheets. It defines, in detail, the syntax and parsing of CSS - how to turn a stream of bytes into a meaningful stylesheet.
Ignored Terms: <keyframes-name>, <keyframe-rule>, <keyframe-selector>, <translation-value>, <media-query-list>
Link Defaults: css-text-decor-3 (property) text-decoration, css-color-3 (property) color, css-transforms-1 (function) translatex()
</pre>
<h2 id="intro">
Introduction</h2>
<em>This section is not normative.</em>
This module defines the abstract syntax and parsing of CSS stylesheets
and other things which use CSS syntax
(such as the HTML <code>style</code> attribute).
It defines algorithms for converting a stream of Unicode <a>code points</a>
(in other words, text)
into a stream of CSS tokens,
and then further into CSS objects
such as stylesheets, rules, and declarations.
<h3 id="placement">
Module interactions</h3>
This module defines the syntax and parsing of CSS stylesheets.
It supersedes the lexical scanner and grammar defined in CSS 2.1.
<h2 id='syntax-description'>
Description of CSS's Syntax</h2>
<em>This section is not normative.</em>
A CSS document is a series of <a>qualified rules</a>,
which are usually style rules that apply CSS properties to elements,
and <a>at-rules</a>,
which define special processing rules or values for the CSS document.
A qualified rule starts with a prelude
then has a {}-wrapped block containing a sequence of declarations.
The meaning of the prelude varies based on the context that the rule appears in -
for style rules, it's a selector which specifies what elements the declarations will apply to.
Each declaration has a name,
followed by a colon and the declaration value.
Declarations are separated by semicolons.
<div class='example'>
A typical rule might look something like this:
<pre>
p > a {
color: blue;
text-decoration: underline;
}
</pre>
In the above rule, "<code>p > a</code>" is the selector,
which, if the source document is HTML,
selects any <code>&lt;a></code> elements that are children of a <code>&lt;p></code> element.
"<code>color: blue;</code>" is a declaration specifying that,
for the elements that match the selector,
their 'color' property should have the value ''blue''.
Similarly, their 'text-decoration' property should have the value ''underline''.
</div>
At-rules are all different, but they have a basic structure in common.
They start with an "@" <a>code point</a> followed by their name.
Some <a>at-rules</a> are simple statements,
with their name followed by more CSS values to specify their behavior,
and finally ended by a semicolon.
Others are blocks;
they can have CSS values following their name,
but they end with a {}-wrapped block,
similar to a <a>qualified rule</a>.
Even the contents of these blocks are specific to the given <a>at-rule</a>:
sometimes they contain a sequence of declarations, like a <a>qualified rule</a>;
other times, they may contain additional blocks, or at-rules, or other structures altogether.
<div class='example'>
Here are several examples of <a>at-rules</a> that illustrate the varied syntax they may contain.
<pre>@import "my-styles.css";</pre>
The ''@import'' <a>at-rule</a> is a simple statement.
After its name, it takes a single string or ''url()'' function to indicate the stylesheet that it should import.
<pre>
@page :left {
margin-left: 4cm;
margin-right: 3cm;
}
</pre>
The ''@page'' <a>at-rule</a> consists of an optional page selector (the '':left'' pseudoclass),
followed by a block of properties that apply to the page when printed.
In this way, it's very similar to a normal style rule,
except that its properties don't apply to any "element",
but rather the page itself.
<pre>
@media print {
body { font-size: 10pt }
}
</pre>
The ''@media'' <a>at-rule</a> begins with a media type
and a list of optional media queries.
Its block contains entire rules,
which are only applied when the ''@media''s conditions are fulfilled.
</div>
Property names and <a>at-rule</a> names are always <a>identifiers</a>,
which have to start with a letter or a hyphen followed by a letter,
and then can contain letters, numbers, hyphens, or underscores.
You can include any <a>code point</a> at all,
even ones that CSS uses in its syntax,
by <a>escaping</a> it.
The sy 7DDD ntax of selectors is defined in the <a href="http://www.w3.org/TR/selectors/">Selectors spec</a>.
Similarly, the syntax of the wide variety of CSS values is defined in the <a href="http://www.w3.org/TR/css3-values/">Values &amp; Units spec</a>.
The special syntaxes of individual <a>at-rules</a> can be found in the specs that define them.
<h3 id="escaping">
Escaping</h3>
<em>This section is not normative.</em>
Any Unicode <a>code point</a> can be included in an <a>identifier</a> or quoted string
by <dfn>escaping</dfn> it.
CSS escape sequences start with a backslash (\), and continue with:
<ul>
<li>
Any Unicode <a>code point</a> that is not a <a>hex digits</a> or a <a>newline</a>.
The escape sequence is replaced by that <a>code point</a>.
<li>
Or one to six <a>hex digits</a>, followed by an optional <a>whitespace</a>.
The escape sequence is replaced by the Unicode <a>code point</a>
whose value is given by the hexadecimal digits.
This optional whitespace allow hexadecimal escape sequences
to be followed by "real" hex digits.
<p class=example>
An <a>identifier</a> with the value "&B"
could be written as ''\26 B'' or ''\000026B''.
<p class=note>
A "real" space after the escape sequence must be doubled.
</ul>
<h3 id="error-handling">
Error Handling</h3>
<em>This section is not normative.</em>
When errors occur in CSS,
the parser attempts to recover gracefully,
throwing away only the minimum amount of content
before returning to parsing as normal.
This is because errors aren't always mistakes -
new syntax looks like an error to an old parser,
and it's useful to be able to add new syntax to the language
without worrying about stylesheets that include it being completely broken in older UAs.
The precise error-recovery behavior is detailed in the parser itself,
but it's simple enough that a short description is fairly accurate:
<ul>
<li>
At the "top level" of a stylesheet,
an <<at-keyword-token>> starts an at-rule.
Anything else starts a qualified rule,
and is included in the rule's prelude.
This may produce an invalid selector,
but that's not the concern of the CSS parser &mdash;
at worst, it means the selector will match nothing.
<li>
Once an at-rule starts,
nothing is invalid from the parser's standpoint;
it's all part of the at-rule's prelude.
Encountering a <<semicolon-token>> ends the at-rule immediately,
while encountering an opening curly-brace <a href="#tokendef-open-curly">&lt;{-token></a> starts the at-rule's body.
The at-rule seeks forward, matching blocks (content surrounded by (), {}, or [])
until it finds a closing curly-brace <a href="#tokendef-close-curly">&lt;}-token></a> that isn't matched by anything else
or inside of another block.
The contents of the at-rule are then interpreted according to the at-rule's own grammar.
<li>
Qualified rules work similarly,
except that semicolons don't end them;
instead, they are just taken in as part of the rule's prelude.
When the first {} block is found,
the contents are always interpreted as a list of declarations.
<li>
When interpreting a list of declarations,
unknown syntax at any point causes the parser to throw away whatever declaration it's currently building,
and seek forward until it finds a semicolon (or the end of the block).
It then starts fresh, trying to parse a declaration again.
<li>
If the stylesheet ends while any rule, declaration, function, string, etc. are still open,
everything is automatically closed.
This doesn't make them invalid,
though they may be incomplete
and thus thrown away when they are verified against their grammar.
</ul>
<h2 id="tokenizing-and-parsing">
Tokenizing and Parsing CSS</h2>
User agents must use the parsing rules described in this specification
to generate the CSSOM trees from text/css resources.
Together, these rules define what is referred to as the CSS parser.
This specification defines the parsing rules for CSS documents,
whether they are syntactically correct or not.
Certain points in the parsing algorithm are said to be a <dfn title="parse error">parse errors</dfn>.
The error handling for parse errors is well-defined:
user agents must either act as described below when encountering such problems,
or must abort processing at the first error that they encounter for which they do not wish to apply the rules described below.
Conformance checkers must report at least one parse error condition to the user
if one or more parse error conditions exist in the document
and must not report parse error conditions
if none exist in the document.
Conformance checkers may report more than one parse error condition if more than one parse error condition exists in the document.
Conformance checkers are not required to recover from parse errors,
but if they do,
they must recover in the same way as user agents.
<h3 id="parsing-overview">
Overview of the Parsing Model</h3>
The input to the CSS parsing process consists of a stream of Unicode <a>code points</a>,
which is passed through a tokenization stage followed by a tree construction stage.
The output is a CSSStyleSheet object.
Note: Implementations that do not support scripting do not have to actually create a CSSOM CSSStyleSheet object,
but the CSSOM tree in such cases is still used as the model for the rest of the specification.
<h3 id="input-byte-stream">
The input byte stream</h3>
When parsing a stylesheet,
the stream of Unicode <a>code points</a> that comprises the input to the tokenization stage
might be initially seen by the user agent as a stream of bytes
(typically coming over the network or from the local file system).
If so, the user agent must decode these bytes into <a>code points</a> according to a particular character encoding.
To decode the stream of bytes into a stream of <a>code points</a>,
UAs must use the <dfn><a href="http://encoding.spec.whatwg.org/#decode">decode</a></dfn> algorithm
defined in [[!ENCODING]],
with the fallback encoding determined as follows.
Note: The <a>decode</a> algorithm
gives precedence to a byte order mark (BOM),
and only uses the fallback when none is found.
To <dfn>determine the fallback encoding</dfn>:
<ol>
<li>
If HTTP or equivalent protocol defines an encoding (e.g. via the charset parameter of the Content-Type header),
<dfn export><a href="http://encoding.spec.whatwg.org/#concept-encoding-get">get an encoding</a></dfn> [[!ENCODING]]
for the specified value.
If that does not return failure,
use the return value as the fallback encoding.
<li>
Otherwise, check the byte stream.
If the first 1024 bytes of the stream begin with the hex sequence
<pre>40 63 68 61 72 73 65 74 20 22 XX* 22 3B</pre>
where each <code>XX</code> byte is a value between 0<sub>16</sub> and 21<sub>16</sub> inclusive
or a value between 23<sub>16</sub> and 7F<sub>16</sub> inclusive,
then <a>get an encoding</a>
for the sequence of <code>XX</code> bytes,
interpreted as <code>ASCII</code>.
<details class='why'>
<summary>What does that byte sequence mean?</summary>
The byte sequence above,
when decoded as ASCII,
is the string "<code>@charset "…";</code>",
where the "…" is the sequence of bytes corresponding to the encoding's label.
</details>
If the return value was <code>utf-16be</code> or <code>utf-16le</code>,
use <code>utf-8</code> as the fallback encoding;
if it was anything else except failure,
use the return value as the fallback encoding.
<details class='why'>
<summary>Why use utf-8 when the declaration says utf-16?</summary>
The bytes of the encoding declaration spell out “<code>@charset "…";</code>” in ASCII,
but UTF-16 is not ASCII-compatible.
Either you've typed in complete gibberish (like <code>䁣桡牳整•utf-16be∻</code>) to get the right bytes in the document,
which we don't want to encourage,
or your document is actually in an ASCII-compatible encoding
and your encoding declaration is lying.
Either way, defaulting to UTF-8 is a decent answer.
As well, this mimics the behavior of HTML's <code>&lt;meta charset></code> attribute.
</details>
Note: Note that the syntax of an encoding declaration <em>looks like</em> the syntax of an <a>@charset</a> rule,
but it's actually much more restrictive.
A number of things you can do in CSS that would produce a valid <a>@charset</a> rule,
such as using multiple spaces, comments, or single quotes,
will cause the encoding declaration to not be recognized.
This behavior keeps the encoding declaration as simple as possible,
and thus maximizes the likelihood of it being implemented correctly.
<li>
Otherwise, if an <a>environment encoding</a> is provided by the referring document,
use that as the fallback encoding.
<li>
Otherwise, use <code>utf-8</code> as the fallback encoding.
</ol>
<div class='note'>
Though UTF-8 is the default encoding for the web,
and many newer web-based file formats assume or require UTF-8 encoding,
CSS was created before it was clear which encoding would win,
and thus can't automatically assume the stylesheet is UTF-8.
Stylesheet authors <em>should</em> author their stylesheets in UTF-8,
and ensure that either an HTTP header (or equivalent method) declares the encoding of the stylesheet to be UTF-8,
or that the referring document declares its encoding to be UTF-8.
(In HTML, this is done by adding a <code>&lt;meta charset=utf-8></code> element to the head of the document.)
If neither of these options are available,
authors should begin the stylesheet with a UTF-8 BOM
or the exact characters
<pre>@charset "utf-8";</pre>
</div>
Document languages that refer to CSS stylesheets that are decoded from bytes
may define an <dfn export>environment encoding</dfn> for each such stylesheet,
which is used as a fallback when other encoding hints are not available or can not be used.
The concept of <a>environment encoding</a> only exists for compatibility with legacy content.
New formats and new linking mechanisms <b>should not</b> provide an <a>environment encoding</a>,
so the stylesheet defaults to UTF-8 instead in the absence of more explicit information.
Note: [[HTML]] defines <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/links.html#link-type-stylesheet">the environment encoding for <code>&lt;link rel=stylesheet></code></a>.
Note: [[CSSOM]] defines <a href="http://dev.w3.org/csswg/cssom/#requirements-on-user-agents-implementing-the-xml-stylesheet-processing-instruction">the environment encoding for <code>&lt;xml-stylesheet?></code></a>.
Note: [[CSS3CASCADE]] defines <a href="http://dev.w3.org/csswg/css-cascade/#at-ruledef-import">the environment encoding for <code>@import</code></a>.
<h3 id="input-preprocessing">
Preprocessing the input stream</h3>
The input stream consists of the <a>code points</a>
pushed into it as the input byte stream is decoded.
Before sending the input stream to the tokenizer,
implementations must make the following <a>code point</a> substitutions:
<ul>
<li>
Replace any U+000D CARRIAGE RETURN (CR) <a>code point</a>,
U+000C FORM FEED (FF) <a>code point</a>,
or pairs of U+000D CARRIAGE RETURN (CR) followed by U+000A LINE FEED (LF)
by a single U+000A LINE FEED (LF) <a>code point</a>.
<li>
Replace any U+0000 NULL <a>code point</a> with U+FFFD REPLACEMENT CHARACTER (�).
</ul>
<h2 id="tokenization">
Tokenization</h2>
Implementations must act as if they used the following algorithms to tokenize CSS.
To transform a stream of <a>code points</a> into a stream of tokens,
repeatedly <a>consume a token</a>
until an <<EOF-token>> is reached,
collecting the returned tokens into a stream.
Each call to the <a>consume a token</a> algorithm
returns a single token,
so it can also be used "on-demand" to tokenize a stream of <a>code points</a> <em>during</em> parsing,
if so desired.
The output of the tokenization step is a stream of zero or more of the following tokens:
<dfn>&lt;ident-token></dfn>,
<dfn>&lt;function-token></dfn>,
<dfn>&lt;at-keyword-token></dfn>,
<dfn>&lt;hash-token></dfn>,
<dfn>&lt;string-token></dfn>,
<dfn>&lt;bad-string-token></dfn>,
<dfn>&lt;url-token></dfn>,
<dfn>&lt;bad-url-token></dfn>,
<dfn>&lt;delim-token></dfn>,
<dfn>&lt;number-token></dfn>,
<dfn>&lt;percentage-token></dfn>,
<dfn>&lt;dimension-token></dfn>,
<dfn>&lt;unicode-range-token></dfn>,
<dfn>&lt;include-match-token></dfn>,
<dfn>&lt;dash-match-token></dfn>,
<dfn>&lt;prefix-match-token></dfn>,
<dfn>&lt;suffix-match-token></dfn>,
<dfn>&lt;substring-match-token></dfn>,
<dfn>&lt;column-token></dfn>,
<dfn>&lt;whitespace-token></dfn>,
<dfn>&lt;CDO-token></dfn>,
<dfn>&lt;CDC-token></dfn>,
<dfn>&lt;colon-token></dfn>,
<dfn>&lt;semicolon-token></dfn>,
<dfn>&lt;comma-token></dfn>,
<dfn id="tokendef-open-square">&lt;[-token></dfn>,
<dfn id="tokendef-close-square">&lt;]-token></dfn>,
<dfn id="tokendef-open-paren">&lt;(-token></dfn>,
<dfn id="tokendef-close-paren">&lt;)-token></dfn>,
<dfn id="tokendef-open-curly">&lt;{-token></dfn>,
and <dfn id="tokendef-close-curly">&lt;}-token></dfn>.
<ul>
<li>
<<ident-token>>, <<function-token>>, <<at-keyword-token>>, <<hash-token>>, <<string-token>>, and <<url-token>> have a value composed of zero or more <a>code points</a>.
Additionally, hash tokens have a type flag set to either "id" or "unrestricted". The type flag defaults to "unrestricted" if not otherwise set.
<li>
<<delim-token>> has a value composed of a single <a>code point</a>.
<li>
<<number-token>>, <<percentage-token>>, and <<dimension-token>> have a representation composed of one or more <a>code points</a>, and a numeric value.
<<number-token>> and <<dimension-token>> additionally have a type flag set to either "integer" or "number". The type flag defaults to "integer" if not otherwise set.
<<dimension-token>> additionally have a unit composed of one or more <a>code points</a>.
<li>
<<unicode-range-token>> has
a <dfn id=unicode-range-start title="start of the range">start</dfn>
and an <dfn id=unicode-range-end title="end of the range">end</dfn>,
a pair of integers.
</ul>
Note: The type flag of hash tokens is used in the Selectors syntax [[SELECT]].
Only hash tokens with the "id" type are valid <a href="http://www.w3.org/TR/selectors/#id-selectors">ID selectors</a>.
Note: As a technical note,
the tokenizer defined here requires only three <a>code points</a> of look-ahead.
The tokens it produces are designed to allow Selectors to be parsed with one token of look-ahead,
and additional tokens may be added in the future to maintain this invariant.
<h3 id='token-diagrams'>
Token Railroad Diagrams</h3>
<em>This section is non-normative.</em>
This section presents an informative view of the tokenizer,
in the form of railroad diagrams.
Railroad diagrams are more compact than an explicit parser,
but often easier to read than an regular expression.
These diagrams are <em>informative</em> and <em>incomplete</em>;
they describe the grammar of "correct" tokens,
but do not describe error-handling at all.
They are provided solely to make it easier to get an intuitive grasp of the syntax of each token.
Diagrams with names such as <em>&lt;foo-token></em> represent tokens.
The rest are productions referred to by other diagrams.
<dl>
<dt id="comment-diagram">comment
<dd>
<pre class='railroad'>
T: /*
Star:
N: anything but * followed by /
T: */
</pre>
<dt id="newline-diagram">newline
<dd>
<pre class='railroad'>
Choice:
T: \n
T: \r\n
T: \r
T: \f
</pre>
<dt id="whitespace-diagram">whitespace
<dd>
<pre class='railroad'>
Choice:
T: space
T: \t
N: newline
</pre>
<dt id="hex-digit-diagram">hex digit
<dd>
<pre class='railroad'>
N: 0-9 a-f or A-F
</pre>
<dt id="escape-diagram">escape
<dd>
<pre class='railroad'>
T: \
Choice:
N: not newline or hex digit
Seq:
Plus:
N: hex digit
C: 1-6 times
Opt: skip
N: whitespace
</pre>
<dt id="whitespace-token-diagram"><<whitespace-token>>
<dd>
<pre class='railroad'>
Plus:
N: whitespace
</pre>
<dt id="ws*-diagram">ws*
<dd>
<pre class='railroad'>
Star:
N: <whitespace-token>
</pre>
<dt id="ident-token-diagram"><<ident-token>>
<dd>
<pre class='railroad'>
Or: 1
T: --
Seq:
Opt: skip
T: -
Or:
N: a-z A-Z _ or non-ASCII
N: escape
Star:
Or:
N: a-z A-Z 0-9 _ - or non-ASCII
N: escape
</pre>
<dt id="function-token-diagram"><<function-token>>
<dd>
<pre class='railroad'>
N: <ident-token>
T: (
</pre>
<dt id="at-keyword-token-diagram"><<at-keyword-token>>
<dd>
<pre class='railroad'>
T: @
N: <ident-token>
</pre>
<dt id="hash-token-diagram"><<hash-token>>
<dd>
<pre class='railroad'>
T: #
Plus:
Choice:
N:a-z A-Z 0-9 _ - or non-ASCII
N: escape
</pre>
<dt id="string-token-diagram"><<string-token>>
<dd>
<pre class='railroad'>
Choice:
Seq:
T: "
Star:
Choice:
N: not " \ or newline
N: escape
Seq:
T: \
N: newline
T: "
Seq:
T: '
Star:
Choice:
N: not ' \ or newline
N: escape
Seq:
T: \
N: newline
T: '
</pre>
<dt id="url-token-diagram"><<url-token>>
<dd>
<pre class='railroad'>
N: <ident-token "url">
T: (
N: ws*
Opt:
Seq:
Choice:
N: url-unquoted
N: <string-token>
N: ws*
T: )
</pre>
<dt id="url-unquoted-diagram">url-unquoted
<dd>
<pre class='railroad'>
Plus:
Choice:
N: not " ' ( ) \ whitespace or non-printable
N: escape
</pre>
<dt id="number-token-diagram"><<number-token>>
<dd>
<pre class='railroad'>
Choice: 1
T: +
Skip:
T: -
Choice:
Seq:
Plus:
N: digit
T: .
Plus:
N: digit
Plus:
N: digit
Seq:
T: .
Plus:
N: digit
Opt: skip
Seq:
Choice:
T: e
T: E
Choice: 1
T: +
S:
T: -
Plus:
N: digit
</pre>
<dt id="dimension-token-diagram"><<dimension-token>>
<dd>
<pre class='railroad'>
N: <number-token>
N: <ident-token>
</pre>
<dt id="percentage-token-diagram"><<percentage-token>>
<dd>
<pre class='railroad'>
N: <number-token>
T: %
</pre>
<dt id="unicode-range-token-diagram"><<unicode-range-token>>
<dd>
<pre class='railroad'>
Choice:
T: U
T: u
T: +
Choice:
Plus:
N: hex digit
C: 1-6 times
Seq:
Star:
N: hex digit
C: 1-5 times
Plus:
T: ?
C: 1 to (6 - digits) times
Seq:
Plus:
N: hex digit
C: 1-6 times
T: -
Plus:
N: hex digit
C: 1-6 times
</pre>
<dt id="include-match-token-diagram"><<include-match-token>>
<dd>
<pre class='railroad'>
T: ~=
</pre>
<dt id="dash-match-token-diagram"><<dash-match-token>>
<dd>
<pre class='railroad'>
T: |=
</pre>
<dt id="prefix-match-token-diagram"><<prefix-match-token>>
<dd>
<pre class='railroad'>
T: ^=
</pre>
<dt id="suffix-match-token-diagram"><<suffix-match-token>>
<dd>
<pre class='railroad'>
T: $=
</pre>
<dt id="substring-match-token-diagram"><<substring-match-token>>
<dd>
<pre class='railroad'>
T: *=
</pre>
<dt id="column-token-diagram"><<column-token>>
<dd>
<pre class='railroad'>
T: ||
</pre>
<dt id="CDO-token-diagram"><<CDO-token>>
<dd>
<pre class='railroad'>
T: <!--
</pre>
<dt id="CDC-token-diagram"><<CDC-token>>
<dd>
<pre class='railroad'>
T: -->
</pre>
</dl>
<h3 id="tokenizer-definitions">
Definitions</h3>
This section defines several terms used during the tokenization phase.
<dl export>
<dt><dfn>code point</dfn>
<dd>
A <a href="http://unicode.org/glossary/#code_point">Unicode code point</a>. [[!UNICODE]]
Any value in the Unicode codespace; that is, the range of integers from 0 to (hexadecimal) 10FFFF.
<dt><dfn>next input code point</dfn>
<dd>
The first <a>code point</a> in the input stream that has not yet been consumed.
<dt><dfn>current input code point</dfn>
<dd>
The last <a>code point</a> to have been consumed.
<dt><dfn>reconsume the current input code point</dfn>
<dd>
Push the <a>current input code point</a> back onto the front of the input stream,
so that the next time you are instructed to consume the <a>next input code point</a>,
it will instead reconsume the <a>current input code point</a>.
<dt><dfn>EOF code point</dfn>
<dd>
A conceptual <a>code point</a> representing the end of the input stream.
Whenever the input stream is empty,
the <a>next input code point</a> is always an EOF code point.
<dt><dfn export>digit</dfn>
<dd>
A <a>code point</a> between U+0030 DIGIT ZERO (0) and U+0039 DIGIT NINE (9).
<dt><dfn export>hex digit</dfn>
<dd>
A <a>digit</a>,
or a <a>code point</a> between U+0041 LATIN CAPITAL LETTER A (A) and U+0046 LATIN CAPITAL LETTER F (F),
or a <a>code point</a> between U+0061 LATIN SMALL LETTER A (a) and U+0066 LATIN SMALL LETTER F (f).
<dt><dfn export>uppercase letter</dfn>
<dd>
A <a>code point</a> between U+0041 LATIN CAPITAL LETTER A (A) and U+005A LATIN CAPITAL LETTER Z (Z).
<dt><dfn export>lowercase letter</dfn>
<dd>
A <a>code point</a> between U+0061 LATIN SMALL LETTER A (a) and U+007A LATIN SMALL LETTER Z (z).
<dt><dfn export>letter</dfn>
<dd>
An <a>uppercase letter</a>
or a <a>lowercase letter</a>.
<dt><dfn export>non-ASCII code point</dfn>
<dd>
A <a>code point</a> with a value equal to or greater than U+0080 &lt;control>.
<dt><dfn export>name-start code point</dfn>
<dd>
A <a>letter</a>,
a <a>non-ASCII code point</a>,
or U+005F LOW LINE (_).
<dt><dfn export>name code point</dfn>
<dd>
A <a>name-start code point</a>,
A <a>digit</a>,
or U+002D HYPHEN-MINUS (-).
<dt><dfn export>non-printable code point</dfn>
<dd>
A <a>code point</a> between U+0000 NULL and U+0008 BACKSPACE,
or U+000B LINE TABULATION,
or a <a>code point</a> between U+000E SHIFT OUT and U+001F INFORMATION SEPARATOR ONE,
or U+007F DELETE.
<dt><dfn export>newline</dfn>
<dd>
U+000A LINE FEED.
<span class='note'>
Note that U+000D CARRIAGE RETURN and U+000C FORM FEED are not included in this definition,
as they are converted to U+000A LINE FEED during <a href="#input-preprocessing">preprocessing</a>.
</span>
<dt><dfn export>whitespace</dfn>
<dd>A <a>newline</a>, U+0009 CHARACTER TABULATION, or U+0020 SPACE.
<dt><dfn export>surrogate code point</dfn>
<dd>
A <a>code point</a> between U+D800 and U+DFFF inclusive.
<dt><dfn export>maximum allowed code point</dfn>
<dd>The greatest <a>code point</a> defined by Unicode: U+10FFFF.
<dt><dfn export>identifier</dfn>
<dd>
A portion of the CSS source that has the same syntax as an <<ident-token>>.
Also appears in <<at-keyword-token>>,
<<function-token>>,
<<hash-token>> with the "id" type flag,
and the unit of <<dimension-token>>.
</dl>
<h3 id="tokenizer-algorithms">
Tokenizer Algorithms</h3>
The algorithms defined in this section transform a stream of <a>code points</a> into a stream of tokens.
<h4 id="consume-a-token">
Consume a token</h4>
This section describes how to <dfn>consume a token</dfn> from a stream of <a>code points</a>.
It will return a single token of any type.
<a>Consume comments</a>.
Consume the <a>next input code point</a>.
<dl>
<dt><a>whitespace</a>
<dd>
Consume as much <a>whitespace</a> as possible.
Return a <<whitespace-token>>.
<dt>U+0022 QUOTATION MARK (")
<dd>
<a>Consume a string token</a>
and return it.
<dt>U+0023 NUMBER SIGN (#)
<dd>
If the <a>next input code point</a> is a <a>name code point</a>
or the <a title="next input code point">next two input code points</a>
<a>are a valid escape</a>,
then:
<ol>
<li>
Create a <<hash-token>>.
<li>
If the <a title="next input code point">next 3 input code points</a> <a>would start an identifier</a>,
set the <<hash-token>>’s type flag to "id".
<li>
<a>Consume a name</a>,
and set the <<hash-token>>’s value to the returned string.
<li>
Return the <<hash-token>>.
</ol>
Otherwise,
return a <<delim-token>>
with its value set to the <a>current input code point</a>.
<dt>U+0024 DOLLAR SIGN ($)
<dd>
If the <a>next input code point</a> is
U+003D EQUALS SIGN (=),
consume it
and return a <<suffix-match-token>>.
Otherwise,
emit a <<delim-token>>
with its value set to the <a>current input code point</a>.
<dt>U+0027 APOSTROPHE (&apos;)
<dd>
<a>Consume a string token</a>
and return it.
<dt>U+0028 LEFT PARENTHESIS (()
<dd>
Return a <a href="#tokendef-open-paren">&lt;(-token></a>.
<dt>U+0029 RIGHT PARENTHESIS ())
<dd>
Return a <a href="#tokendef-close-paren">&lt;)-token></a>.
<dt>U+002A ASTERISK (*)
<dd>
If the <a>next input code point</a> is
U+003D EQUALS SIGN (=),
consume it
and return a <<substring-match-token>>.
Otherwise,
return a <<delim-token>>
with its value set to the <a>current input code point</a>.
<dt>U+002B PLUS SIGN (+)
<dd>
If the input stream <a>starts with a number</a>,
<a>reconsume the current input code point</a>,
<a>consume a numeric token</a>
and return it.
Otherwise,
return a <<delim-token>>
with its value set to the <a>current input code point</a>.
<dt>U+002C COMMA (,)
<dd>
Return a <<comma-token>>.
<dt>U+002D HYPHEN-MINUS (-)
<dd>
If the input stream <a>starts with a number</a>,
<a>reconsume the current input code point</a>,
<a>consume a numeric token</a>,
and return it.
Otherwise,
if the input stream <a>starts with an identifier</a>,
<a>reconsume the current input code point</a>,
<a>consume an ident-like token</a>,
and return it.
Otherwise,
if the <a title="next input code point">next 2 input code points</a> are
U+002D HYPHEN-MINUS
U+003E GREATER-THAN SIGN
(->),
consume them
and return a <<CDC-token>>.
Otherwise,
return a <<delim-token>>