-
Notifications
You must be signed in to change notification settings - Fork 710
/
Copy patholdsrc.html
executable file
·1830 lines (1492 loc) · 69.1 KB
/
oldsrc.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<!-- vim:expandtab:tabstop=2:shiftwidth=2:textwidth=72:
-->
<html>
<!-- the command line to process is this is:
num -l 2 template.html | toc -l 2 | incl | xref | index |\
perl -I../bin ../bin/propindex | cite-mkbib ../biblio.ref \
>template-processed.html
To do: add longdesc
-->
<head>
<title>CSS Syntax Module Level 3</title>
<link rel="stylesheet" type="text/css" href="../default.css">
<link rel="stylesheet" type="text/css" href="http://www.w3.org/StyleSheets/TR/W3C-MO">
</head>
<body>
<div class="head">
<p><a class="logo" rel="home" href="http://www.w3.org/"><img height="48"
width="72" alt="W3C" src="http://www.w3.org/Icons/w3c_home"></a><a
class="logo" rel="in-activity" href="../"><img
src="../../../Woolly/woolly-icon.png" height="48" width="72"
alt=" CSS WG"></a></p>
<h1>CSS Syntax Module Level 3</h1>
<h2 class="no-num no-toc">W3C Working Draft [DATE: 13 August 2003]</h2>
<dl>
<dt>This version:</dt>
<dd><a
href="http://www.w3.org/TR/[YEAR]/WD-css3-syntax-[ISODATE]">http://www.w3.org/TR/[YEAR]/WD-css3-syntax-[ISODATE]</a></dd>
<dt>Latest version:</dt>
<dd><a
href="http://www.w3.org/TR/css3-syntax">http://www.w3.org/TR/css3-syntax</a></dd>
<dt>Previous version:</dt>
<dd><a href="http://www.w3.org/TR/2003/WD-css3-syntax-20030813">http://www.w3.org/TR/2003/WD-css3-syntax-20030813</a></dd>
<dt>Editor:</dt>
<dd><a href="http://dbaron.org/">L. David Baron</a>, <<a href="mailto:dbaron@dbaron.org">dbaron@dbaron.org</a>></dd>
<dt>Additional Contributors:</dt>
<dd>Original CSS2 Authors</dd>
<dd>Bert Bos (W3C), <<a href="mailto:bert@w3.org">bert@w3.org</a>></dd>
<dd>Peter Linss (Netscape)</dd>
</dl>
<!--begin-copyright-->
<p>[Here will be included the file "../copyright.inc"]</p>
<!--end-copyright-->
<hr title="Separator for header">
</div>
<p style="background: #fdd; color: red; font-weight: bold; text-align: center; padding: .5em; border: thick solid red; border-radius: 1em; position: fixed; bottom: 1em; left: 1em; right: 1em;">This specification is not being actively maintained, and should not be used as a guide for implementations. It may be revived in the future, but for now should be considered obsolete. <br>If you have questions or comments on this specification, please send an email to the CSS Working Group's mailing list at <a href="mailto:www-style@w3.org">www-style@w3.org</a>. (Before sending mail for the first time, you have to subscribe at <a href="http://lists.w3.org/Archives/Public/www-style/">http://lists.w3.org/Archives/Public/www-style/</a>.)</p>
<h2 class="no-num no-toc" id="abstract">Abstract</h2>
<p>This CSS3 module describes the basic structure of CSS style sheets,
some of the details of the syntax, and the rules for parsing CSS
style sheets. It also describes (in some cases, informatively) how
stylesheets can be linked to documents and how those links can be
media-dependent. Additional details of the syntax of some parts of CSS
described in other modules will be described in those modules. The
selectors module has a grammar for selectors. Modules that define
properties give the grammar for the values of those properties, in a
format described in this document.</p>
<h2 class="no-num no-toc" id="status">Status of this document</h2>
<p><em>This section describes the status of this document at the
time of its publication. Other documents may supersede this
document. A list of current W3C publications and the latest revision
of this technical report can be found in the <a
href="http://www.w3.org/TR/">W3C technical reports index</a> at
http://www.w3.org/TR/. The latest revision can also be found by
following the "Latest Version" link above.</em></p>
<p>
This document is a draft of one of the modules of CSS Level 3 (CSS3).
Some parts of the document are derived from the CSS Level 1 and CSS
Level 2 recommendations, and those parts are thus relatively stable.
However, it is otherwise an early draft, and considerable revision is
expected in later drafts, especially in formalization of error handling
behavior, the conformance requirements for partial implementations
(given the modularization of CSS3), and integration with other CSS3
modules.
</p>
<p>This document is a working draft of the CSS working group
which is part of the <a href="http://www.w3.org/Style/">style
activity</a> (see <a
href="http://www.w3.org/Style/Activity">summary</a>).
</p>
<p>The working group would like to receive feedback:
discussion takes place on the (<a href="http://lists.w3.org/Archives/Public/www-style/">archived</a>)
public mailing list <a href="http://www.w3.org/Mail/Lists.html#www-style">www-style@w3.org</a> (see <a href="http://www.w3.org/Mail/Request">instructions</a>). W3C Members
can also send comments directly to the CSS working group. </p>
<p>This is a draft document and may be updated, replaced or
obsoleted by other documents at any time. It is inappropriate to cite
this document as other than work in progress.
Its publication does not imply endorsement by the W3C membership or the
<a href="http://www.w3.org/Style/Group/">CSS & FP Working Group</a>
(<a href="http://cgi.w3.org/MemberAccess/AccessRequest">members only</a>).
</p>
<p>Patent disclosures relevant to CSS may be found on the Working Group's
public <a href="http://www.w3.org/Style/CSS/Disclosures"
rel="disclosure">patent disclosure page.</a></p>
<p>This document may be available in translations in the future. The English
version of this specification is the only normative version.</p>
<h2 class="no-num no-toc" id="contents">Table of contents</h2>
<!--toc-->
<hr>
<h2>Dependencies on other modules</h2>
<p>This CSS3 module
depends on the following other CSS3 modules:</p>
<ul>
<li>Selectors [[!SELECT]]</li>
<li>CSS3 module: Values & Units [[!CSS3VAL]]</li>
<li>CSS3 module: Cascading & Inheritance [[!CSS3CASCADE]]</li>
</ul>
<p>It has non-normative (informative) references to the following other
CSS3 modules:</p>
<ul>
<li>CSS3 module: Paged media [[CSS3PAGE]]</li>
<li>CSS3 module: Speech [[CSS3SPEECH]]</li>
<li>Media queries [[MEDIAQ]]</li>
<li>Syntax of CSS rules in HTML's "style" attribute [[CSSSTYLEATTR]]</li>
</ul>
<h2>Introduction</h2>
<p>This specification describes the basic syntax of CSS3 and the syntax
conventions used in the property definitions spread through the CSS3
modules. The syntax of CSS3 has some error-handling requirements for
forward-compatibility, but much of the error-handling behavior depends
on the user agent.</p>
<h2>CSS style sheet representation</h2>
<p>A CSS style sheet is a sequence of characters from the Universal
Character Set (see [[!ISO10646]]). For transmission and storage, these
characters must be <dfn title="character
encoding">encoded</dfn> by a character encoding that supports the set
of characters available in US-ASCII (e.g., ISO-8859-x, Shift_JIS, etc.).
A <span id="BOM" class="index">byte order mark (BOM)</span>, as described in
section 2.7 of [[!UNICODE310]], that begins the sequence of characters
should not be considered, for purposes of applying the grammar below, as
a part of the style sheet. For a good introduction to character sets and
character encodings, please consult the HTML 4.0 specification
([[!HTML40]], chapter 5). See also the XML 1.0 specification ([[XML10]],
sections 2.2 and 4.3.3).</p>
<p>When a style sheet is embedded in another document, such as in the
STYLE element or "style" attribute of HTML, the style sheet shares the
character encoding of the whole document.</p>
<p>When a style sheet resides in a separate file, user agents must
observe the following <span class="index" title="character
encoding::user agent's determination of">priorities</span> when
determining a style sheet's <span class="index" title="character
encoding::default|default::character encoding">character
encoding</span> (from highest priority to lowest):</p>
<ol>
<li>A character encoding specified by a higher level protocol (e.g., the
"charset" parameter to the MIME type specified in an HTTP "Content-Type"
field).
(The HTTP protocol ([[!HTTP11]], section 3.7.1) mentions ISO-8859-1 as a
default character encoding when the "charset" parameter is absent from
the "Content-Type" header field. In practice, this recommendation has
proved useless because some servers don't allow a "charset" parameter to
be sent, and others may not be configured to send the parameter.
Therefore, user agents must not assume any default value for the
"charset" parameter, but must instead look for the <span
class="index">@charset</span> rule.)
</li>
<li>The <dfn>@charset</dfn>
at-rule.</li>
<li>Assume that the style sheet is UTF-8.</li>
</ol>
<p>Since the third point differs from CSS1 and CSS2, authors should not
rely on user agents to assume that style sheets without encoding
information are UTF-8 encoded. Authors should specify the encoding
using one of the first two methods.</p>
<p>At most one @charset rule may appear in an external
style sheet — it must <em>not</em> appear in an embedded style sheet
— and it must appear at the very start of the style sheet, not preceded
by any characters (except for the optional Byte Order Mark <a
href="#BOM">described
above)</a>. After "@charset", authors specify the name of a
character encoding. The name must be a charset name as described in
the IANA registry (See [[!RFC2978]]. Also, see [[CHARSETS]] for a complete
list of charsets). For example:</p>
<div class="example"><p>
@charset "ISO-8859-1";
</div>
<p>This specification does not mandate which character encodings
a user agent must support.
<span class="issue">[Should we require a certain minimal set, such as
UTF-8 and UCS2?]</span>
</p>
<p>Note that reliance on the @charset construct theoretically poses a
problem since there is no <em>a priori</em> information on how it is
encoded. In practice, however, the encodings in wide use on the
Internet are either based on ASCII, UTF-16, UCS-4, or (rarely) on
EBCDIC. This means that in general, the initial byte values of a
style sheet enable a user agent to detect the encoding family reliably,
which provides enough information to decode the @charset rule, which
in turn determines the exact character encoding.</p>
<div class="issue">[Should this specification describe how to handle
encoding errors? Can a user agent ignore the <code>@charset</code> rule
if it's wrong? What if the user agent does not support the encoding
used? Should this specification describe how to handle a
<code>@charset</code> rule that specifies a character encoding that is
incompatible with the family of encodings used to decode the
<code>@charset</code> rule (and BOM) itself?]</div>
<!-- More examples of good encodings to use? -IJ -->
<!-- Encodings not to use? (cf. HTML 4.0) -IJ -->
<h3>Referring to characters not represented in a character encoding</h3>
<p>A style sheet may have to refer to characters that cannot be
represented in the current character encoding. These characters must
be written as <span title="backslash escapes">escaped</span> references to
ISO 10646 characters. These escapes serve the same purpose as numeric
character references in HTML or XML documents (see [[!HTML40]],
chapters 5 and 25).
<p>The character escape mechanism should be used when only a few
characters must be represented this way. If most of a style sheet
requires escaping, authors should encode it with a more appropriate
encoding (e.g., if the style sheet contains a lot of Greek characters,
authors might use "ISO-8859-7" or "UTF-8").
<p>Intermediate processors using a different character encoding may
translate these escaped sequences into byte sequences of that
encoding. Intermediate processors must not, on
the other hand, alter escape sequences that cancel the special meaning
of an ASCII character.
<p><a href="#conformance">Conforming user agents</a> must
correctly map to Unicode all characters in any character encodings
that they recognize (or they must behave as if they did).
<p>For example, a style sheet transmitted as ISO-8859-1
(Latin-1) cannot contain Greek letters directly:
"κουρος" (Greek: "kouros") has to be
written as "\3BA\3BF\3C5\3C1\3BF\3C2".
<div class="note"><p>
<em><strong>Note.</strong>
In HTML 4.0,
numeric character references are interpreted in "style" attribute
values but not in the content of the STYLE element. Because of this
asymmetry, we recommend that authors use the CSS character
escape mechanism rather than numeric character references
for both the "style" attribute and the STYLE element.
For example, we recommend:</em></p>
<pre class="html-example">
<span style="voice-family: D\FC rst">...</span>
</pre>
<p><em>rather than:</em></p>
<pre class="html-example">
<span style="voice-family: D&#252;rst">...</span>
</pre>
</div>
<h3>The <dfn>text/css</dfn> content type</h3>
<p>CSS style sheets that exist in separate files are sent over the
Internet as a sequence of bytes accompanied by encoding
information<!--(see [[!HTML40]], chapter 5)-->. The structure of the
transmission, termed a <dfn title="message entity">message
entity,</dfn> is defined by MIME and HTTP 1.1 (see
[[!RFC2045]] and [[!HTTP11]]). A message entity with a content type of
"text/css" represents an independent CSS style sheet. The "text/css"
content type has been registered by RFC 2318 ([[!RFC2318]]).</p>
<h2 id="syntax">General syntax of CSS</h2>
<p>This section describes a grammar (and <dfn>forward-compatible
parsing</dfn> rules) common to any version of CSS (including
CSS3). Future versions of CSS will adhere to this core syntax, although
they may add additional syntactic constraints.</p>
<p>See the <a href="#characters">section on characters and case</a> for
information on case-sensitivity.</p>
<p>These descriptions are normative.
<h3 id="characters">Characters and case</h3>
<p> The following rules always hold:</p>
<UL>
<li><p>All CSS style sheets are <span class="index" 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.</p></li>
<li><p>In CSS3, <dfn title="identifier">identifiers</dfn>
(including element names, classes, and IDs in
selectors (see [[!SELECT]] <span class="issue">[or is this still
true]</span>)) 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
digit or a hyphen followed by 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
"<code>B&W?</code>" may
be written as "<code>B\&W\?</code>" or "<code>B\26
W\3F</code>".</span>
(See [[!UNICODE310]] and [[!ISO10646]].)</p></li>
<li><p>In CSS3, a backslash (\) character indicates three types of
<dfn title="backslash escapes">character escapes</dfn>.</p>
<p>First, inside a string (see [[!CSS3VAL]]), a backslash
followed by a newline is ignored (i.e., the string is deemed not
to contain either the backslash or the newline).</p>
<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>
<p>Third, backslash escapes allow authors to refer to characters
they can't easily put in a style sheet. 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:</p>
<ol>
<li>with a space (or other whitespace character): "\26 B" ("&B").
In this case, user agents should treat a "CR/LF" pair
(13/10) as a single
whitespace character.</li>
<li>by providing exactly 6 hexadecimal digits: "\000026B" ("&B")</li>
</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.</p>
</li>
<li><p>Backslash escapes are always considered to be part of an
<span>identifier</span> 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).</p></li>
</ul>
<h3 id="tokenization">Tokenization</h3>
<p class="issue">[This needs to be integrated with the selectors module.
How should that be done?]</p>
<p>All levels of CSS — level 1, level 2, level 3, 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>
<p>At the lexical level, CSS style sheets consist of a sequence of
tokens. Hexadecimal codes (e.g., <code>#x20</code>) refer to ISO 10646
([[!ISO10646]]). In case of multiple matches, the longest match
determines the token.</p>
<p>The following productions are <em>parts</em> of tokens:</p>
<p class="issue">[We need something to allow signs on integers. Do we need to
go as far as css3-selectors?]</p>
<table>
<tr><td id="SUBTOK-ident">ident <td>::=<td><code>'-'? <a href="#SUBTOK-nmstart">nmstart</a> <a href="#SUBTOK-nmchar">nmchar</a>*</code>
<tr><td id="SUBTOK-name">name <td>::=<td><code><a href="#SUBTOK-nmchar">nmchar</a>+</code>
<tr><td id="SUBTOK-nmstart">nmstart <td>::=<td><code>[a-zA-Z] | '_' | <a href="#SUBTOK-nonascii">nonascii</a> | <a href="#SUBTOK-escape">escape</a></code>
<tr><td id="SUBTOK-nonascii">nonascii <td>::=<td><code>[#x80-#xD7FF#xE000-#xFFFD#x10000-#x10FFFF]</code>
<tr><td id="SUBTOK-unicode">unicode <td>::=<td><code>'\' [0-9a-fA-F]{1,6} <a href="#SUBTOK-wc">wc</a>?</code>
<tr><td id="SUBTOK-escape">escape <td>::=<td><code><a href="#SUBTOK-unicode">unicode</a> | '\' [#x20-#x7E#x80-#xD7FF#xE000-#xFFFD#x10000-#x10FFFF]</code>
<tr><td id="SUBTOK-nmchar">nmchar <td>::=<td><code>[a-zA-Z0-9] | '-' | '_' | <a href="#SUBTOK-nonascii">nonascii</a> | <a href="#SUBTOK-escape">escape</a></code>
<tr><td id="SUBTOK-num">num <td>::=<td><code>[0-9]+ | [0-9]* '.' [0-9]+</code>
<tr><td id="SUBTOK-string">string <td>::=<td><code>'"' (<a href="#SUBTOK-stringchar">stringchar</a> | "'")* '"' | "'" (<a href="#SUBTOK-stringchar">stringchar</a> | '"')* "'"</code>
<tr><td id="SUBTOK-stringchar">stringchar <td>::=<td><code><a href="#SUBTOK-urlchar">urlchar</a> | #x20 | '\' <a href="#SUBTOK-nl">nl</a></code>
<tr><td id="SUBTOK-urlchar">urlchar <td>::=<td><code>[#x9#x21#x23-#x26#x27-#x7E] | <a href="#SUBTOK-nonascii">nonascii</a> | <a href="#SUBTOK-escape">escape</a></code>
<tr><td id="SUBTOK-nl">nl <td>::=<td><code>#xA | #xD #xA | #xD | #xC</code>
<tr><td id="SUBTOK-w">w <td>::=<td><code><a href="#SUBTOK-wc">wc</a>*</code>
<tr><td id="SUBTOK-wc">wc <td>::=<td><code>#x9 | #xA | #xC | #xD | #x20</code>
</table>
<p>The following productions are the complete list of tokens in
CSS3:</p>
<table>
<tr><td id="TOK-IDENT">IDENT <td>::=<td><code><a href="#SUBTOK-ident">ident</a></code>
<tr><td id="TOK-ATKEYWORD">ATKEYWORD <td>::=<td><code>'@' <a href="#SUBTOK-ident">ident</a></code>
<tr><td id="TOK-STRING">STRING <td>::=<td><code><a href="#SUBTOK-string">string</a></code>
<tr><td id="TOK-HASH">HASH <td>::=<td><code>'#' <a href="#SUBTOK-name">name</a></code>
<tr><td id="TOK-NUMBER">NUMBER <td>::=<td><code><a href="#SUBTOK-num">num</a></code>
<tr><td id="TOK-PERCENTAGE">PERCENTAGE <td>::=<td><code><a href="#SUBTOK-num">num</a> '%'</code>
<tr><td id="TOK-DIMENSION">DIMENSION <td>::=<td><code><a href="#SUBTOK-num">num</a> <a href="#SUBTOK-ident">ident</a></code>
<tr><td id="TOK-URI">URI <td>::=<td><code>"url(" <a href="#SUBTOK-w">w</a> (<a href="#SUBTOK-string">string</a> | <a href="#SUBTOK-urlchar">urlchar</a>* ) <a href="#SUBTOK-w">w</a> ")"</code>
<tr><td id="TOK-UNICODE-RANGE">UNICODE-RANGE <td>::=<td><code>"U+" [0-9A-F?]{1,6} ('-' [0-9A-F]{1,6})?</code>
<tr><td id="TOK-CDO">CDO <td>::=<td><code>"<!--"</code>
<tr><td id="TOK-CDC">CDC <td>::=<td><code>"-->"</code>
<tr><td id="TOK-S">S <td>::=<td><code><a href="#SUBTOK-wc">wc</a>+</code>
<tr><td id="TOK-COMMENT">COMMENT <td>::=<td><code>"/*" [^*]* '*'+ ([^/] [^*]* '*'+)* "/"</code>
<tr><td id="TOK-FUNCTION">FUNCTION <td>::=<td><code><a href="#SUBTOK-ident">ident</a> '('</code>
<tr><td id="TOK-INCLUDES">INCLUDES <td>::=<td><code>"~="</code>
<tr><td id="TOK-DASHMATCH">DASHMATCH <td>::=<td><code>"|="</code>
<tr><td id="TOK-PREFIXMATCH">PREFIXMATCH <td>::=<td><code>"^="</code>
<tr><td id="TOK-SUFFIXMATCH">SUFFIXMATCH <td>::=<td><code>"$="</code>
<tr><td id="TOK-SUBSTRINGMATCH">SUBSTRINGMATCH <td>::=<td><code>"*="</code>
<tr><td id="TOK-CHAR">CHAR <td>::=<td>any other character not matched by the above rules, except for <code>"</code> or <code>'</code>
<tr><td id="TOK-BOM">BOM <td>::=<td><code>#xFEFF</code>
</table>
<p>
Since any single character other than ' or " that cannot be part of a
larger token is a single character token, there cannot be errors in
tokenization other than the inability to tokenize an unmatched
quotation mark. If at some point it is not possible to continue
tokenizing an incoming style sheet, the remainder of the style sheet
should be ignored and only the largest initial segment of the
style sheet that can be tokenized according to the above rules (that
is, the entire style sheet except for the part from the unmatched
(single or double) quotation mark to the end) should be used to form
the sequence of tokens to be parsed according to the grammar.
</p>
<p class="issue">[This isn't exactly right. Since the string token can't
contain newlines that aren't escaped by backslashes, an untokenizable
sequence can occur in the middle of a file. Would it be better to
change things so that unmatched quotation marks become single-character
tokens and all character streams are tokenizable?]</p>
<h3>Grammar</h3>
<h4>Principles of CSS error handling</h4>
<p>All levels of CSS, starting from CSS1, have required that user agents
ignore certain types of invalid style sheets in well-defined ways. This
allows forward-compatibility, since it allows future extensions to CSS
within basic grammatical constraints that will be ignored in
well-defined ways by user agents implementing earlier versions of
CSS.</p>
<p>Handling of CSS that is not valid CSS3 but is valid according to the
forward-compatible syntax requires first determining the beginning and
end of the part that is invalid and then handling that part in a
specified way. The latter is described in the <a
href="#error-handling">rules for handling parsing errors</a>. The
mechanism for the former is described within the grammar.</p>
<p>The handling of style sheets that do not parse according to the
forward-compatible core syntax is not defined by this specification.
<span class="issue">[Should it be?]</span>
</p>
<p>Certain productions within the grammar are <dfn>error handling
points</dfn>. Every error handling point has a backup production that
is to be used if it is not possible to parse the stream of tokens based
on the primary production. If the error handling production is
represented as <code>prod</code>, then the backup production is
represented as <code>FAIL(prod)</code>.</p>
<p class="issue">[The <a href="#detailed-grammar">grammar</a> given in
Appendix D
of CSS2 still needs to be incorporated into this specification. The editor
hopes that it can be done by unifying it with the forward-compatible grammar
into a single grammar that describes both the rules for forward-compatible
parsing and the syntax of what is currently possible in CSS, but that may not
be possible. However, hopefully it will be possible to do this by
describing the general grammar in terms of the concepts described in the
previous paragraph.]</p>
<p>Excluding the transformation of a production into its backup
production, this grammar is LL(1). <span class="issue">[We should
explain briefly what this means, except that it's probably not true.
It's probably just LALR(1).]</span>
</p>
<p>The portion of a CSS style sheet that is to be used is the largest
initial stream of the tokens resulting from the <a
href="#tokenization">tokenization process</a> that can be parsed
according to the grammar presented in this chapter. (For example, if a
brace closing a declaration block <span class="issue">[link-ify
this]</span> is not present, the declaration block
must be ignored since the closing brace is required to satisfy this
grammar.) <span class="issue">[This might lead to highly unexpected
behavior when there's an extra closing brace (etc.). Do we really want
this?]</span></p>
<p>Some of the constraints of CSS are not expressed in the grammar. For
example, an <code>@charset</code> rule is not permitted in an embedded
style sheet, or a namespace prefix that has not been defined by an
<code>@namespace</code> rule is an invalid selector. These constraints
should be handled just as a parsing error would be (by ignoring out to
the next backup production) unless specified otherwise.</p>
<h4>Style sheets</h4>
<p>Below is the core syntax for CSS. Lowercase identifiers represent
productions in this grammar, uppercase identifiers represent tokens (see
above), and characters in single quotes (') represent CHAR tokens (see
above). The sections that follow describe
how to use it.</p>
<p class="issue">[This might need better integration with the selectors
module, although maybe it's ok.]</p>
<PRE>
stylesheet : [ CDO | CDC | S | statement ]*;
statement : ruleset | at-rule;
at-rule : ATKEYWORD S* any* [ block | ';' S* ];
block : '{' S* [ any | block | ATKEYWORD S* | ';' 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 S* any* ')' | DASHMATCH | '(' S* any* ')'
| '[' S* any* ']' ] S*;
</PRE>
<div class="issue">
[The definitions of these productions should be spread below into the
prose describing what they mean. Furthermore, they should be combined
with the Appendix D grammar from CSS2, perhaps using notation like:
<table>
<tr><td>ruleset</td><td>::=</td><td>...</td></tr>
<tr><td>FAIL(ruleset)</td><td>::=</td><td>...</td></tr>
</table>
]</div>
<p><dfn>COMMENT</dfn> 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 <dfn>whitespace</dfn>.
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 id="keywords">Keywords</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>
<p>is not. (It is a string.) Other illegal examples:
<div class="illegal example"><p>
<pre>
width: "auto";
border: "none";
background: "red";
</pre>
</div>
<h3>Statements</h3>
<p>A CSS style sheet, for any version of CSS, consists of a list of
<em class="index">statements</em>
(see the grammar above). There are two kinds of statements: <em
class="index">at-rules</em>
and <em class="index" title="rule sets">rule
sets.</em> There may be <a href="#whitespace">whitespace</a>
around the statements.</p>
<h3><dfn>At-rules</dfn></h3>
<p> At-rules start with an <DFN>at-keyword</DFN>, an '@' character
followed immediately by an <span>identifier</span> (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 or misplaced
at-rule must <span class="index">ignore</span> the whole of the at-rule and continue
parsing after it.</p>
<div class="illegal example"><p>
Assume, for example, that a CSS3 parser encounters this style sheet:
<PRE>
@import "subs.css";
h1 { color: blue }
@import "list.css";
</PRE>
<p>The second '<code>@import</code>' is illegal according to CSS3 since
'<code>@import</code>' rules must occur before all rules other than
'<code>@charset</code>' rules. The CSS3 parser
<span class="index" title="ignore">ignores</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><dfn>Blocks</dfn></h3>
<p> A <span class="index"><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 (( )), brackets ([ ]) and braces ({ }) 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">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 <span title="backslash escapes">escaped
character</span>, and thus doesn't match the first single quote:
<PRE>
{ causta: "}" + ({7} * '\'') }
</PRE>
<p>Note that the above rule is not valid CSS3, 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 <dfn>declaration-block</dfn> (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 <dfn>selector</dfn> (see the Selectors module
[[!SELECT]]) 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 CSS3), it must <span class="index">ignore</span> the {}-block as well.
<p>CSS3 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" title="ignore">ignored</span> if there is an error anywhere in the
selector, even though the rest of the selector may look reasonable in
CSS3.
<DIV class=illegal example>
<p>For example, since the "&" is not a valid token in a CSS3
selector, a CSS3 user agent must
<span class="index">ignore</span>
the whole second line, and not set the color of H3 to red:
<PRE>
h1, h2 {color: green }
h3, h4 & 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 CSS3 statement.
<PRE>
p[example="public class foo\
{\
private int x;\
\
foo(int x) {\
this.x = x;\
}\
\
}"] { color: red }
</PRE>
<div class="note"><p>
<em><strong>Note.</strong>
The <span class="css">\</span> characters in the above example cause the
newlines to be ignored. Newlines can be placed in strings only using the
correct numeric character escape. See <a href="#characters">characters
and case</a> above.
</em></p></div>
</div>
<h3 id="declarations">Declarations and properties</h3>
<p> A <dfn>declaration</dfn> is either empty or
consists of a <dfn>property</dfn>, 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: 2em }
h1 { line-height: 1.2 }
h1 { font-family: Helvetica, Arial, sans-serif }
h1 { font-variant: normal }
h1 { font-style: normal }
</pre>
<p>are equivalent to:</p>
<pre>
h1 {
font-weight: bold;
font-size: 2em;
line-height: 1.2;
font-family: Helvetica, Arial, sans-serif;
font-variant: normal;
font-style: normal
}
</pre>
</div>
<p>A property is an <span>identifier</span>. Any character may occur
in the value, but parentheses ("( )"), brackets ("[ ]"),
braces ("{ }"), single
quotes (') and double quotes (") <!-- " --> must come in matching
pairs, and semicolons not in strings must be <span title="backslash
escapes">escaped</span>. Parentheses, brackets, and
braces may be nested. Inside the quotes, characters are parsed as a
string.
<p>The syntax of <dfn title="value">values</dfn>
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">ignore</span> a declaration with an invalid property
name or an invalid value. Every CSS3 property has its own syntactic
and semantic restrictions on the values it accepts.
<div class="illegal example"><p>
For example, assume a CSS3 parser encounters this style sheet:
<PRE>
h1 { color: red; font-style: 12px } /* Invalid value: 12px */
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 CSS3 parser will <span
class="index">ignore</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><dfn>Comments</dfn></h3>
<p><span class="index">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 ("<!--" and
"-->") 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 id="error-handling">Rules for handling parsing errors or unsupported features</h2>
<p class="issue">[Hopefully (assuming it can be formalized within the
rules above) this section will not need so much detail and can be folded
into the previous section.]</p>
<p>In some cases, user agents must ignore part of an illegal style
sheet. This specification defines <dfn>ignore</dfn> to mean
that the user agent parses the illegal part according to the grammar
above (in order to find its
beginning and end), but otherwise acts as if it had not been there.</p>
<p>If a style sheet cannot be parsed according to the grammar above, the
user agent must behave the same as it would if the style sheet had the
smallest sequence of characters removed from its end that would allow
it to be parsed according to the grammar.</p>
<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">ignore</span> a <a
href="#declarations">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 id="illegalvalues"><strong>Illegal values.</strong> User agents must ignore a
declaration with an illegal value. For example:
<PRE class="illegal example">
img { float: left } /* correct CSS3 */
img { float: left here } /* "here" is not a value of 'float' */
img { background: "red" } /* keywords cannot be quoted in CSS3 */
img { border-width: 3 } /* a unit must be specified for length values */
</PRE>
A CSS3 parser would honor the first rule and
<span class="index">ignore</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>
<p class="issue">[A general comment on how to handle negative numbers
when disallowed might be useful. It should be a parsing error (and thus
ignored). We might want to add additional grammar productions for
potentially negative numbers.]</p>
</li>
<li><strong>Malformed declarations.</strong> User agents must handle
unexpected tokens encountered while parsing a declaration by reading
until the end of the declaration, while observing the rules for matching
pairs of (), [], {}, "", and '', and correctly handling escapes. For
example, a malformed declaration may be missing a property, colon (:) or
value. The following are all equivalent:
<pre class="example"><code>
p { color:green }
p { color:green; color } /* malformed declaration missing ':', value */
p { color:red; color; color:green } /* same with expected recovery */
p { color:green; color: } /* malformed declaration missing value */
p { color:red; color:; color:green } /* same with expected recovery */
p { color:green; color{;color:maroon} } /* unexpected tokens { } */
p { color:red; color{;color:maroon}; color:green } /* same with recovery */
</code></pre>
</li>
<LI><strong>Invalid at-keywords.</strong> User agents must <span
class="index">ignore</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 CSS3. Therefore, the whole
at-rule (up to, and including, the third right curly brace) is <span
class="index" title="ignore">ignored.</span> A
CSS3 user agent <span class="index" title="ignore">ignores</span> it, effectively reducing the style sheet
to:</p>
<PRE class="example">
h1 { color: blue }
</PRE>
</li>
<li id="unsupportedvalues">
<p><strong>Unsupported Values</strong>If a UA does not support a
particular value, it should <em>ignore</em> that value when parsing
stylesheets, as if that value was an <a href="#illegalvalues">illegal
value</a>. For example:</p>
<div class="example">
<pre>
h3 {
display: inline;
display: run-in;
}
</pre>
</div>
<p>
A UA that supports the 'run-in' value for the 'display' property will
accept the first display declaration and then "write over" that value with
the second display declaration. A UA that does not support the 'run-in'
value will process the first display declaration and ignore the second
display declaration.
</p>
</li>
</UL>
<h3>Partial implementations</h3>
<p>CSS3, unlike CSS1 and CSS2, is modular and thus allows for partial
implementations. The conformance requirements of some modules may also allow
for conformant implementations to implement only part of a module.</p>