-
Notifications
You must be signed in to change notification settings - Fork 791
Expand file tree
/
Copy pathold.html
More file actions
executable file
·2799 lines (2121 loc) · 99.2 KB
/
old.html
File metadata and controls
executable file
·2799 lines (2121 loc) · 99.2 KB
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 href="../default.css" rel=stylesheet type="text/css">
<link href="http://www.w3.org/StyleSheets/TR/W3C-WD" rel=stylesheet
type="text/css">
<body>
<div class=head>
<p><a class=logo href="http://www.w3.org/" rel=home><img alt=W3C height=48
src="http://www.w3.org/Icons/w3c_home" width=72></a><a class=logo
href="../" rel=in-activity><img alt=" CSS WG" height=48
src="../../../Woolly/woolly-icon.png" width=72></a></p>
<h1>CSS Syntax Module Level 3</h1>
<h2 class="no-num no-toc" id=w3c-working-draft-date-13-august-2003>W3C
Working Draft 12 April 2012</h2>
<dl>
<dt>This version:
<dd><a
href="http://www.w3.org/TR/2012/WD-css3-syntax-[ISODATE]">http://www.w3.org/TR/2012/WD-css3-syntax-[ISODATE]</a>
<dt>Latest version:
<dd><a
href="http://www.w3.org/TR/css3-syntax">http://www.w3.org/TR/css3-syntax</a>
<dt>Previous version:
<dd><a
href="http://www.w3.org/TR/2003/WD-css3-syntax-20030813">http://www.w3.org/TR/2003/WD-css3-syntax-20030813</a>
<dt>Editor:
<dd><a href="http://dbaron.org/">L. David Baron</a>, <<a
href="mailto:dbaron@dbaron.org">dbaron@dbaron.org</a>>
<dt>Additional Contributors:
<dd>Original CSS2 Authors
<dd>Bert Bos (W3C), <<a href="mailto:bert@w3.org">bert@w3.org</a>>
<dd>Peter Linss (Netscape)
</dl>
<!--begin-copyright-->
<p class=copyright><a
href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright"
rel=license>Copyright</a> © 2012 <a href="http://www.w3.org/"><abbr
title="World Wide Web Consortium">W3C</abbr></a><sup>®</sup> (<a
href="http://www.csail.mit.edu/"><abbr
title="Massachusetts Institute of Technology">MIT</abbr></a>, <a
href="http://www.ercim.eu/"><abbr
title="European Research Consortium for Informatics and Mathematics">ERCIM</abbr></a>,
<a href="http://www.keio.ac.jp/">Keio</a>), All Rights Reserved. W3C <a
href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>,
<a
href="http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a>
and <a
href="http://www.w3.org/Consortium/Legal/copyright-documents">document
use</a> rules apply.</p>
<!--end-copyright-->
<hr title="Separator for header">
</div>
<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>.)
<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.
<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> 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>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>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>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>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>This document may be available in translations in the future. The
English version of this specification is the only normative version.
<h2 class="no-num no-toc" id=contents>Table of contents</h2>
<!--begin-toc-->
<ul class=toc>
<li><a href="#dependencies-on-other-modules"><span class=secno>1.
</span>Dependencies on other modules</a>
<li><a href="#introduction"><span class=secno>2. </span>Introduction</a>
<li><a href="#css-style-sheet-representation"><span class=secno>3.
</span>CSS style sheet representation</a>
<ul class=toc>
<li><a href="#referring-to-characters-not-represented-"><span
class=secno>3.1. </span>Referring to characters not represented in a
character encoding</a>
<li><a href="#the-textcss-content-type"><span class=secno>3.2.
</span>The text/css content type</a>
</ul>
<li><a href="#syntax"><span class=secno>4. </span>General syntax of
CSS</a>
<ul class=toc>
<li><a href="#characters"><span class=secno>4.1. </span>Characters and
case</a>
<li><a href="#tokenization"><span class=secno>4.2.
</span>Tokenization</a>
<li><a href="#grammar"><span class=secno>4.3. </span>Grammar</a>
<ul class=toc>
<li><a href="#principles-of-css-error-handling"><span
class=secno>4.3.1. </span>Principles of CSS error handling</a>
<li><a href="#style-sheets"><span class=secno>4.3.2. </span>Style
sheets</a>
</ul>
<li><a href="#keywords"><span class=secno>4.4. </span>Keywords</a>
<li><a href="#statements"><span class=secno>4.5. </span>Statements</a>
<li><a href="#at-rules"><span class=secno>4.6. </span>At-rules</a>
<li><a href="#blocks"><span class=secno>4.7. </span>Blocks</a>
<li><a href="#rule-sets-declaration-blocks-and-selecto"><span
class=secno>4.8. </span>Rule sets, declaration blocks, and
selectors</a>
<li><a href="#declarations"><span class=secno>4.9. </span>Declarations
and properties</a>
<li><a href="#comments"><span class=secno>4.10. </span>Comments</a>
</ul>
<li><a href="#error-handling"><span class=secno>5. </span>Rules for
handling parsing errors or unsupported features</a>
<ul class=toc>
<li><a href="#partial-implementations"><span class=secno>5.1.
</span>Partial implementations</a>
</ul>
<li><a href="#vendor-specific-extensions"><span class=secno>6.
</span>Vendor-specific extensions</a>
<ul class=toc>
<li><a href="#historical-notes"><span class=secno>6.1. </span>Historical
notes</a>
</ul>
<li><a href="#conf"><span class=secno>7. </span>Conformance</a>
<ul class=toc>
<li><a href="#definitions"><span class=secno>7.1. </span>Definitions</a>
<li><a href="#conf-UA"><span class=secno>7.2. </span>User agent
conformance</a>
<ul class=toc>
<li><a href="#error-conditions"><span class=secno>7.2.1. </span>Error
conditions</a>
</ul>
<li><a href="#conf-SS"><span class=secno>7.3. </span>Style sheet
conformance</a>
<li><a href="#conf-AT"><span class=secno>7.4. </span>Authoring tool
conformance</a>
</ul>
<li><a href="#property-defs"><span class=secno>8. </span>Format of
property definitions in other modules</a>
<ul class=toc>
<li><a href="#property-def-value"><span class=secno>8.1.
</span>Value</a>
<ul class=toc>
<li><a href="#initial-and-inherit-values"><span class=secno>8.1.1.
</span><code>initial</code> and <code>inherit</code> values</a>
</ul>
<li><a href="#property-def-initial"><span class=secno>8.2.
</span>Initial</a>
<li><a href="#property-def-applies"><span class=secno>8.3.
</span>Applies to</a>
<li><a href="#property-def-inherited"><span class=secno>8.4.
</span>Inherited</a>
<li><a href="#property-def-computed"><span class=secno>8.5.
</span>Computed value</a>
<li><a href="#property-def-percent"><span class=secno>8.6.
</span>Percentage values</a>
<li><a href="#media-groups"><span class=secno>8.7. </span>Media
groups</a>
<li><a href="#shorthand-properties"><span class=secno>8.8.
</span>Shorthand properties</a>
</ul>
<li><a href="#detailed-grammar"><span class=secno>9. </span>Appendix:
Second grammar</a>
<ul class=toc>
<li><a href="#grammar0"><span class=secno>9.1. </span>Grammar</a>
<li><a href="#lexical-scanner"><span class=secno>9.2. </span>Lexical
scanner</a>
</ul>
<li class=no-num><a href="#changes-from-css2">Changes from CSS2</a>
<li class=no-num><a href="#acknowledgments">Acknowledgments</a>
<li class=no-num><a href="#references">References</a>
<ul class=toc>
<li class=no-num><a href="#normative-references">Normative
references</a>
<li class=no-num><a href="#other-references">Other references</a>
</ul>
<li class=no-num><a href="#index">Index</a>
</ul>
<!--end-toc-->
<hr>
<h2 id=dependencies-on-other-modules><span class=secno>1.
</span>Dependencies on other modules</h2>
<p>This CSS3 module depends on the following other CSS3 modules:
<ul>
<li>Selectors <a href="#SELECT"
rel=biblioentry>[SELECT]<!--{{!SELECT}}--></a>
<li>CSS3 module: Values & Units <a href="#CSS3VAL"
rel=biblioentry>[CSS3VAL]<!--{{!CSS3VAL}}--></a>
<li>CSS3 module: Cascading & Inheritance <a href="#CSS3CASCADE"
rel=biblioentry>[CSS3CASCADE]<!--{{!CSS3CASCADE}}--></a>
</ul>
<p>It has non-normative (informative) references to the following other
CSS3 modules:
<ul>
<li>CSS3 module: Paged media <a href="#CSS3PAGE"
rel=biblioentry>[CSS3PAGE]<!--{{CSS3PAGE}}--></a>
<li>CSS3 module: Speech <a href="#CSS3SPEECH"
rel=biblioentry>[CSS3SPEECH]<!--{{CSS3SPEECH}}--></a>
<li>Media queries <a href="#MEDIAQ"
rel=biblioentry>[MEDIAQ]<!--{{MEDIAQ}}--></a>
<li>Syntax of CSS rules in HTML's "style" attribute <a
href="#CSSSTYLEATTR"
rel=biblioentry>[CSSSTYLEATTR]<!--{{CSSSTYLEATTR}}--></a>
</ul>
<h2 id=introduction><span class=secno>2. </span>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.
<h2 id=css-style-sheet-representation><span class=secno>3. </span>CSS style
sheet representation</h2>
<p>A CSS style sheet is a sequence of characters from the Universal
Character Set (see <a href="#ISO10646"
rel=biblioentry>[ISO10646]<!--{{!ISO10646}}--></a>). For transmission and
storage, these characters must be <dfn id=encoded
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 class=index id=BOM>byte order mark (BOM)</span>,
as described in section 2.7 of <a href="#UNICODE310"
rel=biblioentry>[UNICODE310]<!--{{!UNICODE310}}--></a>, 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 (<a href="#HTML40"
rel=biblioentry>[HTML40]<!--{{!HTML40}}--></a>, chapter 5). See also the
XML 1.0 specification (<a href="#XML10"
rel=biblioentry>[XML10]<!--{{XML10}}--></a>, sections 2.2 and 4.3.3).
<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>When a style sheet resides in a separate file, user agents must observe
the following <span class=index id=priorities
title="character encoding::user agent's determination of">priorities</span>
when determining a style sheet's <span class=index id=character-encoding
title="character encoding::default|default::character encoding">character
encoding</span> (from highest priority to lowest):
<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 (<a href="#HTTP11"
rel=biblioentry>[HTTP11]<!--{{!HTTP11}}--></a>, 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 <a class=index
href="#charset0" id=charset>@charset</a> rule.)
<li>The <dfn id=charset0>@charset</dfn> at-rule.
<li>Assume that the style sheet is UTF-8.
</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>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 <a href="#RFC2978"
rel=biblioentry>[RFC2978]<!--{{!RFC2978}}--></a>. Also, see <a
href="#CHARSETS" rel=biblioentry>[CHARSETS]<!--{{CHARSETS}}--></a> for a
complete list of charsets). For example:
<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>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.
<div class=issue>[Should this specification describe how to handle encoding
errors? Can a user agent ignore the <a
href="#charset0"><code>@charset</code></a> rule if it's wrong? What if the
user agent does not support the encoding used? Should this specification
describe how to handle a <a href="#charset0"><code>@charset</code></a>
rule that specifies a character encoding that is incompatible with the
family of encodings used to decode the <a
href="#charset0"><code>@charset</code></a> rule (and BOM) itself?]</div>
<!-- More examples of good encodings to use? -IJ -->
<!-- Encodings not to use? (cf. HTML 4.0) -IJ -->
<h3 id=referring-to-characters-not-represented-><span class=secno>3.1.
</span>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 <a
href="#character-escapes" title="backslash escapes">escaped</a> references
to ISO 10646 characters. These escapes serve the same purpose as numeric
character references in HTML or XML documents (see <a href="#HTML40"
rel=biblioentry>[HTML40]<!--{{!HTML40}}--></a>, 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 id=the-textcss-content-type><span class=secno>3.2. </span>The <dfn
id=textcss>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 id=message-entity
title="message entity">message entity,</dfn> is defined by MIME and HTTP
1.1 (see <a href="#RFC2045"
rel=biblioentry>[RFC2045]<!--{{!RFC2045}}--></a> and <a href="#HTTP11"
rel=biblioentry>[HTTP11]<!--{{!HTTP11}}--></a>). 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 (<a
href="#RFC2318" rel=biblioentry>[RFC2318]<!--{{!RFC2318}}--></a>).
<h2 id=syntax><span class=secno>4. </span>General syntax of CSS</h2>
<p>This section describes a grammar (and <dfn
id=forward-compatible-parsing>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>See the <a href="#characters">section on characters and case</a> for
information on case-sensitivity.
<p>These descriptions are normative.
<h3 id=characters><span class=secno>4.1. </span>Characters and case</h3>
<p> The following rules always hold:
<ul>
<li>
<p>All CSS style sheets are <span class=index id=case-insensitive
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>
<p>In CSS3, <dfn id=identifiers title=identifier>identifiers</dfn>
(including element names, classes, and IDs in selectors (see <a
href="#SELECT" rel=biblioentry>[SELECT]<!--{{!SELECT}}--></a> <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 <a href="#UNICODE310"
rel=biblioentry>[UNICODE310]<!--{{!UNICODE310}}--></a> and <a
href="#ISO10646" rel=biblioentry>[ISO10646]<!--{{!ISO10646}}--></a>.)
<li>
<p>In CSS3, a backslash (\) character indicates three types of <dfn
id=character-escapes title="backslash escapes">character escapes</dfn>.</p>
<p>First, inside a string (see <a href="#CSS3VAL"
rel=biblioentry>[CSS3VAL]<!--{{!CSS3VAL}}--></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>
<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 (<a href="#ISO10646"
rel=biblioentry>[ISO10646]<!--{{!ISO10646}}--></a>) 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>by providing exactly 6 hexadecimal digits: "\000026B" ("&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.</p>
<li>
<p>Backslash escapes are always considered to be part of an <a
href="#identifiers">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 id=tokenization><span class=secno>4.2. </span>Tokenization</h3>
<p class=issue>[This needs to be integrated with the selectors module. How
should that be done?]
<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>At the lexical level, CSS style sheets consist of a sequence of tokens.
Hexadecimal codes (e.g., <code>#x20</code>) refer to ISO 10646 (<a
href="#ISO10646" rel=biblioentry>[ISO10646]<!--{{!ISO10646}}--></a>). In
case of multiple matches, the longest match determines the token.
<p>The following productions are <em>parts</em> of tokens:
<p class=issue>[We need something to allow signs on integers. Do we need to
go as far as css3-selectors?]
<table>
<tbody>
<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:
<table>
<tbody>
<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 ‘<code class=css> 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. </code>
<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?]
<h3 id=grammar><span class=secno>4.3. </span>Grammar</h3>
<h4 id=principles-of-css-error-handling><span class=secno>4.3.1.
</span>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>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>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>Certain productions within the grammar are <dfn
id=error-handling-points>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 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>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>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>Some of the constraints of CSS are not expressed in the grammar. For
example, an <a href="#charset0"><code>@charset</code></a> 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.
<h4 id=style-sheets><span class=secno>4.3.2. </span>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 (‘<code class=css>)
represent CHAR tokens (see above). The sections that follow describe how
to use it.</code>
<p class=issue>[This might need better integration with the selectors
module, although maybe it’s ok.]
<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>
<tbody>
<tr>
<td>ruleset
<td>::=
<td>...
<tr>
<td>FAIL(ruleset)
<td>::=
<td>...
</table>
]</div>
<p><dfn id=comment>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