-
Notifications
You must be signed in to change notification settings - Fork 708
/
Copy pathsyndata.html
1629 lines (1457 loc) · 72.7 KB
/
syndata.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//EN">
<html lang="en">
<head>
<title>Syntax and basic data types</title>
<link rel="stylesheet" href="style/default.css" type="text/css">
<link rel="stylesheet" href="https://www.w3.org/StyleSheets/TR/W3C-REC.css" type="text/css">
<link rel="prev" href="conform.html">
<link rel="next" href="selector.html">
<link rel="contents" href="cover.html#minitoc">
<link rel="CSS-properties" href="propidx.html" title="properties">
<link rel="index" href="indexlist.html" title="index">
<link rel="first" href="cover.html">
<style type="text/css">
span.colorsquare { float:left; width:5em; height:3em; text-align:center; padding:1.2em 0 .8em }
span.colorname { font-weight:bold }
div.colordiagram { width:25em; height:20em; margin:1em auto; font-family:Verdana,sans-serif; font-size:12px }
div.diagramrow { height:5em }
</style>
<style type="text/css">
.current,.proposed,span.delcurrent { background:#feb }
ins.proposed,span.insproposed { background:#bfb }
del.proposed,span.delproposed { background:#fbb }
span.insproposed { text-decoration:underline }
span.delproposed,span.delcurrent { text-decoration:line-through }
body>del,body>ins {display:block}
</style>
</head>
<body>
<div class="navbar">
<p><a href="conform.html">previous</a>
<a href="selector.html">next</a>
<a href="cover.html#minitoc">contents</a>
<a href="propidx.html">properties</a>
<a href="indexlist.html">index</a>
</div>
<hr class="navbar">
<h1><a name="q4.0">4 Syntax and basic data types</a></h1>
<div class="subtoc">
<p><strong>Contents</strong>
<ul class="toc">
<li class="tocline2"><a href="syndata.html#syntax" class="tocxref">4.1 Syntax</a>
<ul class="toc">
<li class="tocline3"><a href="syndata.html#tokenization" class="tocxref">4.1.1 Tokenization</a>
<li class="tocline3"><a href="syndata.html#keywords" class="tocxref">4.1.2 Keywords</a>
<ul class="toc">
<li class="tocline4"><a href="syndata.html#vendor-keywords" class="tocxref">4.1.2.1 Vendor-specific extensions</a>
<li class="tocline4"><a href="syndata.html#vendor-keyword-history" class="tocxref">4.1.2.2 Informative Historical Notes</a>
</ul>
<li class="tocline3"><a href="syndata.html#characters" class="tocxref">4.1.3 Characters and case</a>
<li class="tocline3"><a href="syndata.html#statements" class="tocxref">4.1.4 Statements</a>
<li class="tocline3"><a href="syndata.html#at-rules" class="tocxref">4.1.5 <span class="index-def" title="at-rule"> At-rules</span></a>
<li class="tocline3"><a href="syndata.html#block" class="tocxref">4.1.6 Blocks</a>
<li class="tocline3"><a href="syndata.html#rule-sets" class="tocxref">4.1.7 Rule sets, declaration blocks, and selectors</a>
<li class="tocline3"><a href="syndata.html#declaration" class="tocxref">4.1.8 Declarations and properties</a>
<li class="tocline3"><a href="syndata.html#comments" class="tocxref">4.1.9 Comments</a>
</ul>
<li class="tocline2"><a href="syndata.html#parsing-errors" class="tocxref">4.2 Rules for handling parsing errors</a>
<li class="tocline2"><a href="syndata.html#values" class="tocxref">4.3 Values</a>
<ul class="toc">
<li class="tocline3"><a href="syndata.html#numbers" class="tocxref">4.3.1 Integers and real numbers</a>
<li class="tocline3"><a href="syndata.html#length-units" class="tocxref">4.3.2 Lengths</a>
<li class="tocline3"><a href="syndata.html#percentage-units" class="tocxref">4.3.3 Percentages</a>
<li class="tocline3"><a href="syndata.html#uri" class="tocxref">4.3.4 URLs and URIs</a>
<li class="tocline3"><a href="syndata.html#counter" class="tocxref">4.3.5 Counters</a>
<li class="tocline3"><a href="syndata.html#color-units" class="tocxref">4.3.6 Colors</a>
<li class="tocline3"><a href="syndata.html#strings" class="tocxref">4.3.7 Strings</a>
<li class="tocline3"><a href="syndata.html#unsupported-values" class="tocxref">4.3.8 Unsupported Values</a>
</ul>
<li class="tocline2"><a href="syndata.html#charset" class="tocxref">4.4 CSS style sheet representation</a>
<ul class="toc">
<li class="tocline3"><a href="syndata.html#escaping" class="tocxref">4.4.1 Referring to characters not represented in a character encoding</a>
</ul>
</ul>
</div>
<!-- warning -->
<div> <input id=annoying-warning type=checkbox title="hide note"> <label for=annoying-warning>(hide)</label> <div class=annoying-warning> <p><strong>Note:</strong> Several sections of this specification have been updated by other specifications. Please, see <a href="https://www.w3.org/TR/CSS/#css" >"Cascading Style Sheets (CSS) — The Official Definition"</a> in the latest <cite>CSS Snapshot</cite> for a list of specifications and the sections they replace. <p>The CSS Working Group is also developing <a href="http://www.w3.org/TR/CSS22/" >CSS level 2 revision 2 (CSS 2.2).</a> </div> </div>
<!-- /warning -->
<h2>4.1 <a name="syntax">Syntax</a></h2>
<p>This section describes a grammar (and <a name="x0"><span class="index-def"
title="forward-compatible parsing"><dfn>forward-compatible
parsing</dfn></span></a> rules) common to any level of CSS (including
CSS 2.1). Future updates of CSS will adhere to this core syntax,
although they may add additional syntactic constraints.
</p>
<p>These descriptions are normative. They are also
complemented by the normative grammar rules presented in <a
href="grammar.html">Appendix G</a>.
</p>
<p>In this specification, the expressions "immediately before" or
"immediately after" mean with no intervening white space or comments.
<h3>4.1.1 <a name="tokenization">Tokenization</a></h3>
<p>All levels of CSS — level 1, level 2, and any future levels — use
the same core syntax. This allows UAs to parse (though not completely
understand) style sheets written in levels of CSS that did not 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.
The list of tokens for CSS is as follows. The definitions use Lex-style
regular expressions. Octal codes refer to ISO 10646 (<a href="refs.html#ref-ISO10646" rel="biblioentry" class="noxref"><span class="normref">[ISO10646]</span></a>). As in
Lex, in case of multiple matches, the longest match determines the token.
</p>
<table>
<thead>
<tr><th>Token </th><th>Definition</th></tr>
</thead>
<tr><td colspan=2><hr></td></tr>
<tr><td>IDENT </td><td><code><var>{ident}</var></code></td></tr>
<tr><td>ATKEYWORD </td><td><code>@<var>{ident}</var></code></td></tr>
<tr><td>STRING </td><td><code><var>{string}</var></code></td></tr>
<tr><td>BAD_STRING </td><td><code><var>{badstring}</var></code></td></tr>
<tr><td>BAD_URI </td><td><code><var>{baduri}</var></code></td></tr>
<tr><td>BAD_COMMENT </td><td><code><var>{badcomment}</var></code></td></tr>
<tr><td>HASH </td><td><code>#<var>{name}</var></code></td></tr>
<tr><td>NUMBER </td><td><code><var>{num}</var></code></td></tr>
<tr><td>PERCENTAGE </td><td><code><var>{num}</var>%</code></td></tr>
<tr><td>DIMENSION </td><td><code><var>{num}{ident}</var></code></td></tr>
<tr><td>URI </td><td><code>url\(<var>{w}{string}{w}</var>\)<br>
|url\(<var>{w}</var>([!#$%&*-\[\]-~]|<var>{nonascii}</var>|<var>{escape}</var>)*<var>{w}</var>\)</code></td></tr>
<tr><td>UNICODE-RANGE </td><td><code>u\+[0-9a-f?]{1,6}(-[0-9a-f]{1,6})?</code></td></tr>
<tr><td>CDO </td><td><code><!--</code></td></tr>
<tr><td>CDC </td><td><code>--></code></td></tr>
<tr><td>: </td><td><code>:</code></td></tr>
<tr><td>; </td><td><code>;</code></td></tr>
<tr><td>{ </td><td><code>\{</code></td></tr>
<tr><td>} </td><td><code>\}</code></td></tr>
<tr><td>( </td><td><code>\(</code></td></tr>
<tr><td>) </td><td><code>\)</code></td></tr>
<tr><td>[ </td><td><code>\[</code></td></tr>
<tr><td>] </td><td><code>\]</code></td></tr>
<tr><td>S </td><td><code>[ \t\r\n\f]+</code></td></tr>
<tr><td>COMMENT </td><td><code>\/\*[^*]*\*+([^/*][^*]*\*+)*\/</code></td></tr>
<tr><td>FUNCTION </td><td><code><var>{ident}</var>\(</code></td></tr>
<tr><td>INCLUDES </td><td><code>~=</code></td></tr>
<tr><td>DASHMATCH </td><td><code>|=</code></td></tr>
<tr><td>DELIM </td><td><var>any other character not matched by
the above rules, and neither a single nor a double quote</var>
</td></tr></table>
<p>The macros in curly braces ({}) above are defined as follows:
</p>
<table>
<thead>
<tr><th>Macro </th><th>Definition</th></tr>
</thead>
<tr><td colspan=2><hr></td></tr>
<tr><td>ident </td><td><code>[-]?<var>{nmstart}</var><var>{nmchar}*</var></code></td></tr>
<tr><td>name </td><td><code><var>{nmchar}+</var></code></td></tr>
<tr><td>nmstart </td><td><code>[_a-z]|<var>{nonascii}</var>|<var>{escape}</var></code></td></tr>
<tr><td>nonascii</td><td><code>[^\0-\237]</code></td></tr>
<tr><td>unicode </td><td><code>\\[0-9a-f]{1,6}(\r\n|[ \n\r\t\f])?</code></td></tr>
<tr><td>escape </td><td><code><var>{unicode}</var>|\\[^\n\r\f0-9a-f]</code></td></tr>
<tr><td>nmchar </td><td><code>[_a-z0-9-]|<var>{nonascii}</var>|<var>{escape}</var></code></td></tr>
<tr><td>num </td><td><code>[0-9]+|[0-9]*\.[0-9]+</code></td></tr>
<tr><td>string </td><td><code><var>{string1}</var>|<var>{string2}</var></code></td></tr>
<tr><td>string1 </td><td><code>\"([^\n\r\f\\"]|\\{nl}|<var>{escape}</var>)*\"</code></td></tr>
<tr><td>string2 </td><td><code>\'([^\n\r\f\\']|\\{nl}|<var>{escape}</var>)*\'</code></td></tr>
<tr><td>badstring </td><td><code><var>{badstring1}</var>|<var>{badstring2}</var></code></td></tr>
<tr><td>badstring1 </td><td><code>\"([^\n\r\f\\"]|\\{nl}|<var>{escape}</var>)*\\?</code></td></tr>
<tr><td>badstring2 </td><td><code>\'([^\n\r\f\\']|\\{nl}|<var>{escape}</var>)*\\?</code></td></tr>
<tr><td>badcomment </td><td><code><var>{badcomment1}</var>|<var>{badcomment2}</var></code></td></tr>
<tr><td>badcomment1 </td><td><code>\/\*[^*]*\*+([^/*][^*]*\*+)*</code></td></tr>
<tr><td>badcomment2 </td><td><code>\/\*[^*]*(\*+[^/*][^*]*)*</code></td></tr>
<tr><td>baduri </td><td><code><var>{baduri1}</var>|<var>{baduri2}</var>|<var>{baduri3}</var></code></td></tr>
<tr><td>baduri1 </td><td><code>url\(<var>{w}</var>([!#$%&*-~]|<var>{nonascii}</var>|<var>{escape}</var>)*<var>{w}</var></code></td></tr>
<tr><td>baduri2 </td><td><code>url\(<var>{w}</var><var>{string}</var><var>{w}</var></code></td></tr>
<tr><td>baduri3 </td><td><code>url\(<var>{w}</var><var>{badstring}</var></code></td></tr>
<tr><td>nl </td><td><code>\n|\r\n|\r|\f</code></td></tr>
<tr><td>w </td><td><code>[ \t\r\n\f]*</code></td></tr>
</table>
<div class="example"><P style="display:none">Example(s):</P>
<p>For example, the rule of the longest match means that
"<code>red--></code>" is tokenized as the IDENT "<code>red--</code>"
followed by the DELIM "<code>></code>", rather than as an IDENT
followed by a CDC.
</div>
<p>Below is the core syntax for CSS. The sections that follow describe
how to use it. <a href="grammar.html">Appendix G</a> describes a
more restrictive grammar that is closer to the CSS level 2 language.
Parts of style sheets that can be parsed according to this grammar but
not according to the grammar in Appendix G are among the parts that
will be ignored according to the <a href="#parsing-errors">rules for
handling parsing errors</a>.
</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* ':' S* value;
property : IDENT;
value : [ any | block | ATKEYWORD S* ]+;
any : [ IDENT | NUMBER | PERCENTAGE | DIMENSION | STRING
| DELIM | URI | HASH | UNICODE-RANGE | INCLUDES
| DASHMATCH | ':' | FUNCTION S* [any|unused]* ')'
| '(' S* [any|unused]* ')' | '[' S* [any|unused]* ']'
] S*;
unused : block | ATKEYWORD S* | ';' S* | CDO S* | CDC S*;
</pre>
<p>The "unused" production is not used in CSS and will not be used by
any future extension. It is included here only to help with error
handling. (See <a href="#parsing-errors">4.2 "Rules for handling
parsing errors."</a>)
<p><a name="comment">COMMENT</a> tokens do not occur
in the grammar (to keep it readable), but any number of these tokens
may appear anywhere outside other tokens. (Note, however, that a
comment before or within the @charset rule disables the @charset.)</p>
<p>The token S in the grammar above stands for <a
name="whitespace">white space</a>. Only the characters "space" (U+0020), "tab" (U+0009), "line feed" (U+000A), "carriage return" (U+000D), and
"form feed" (U+000C) can occur in white space. Other space-like characters,
such as "em-space" (U+2003) and "ideographic space" (U+3000), are never part of white space.
</p>
<p>The meaning of input that cannot be tokenized or parsed is
undefined in CSS 2.1.
</p>
<h3>4.1.2 <a name="keywords">Keywords</a></h3>
<p>Keywords have the form of <a
href="#value-def-identifier">identifiers.</a> Keywords must not be
placed between quotes ("..." or '...'). Thus,
</p>
<pre>
red
</pre>
<p>is a keyword, but
</p>
<pre>
"red"
</pre>
<p>is not. (It is a <a href="#strings">string</a>.) Other illegal examples:
<div class="illegal-example"><P style="display:none">Illegal example(s):</P>
<pre><code>
width: "auto";
border: "none";
background: "red";
</code></pre>
</div>
<h4>4.1.2.1 <a name="vendor-keywords">Vendor-specific extensions</a></h4>
<p>In CSS, identifiers may begin with '<code
class="css">-</code>' (dash) or '<code
class="css">_</code>' (underscore). Keywords
and <a href="#properties">property names</a> beginning
with <code class="css">-</code>' or '<code
class="css">_</code>' are reserved for vendor-specific extensions. Such vendor-specific extensions should have one of the following formats:
</p>
<pre>
'-' + vendor identifier + '-' + meaningful name
'_' + vendor identifier + '-' + meaningful name
</pre>
<div class="example"><P style="display:none">Example(s):</P>
<p>For example, if XYZ organization added a property to describe the color of the
border on the East side of the display, they might call it <span
class="css">-xyz-border-east-color</span>.
</p>
<p>Other known examples:</p>
<pre>
-moz-box-sizing
-moz-border-radius
-wap-accesskey
</pre>
</div>
<p>An initial dash or underscore is guaranteed never to be used in a property or keyword by any current or future level of CSS. Thus typical CSS implementations may not
recognize such properties and may ignore them according to the <a
href="#parsing-errors">rules for handling parsing errors</a>. However, because the initial dash or underscore is part of the grammar, CSS 2.1 implementers should always be able to use a CSS-conforming parser, whether or not they support any vendor-specific extensions.
</p>
<p>Authors should avoid vendor-specific extensions</p>
<h4>4.1.2.2 <a name="vendor-keyword-history">Informative Historical Notes</a></h4>
<p>This section is informative.</p>
<p>At the time of writing, the following prefixes are known to exist:</p>
<table border='1'>
<thead><tr><th>prefix</th><th>organization</th></tr></thead>
<tbody>
<tr><td><code>-ms-</code>, <code>mso-</code></td><td>Microsoft</td></tr>
<tr><td><code>-moz-</code></td><td>Mozilla</td></tr>
<tr><td><code>-o-</code>, <code>-xv-</code></td><td>Opera Software</td></tr>
<tr><td><code>-atsc-</code></td><td>Advanced Television Standards Committee</td></tr>
<tr><td><code>-wap-</code></td><td>The WAP Forum</td></tr>
<tr><td><code>-khtml-</code></td><td>KDE</td></tr>
<tr><td><code>-webkit-</code></td><td>Apple</td></tr>
<tr><td><code>prince-</code></td><td>YesLogic</td></tr>
<tr><td><code>-ah-</code></td><td>Antenna House</td></tr>
<tr><td><code>-hp-</code></td><td>Hewlett Packard</td></tr>
<tr><td><code>-ro-</code></td><td>Real Objects</td></tr>
<tr><td><code>-rim-</code></td><td>Research In Motion</td></tr>
<tr><td><code>-tc-</code></td><td>TallComponents</td></tr>
</tbody>
</table>
<h3>4.1.3 <a name="characters">Characters and case</a></h3>
<p> The following rules always hold:</p>
<ul>
<li> All CSS syntax is <a name="x1"><span class="index-inst" title="case
sensitivity">case-insensitive</span></a> within the ASCII
range (i.e., [a-z] and [A-Z] are equivalent), 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>
<li> In CSS, <span class="index-def"
title="identifier|identifier, definition of"><a
name="value-def-identifier"><dfn>identifiers</dfn></a></span>
(including element names, classes, and IDs in <a
href="selector.html">selectors</a>) can contain only the
characters [a-zA-Z0-9] and ISO 10646 characters U+00A0 and higher,
plus the hyphen (-) and the underscore (_); they cannot start with
a digit, two hyphens, or a hyphen followed by a digit.
Identifiers can also contain escaped characters and any ISO 10646
character as a numeric code (see next item).
<span class="example">For instance, the identifier "B&W?" may
be written as "B\&W\?" or "B\26 W\3F".</span>
<p>Note that Unicode is code-by-code equivalent to ISO 10646 (see
<a href="refs.html#ref-UNICODE" rel="biblioentry" class="noxref"><span class="normref">[UNICODE]</span></a> and <a href="refs.html#ref-ISO10646" rel="biblioentry" class="noxref"><span class="normref">[ISO10646]</span></a>).
</p>
</li>
<li> In CSS 2.1, a backslash (\) character can indicate one
of three types of <span class="index-def" title="backslash
escapes"> <a name="escaped-characters">character
escape.</a></span> Inside a CSS comment, a backslash stands for
itself, and if a backslash is immediately followed by the end of
the style sheet, it also stands for itself (i.e., a DELIM token).
<p>First, inside a <a href="#strings">string</a>, a backslash
followed by a newline is ignored (i.e., the string is deemed not
to contain either the backslash or the newline).
Outside a string, a backslash followed by a newline stands for
itself (i.e., a DELIM followed by a newline).
<p>Second, it cancels the meaning of special CSS characters.
Any character (except a
hexadecimal digit, linefeed, carriage return, or form feed)
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 cannot easily put in a document. In this case, the backslash
is followed by at most six hexadecimal digits (0..9A..F), which
stand for the ISO 10646 (<a href="refs.html#ref-ISO10646" rel="biblioentry" class="noxref"><span class="normref">[ISO10646]</span></a>)
character with that number, which must not be zero.
(It is undefined in CSS 2.1 what happens if a style sheet
<em>does</em> contain a character with Unicode codepoint zero.)
If a character in the range [0-9a-fA-F] 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 white space character): "\26 B" ("&B").
In this case, user agents should treat a "CR/LF" pair
(U+000D/U+000A) as a single white space character.</li>
<li>by providing exactly 6 hexadecimal digits: "\000026B" ("&B")</li>
</ol>
<p>In fact, these two methods may be combined. Only one white space
character is ignored after a hexadecimal escape. Note that this means
that a "real" space after the escape sequence must be
doubled.
</p>
<p>If the number is outside the range allowed by Unicode (e.g.,
"\110000" is above the maximum 10FFFF allowed in current Unicode),
the UA may replace the escape with the "replacement character"
(U+FFFD). If the character is to be displayed, the UA should show
a visible symbol, such as a "missing character" glyph (cf. <a
href="fonts.html#algorithm">15.2,</a> point 5).
</li>
<li class=note>Note: Backslash escapes are always
considered to be part of an <a
href="#value-def-identifier">identifier</a> or a string (i.e.,
"\7B" is not punctuation, even though "{" is, and "\32" is allowed
at the start of a class name, even though "2" is not).
<p>The identifier "te\st" is exactly the same identifier as "test".
</li>
</ul>
<h3>4.1.4 <a name="statements">Statements</a></h3>
<p> A CSS style sheet, for any level of CSS, consists of a list of
<a name="x5"><span class="index-inst" title="statements"><em>statements</em></span></a>
(see the <a href="#tokenization">grammar</a> above). There are two
kinds of statements: <a name="x6"><span
class="index-inst" title="at-rules"><em>at-rules</em></span></a>
and <a name="x7"><span class="index-inst" title="rule sets"><em>rule
sets.</em></span></a> There may be <a href="#whitespace">white space</a>
around the statements.
</p>
<h3>4.1.5 <span class="index-def" title="at-rule">
<a name="at-rules">At-rules</a></span></h3>
<p> At-rules start with an <dfn>at-keyword</dfn>, an '@' character
followed immediately by an <a
href="#value-def-identifier">identifier</a> (for example, '@import',
'@page').
</p>
<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.
</p>
<p>CSS 2.1 user agents must <span class="index-inst" title="ignore"><a name="x9"
href="#ignore">ignore</a></span> any <a
href="cascade.html#at-import">'@import'</a> rule that occurs inside a <a
href="#block">block</a> or after any non-ignored statement other than an <a name="x10"><span
class="index-inst">@charset</span></a> or an @import rule.
</p>
<div class="illegal-example"><P style="display:none">Illegal example(s):</P><p>
Assume, for example, that a CSS 2.1 parser encounters this style sheet:
</p>
<pre><code>
@import "subs.css";
h1 { color: blue }
@import "list.css";
</code></pre>
<p> The second '@import' is illegal according to CSS 2.1. The CSS 2.1 parser
<span class="index-inst" title="ignore"><a name="x11" href="#ignore">ignores</a></span>
the whole at-rule, effectively reducing the style sheet to:
</p>
<pre><code class="css">
@import "subs.css";
h1 { color: blue }
</code></pre>
</div>
<div class="illegal-example"><P style="display:none">Illegal example(s):</P><p>
In the following example, the second '@import' rule is invalid,
since it occurs inside a '@media' <a href="#block">block</a>.
</p>
<pre><code>
@import "subs.css";
@media print {
@import "print-main.css";
body { font-size: 10pt }
}
h1 {color: blue }
</code></pre>
<p>Instead, to achieve the effect of only importing a style sheet
for 'print' media, use the @import rule with media syntax, e.g.:
</p>
<pre><code class="css">
@import "subs.css";
@import "print-main.css" print;
@media print {
body { font-size: 10pt }
}
h1 {color: blue }
</code></pre>
</div>
<h3>4.1.6 <a name="block">Blocks</a></h3>
<p> A <a name="x12"><span class="index-inst" title="block"><em>block</em></span></a>
starts with a left curly brace ({) and ends with the matching right
curly brace (}). In between there may be any tokens, 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 <a name="x13"><span class="index-inst" title="string">string</span></a>.
See <a href="#tokenization">Tokenization</a> above for the definition
of a string.
</p>
<div class="illegal-example"><P style="display:none">Illegal example(s):</P>
<p> Here is an example of a block. Note that the right brace between
the double quotes does not match the opening brace of the block, and that the
second single quote is an <a href="#escaped-characters">escaped
character</a>, and thus does not match the first single quote:
</p>
<pre><code>
{ causta: "}" + ({7} * '\'') }
</code></pre>
<p>Note that the above rule is not valid CSS 2.1, but it is still
a block as defined above.
</p>
</div>
<h3>4.1.7 <a name="rule-sets">Rule sets, declaration blocks, and selectors</a></h3>
<p> A rule set (also called "rule") consists of a selector followed by
a declaration block.
</p>
<p> A <a name="x14"><span class="index-def"
title="declaration block"><dfn>declaration block</dfn></span></a>
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>
<p>The <a name="x15"><span class="index-def"
title="selector"><em>selector</em></span></a> (see also the section on <a
href="selector.html">selectors</a>) consists of everything up to (but
not including) the first left curly brace ({). A selector always goes
together with a declaration block. When a user agent cannot parse the selector (i.e., it
is not valid CSS 2.1), it must <span class="index-inst" title="ignore"><a name="x16"
href="#ignore">ignore</a></span> the selector and the following
declaration block (if any) as well.
</p>
<p>CSS 2.1 gives a special meaning to the comma (,) in
selectors. However, since it is not known if the comma may acquire
other meanings in future updates of CSS, the whole statement should
be <span class="index-inst" title="ignore"><a name="x17"
href="#ignore">ignored</a></span> if there is an error anywhere in the
selector, even though the rest of the selector may look reasonable in
CSS 2.1.
</p>
<div class=illegal-example><P style="display:none">Illegal example(s):</P>
<p>For example, since the "&" is not a valid token in a CSS 2.1
selector, a CSS 2.1 user agent must
<span class="index-inst" title="ignore"><a name="x18" href="#ignore">ignore</a></span>
the whole second line, and not set the color of H3 to red:
</p>
<pre><code>
h1, h2 {color: green }
h3, h4 & h5 {color: red }
h6 {color: black }
</code></pre>
</div>
<div class="example"><P style="display:none">Example(s):</P>
<p>Here is a more complex example. The first two pairs of curly braces
are inside a string, and do not mark the end of the selector. This is
a valid CSS 2.1 rule.
</p>
<pre><code class="css">
p[example="public class foo\
{\
private int x;\
\
foo(int x) {\
this.x = x;\
}\
\
}"] { color: red }
</code></pre>
</div>
<h3>4.1.8 <a name="declaration">Declarations</a> and <a
name="properties">properties</a></h3>
<p> A <a name="x19"><span class="index-def"
title="declaration"><dfn>declaration</dfn></span></a> is either empty or
consists of a <a name="x20"><span class="index-inst"
title="property">property name</span></a>, followed by a colon (:), followed by
a property value. Around each of these there may be <a
href="#whitespace">white space</a>.
</p>
<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 style="display:none">Example(s):</P><p>
Thus, the following rules:</p>
<pre><code class="css">
h1 { font-weight: bold }
h1 { font-size: 12px }
h1 { line-height: 14px }
h1 { font-family: Helvetica }
h1 { font-variant: normal }
h1 { font-style: normal }
</code></pre>
<p>are equivalent to:</p>
<pre><code class="css">
h1 {
font-weight: bold;
font-size: 12px;
line-height: 14px;
font-family: Helvetica;
font-variant: normal;
font-style: normal
}
</code></pre>
</div>
<p>A property name is an <a
href="#value-def-identifier">identifier</a>. Any token may occur
in the property value. Parentheses ("( )"), brackets ("[ ]"),
braces ("{ }"), single
quotes ('), and double quotes (") must come in matching
pairs, and semicolons not in strings must be <a
href="#escaped-characters">escaped</a>. Parentheses, brackets, and
braces may be nested. Inside the quotes, characters are parsed as a
string.
</p>
<p>The syntax of <a name="x21"><span class="index-def" title="value">values</span></a>
is specified separately for each property, but in any case, values are
built from identifiers, strings, numbers, lengths, percentages, URIs,
colors, etc.
</p>
<p>A user agent must <span class="index-inst" title="ignore"><a name="x22"
href="#ignore">ignore</a></span> a declaration with an invalid property
name or an invalid value. Every CSS property has its own syntactic
and semantic restrictions on the values it accepts.
</p>
<div class="illegal-example"><P style="display:none">Illegal example(s):</P><p>
For example, assume a CSS 2.1 parser encounters this style sheet:
</p>
<pre><code>
h1 { color: red; font-style: 12pt } /* Invalid value: 12pt */
p { color: blue; font-vendor: any; /* Invalid prop.: font-vendor */
font-variant: small-caps }
em em { font-style: normal }
</code></pre>
<p> The second declaration on the first line has an invalid value
'12pt'. The second declaration on the second line contains an
undefined property 'font-vendor'. The CSS 2.1 parser will <span
class="index-inst" title="ignore"><a name="x23" href="#ignore">ignore</a></span> these
declarations, effectively reducing the style sheet to:
</p>
<pre class="example"><code class="css">
h1 { color: red; }
p { color: blue; font-variant: small-caps }
em em { font-style: normal }
</code></pre>
</div>
<h3>4.1.9 <a name="comments">Comments</a></h3>
<p><a name="x24"><span class="index-inst" title="comments">Comments </span></a> begin
with the characters "/*" and end with the characters "*/". They may
occur anywhere outside other tokens,
and their contents have no influence on the rendering. Comments may
not be nested.
</p>
<p>CSS also allows the SGML comment delimiters ("<!--" and
"-->") in certain places defined by the grammar, 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 specification (<a href="refs.html#ref-HTML4" rel="biblioentry" class="noxref"><span class="informref">[HTML4]</span></a>) for more information.
</p>
<h2>4.2 <a name="parsing-errors">Rules for handling parsing
errors</a></h2>
<p>In some cases, user agents must ignore part of an illegal style
sheet. This specification defines <span class="index-def"
title="ignore"><a name="ignore"><dfn>ignore</dfn></a></span> to mean
that the user agent parses the illegal part (in order to find its
beginning and end), but otherwise acts as if it had not been there.
CSS 2.1 reserves for future updates of CSS all property:value combinations
and @-keywords that do not contain an identifier beginning with dash or
underscore. Implementations must ignore such combinations (other than those
introduced by future updates of CSS).
</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-inst" title="ignore"><a name="x26" href="#ignore">ignore</a></span> a <a
href="syndata.html#declaration">declaration</a> with an unknown
property. For example, if the style sheet is:
<pre class="illegal-example">
h1 { color: red; rotation: 70minutes }
</pre>
<p> the user agent will treat this as if the style sheet had been
</p>
<pre class="example"><code class="css">
h1 { color: red }
</code></pre>
</li>
<li id="illegalvalues"><strong>Illegal values.</strong> User agents must ignore a
declaration with an illegal value. For example:
<pre class="illegal-example"><code>
img { float: left } /* correct CSS 2.1 */
img { float: left here } /* "here" is not a value of 'float' */
img { background: "red" } /* keywords cannot be quoted */
img { border-width: 3 } /* a unit must be specified for length values */
</code></pre>
A CSS 2.1 parser would honor the first rule and
<span class="index-inst" title="ignore"><a name="x27" href="#ignore">ignore</a></span>
the rest, as if the style sheet had been:
<pre class="example"><code class="css">
img { float: left }
img { }
img { }
img { }
</code></pre>
<p>A user agent conforming to a future CSS specification may accept one or
more of the other rules as well.</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 name, colon (:), or
property 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>Malformed statements.</strong> User agents must handle
unexpected tokens encountered while parsing a statement by reading
until the end of the statement, while observing the rules for matching
pairs of (), [], {}, "", and '', and correctly handling escapes. For
example, a malformed statement may contain an unexpected closing brace
or at-keyword. E.g., the following lines are all ignored:
<pre>
p @here {color: red} /* ruleset with unexpected at-keyword "@here" */
@foo @bar; /* at-rule with unexpected at-keyword "@bar" */
}} {{ - }} /* ruleset with unexpected right brace */
) ( {} ) p {color: red } /* ruleset with unexpected right parenthesis */
</pre>
<li><strong>At-rules with unknown at-keywords.</strong> User agents must <span
class="index-inst" title="ignore"><a name="x28" href="#ignore">ignore</a></span>
an invalid at-keyword together with everything following it, up to the
end of the block that contains the invalid at-keyword, or up to and
including the next semicolon (;), or up to and including the next
block ({...}), whichever comes first. For example, consider the
following:
<pre class="illegal-example"><code>
@three-dee {
@background-lighting {
azimuth: 30deg;
elevation: 190deg;
}
h1 { color: red }
}
h1 { color: blue }
</code></pre>
<p> The '@three-dee' at-rule is not part of CSS 2.1. Therefore, the whole
at-rule (up to, and including, the third right curly brace) is <span
class="index-inst" title="ignore"><a name="x29" href="#ignore">ignored.</a></span> A
CSS 2.1 user agent <span class="index-inst" title="ignore"><a name="x30"
href="#ignore">ignores</a></span> it, effectively reducing the style sheet
to:</p>
<pre class="example"><code class="css">
h1 { color: blue }
</code></pre>
<p>Something inside an at-rule that is ignored because it is invalid,
such as an invalid declaration within an @media-rule, does not make
the entire at-rule invalid.
</p>
</li>
<li id=unexpected-eof><strong>Unexpected end of style sheet.</strong>
<p>
User agents must close all open constructs (for example: blocks, parentheses, brackets, rules, strings, and comments) at the end of the
style sheet. For example:
</p>
<pre class="illegal-example"><code>
@media screen {
p:before { content: 'Hello
</code></pre>
<p>
would be treated the same as:
</p>
<pre class="example"><code class="css">
@media screen {
p:before { content: 'Hello'; }
}
</code></pre>
<p>
in a conformant UA.
</p>
</li>
<li><strong>Unexpected end of string.</strong>
<p>
User agents must close strings upon reaching the end of a line
(i.e., before an unescaped line feed, carriage return or form
feed character), but
then drop the construct (declaration or rule) in which the string
was found. For example:
</p>
<pre><code>
p {
color: green;
font-family: 'Courier New Times
color: red;
color: green;
}
</code></pre>
<p>
...would be treated the same as:
</p>
<pre><code class="css">
p { color: green; color: green; }
</code></pre>
<p>
...because the second declaration (from 'font-family' to the
semicolon after 'color: red') is invalid and is dropped.
</p>
</li>
<li>See also <a href="#rule-sets">Rule sets, declaration blocks, and
selectors</a> for parsing rules for declaration blocks.
</li>
</ul>
<h2>4.3 <a name="values">Values</a></h2>
<h3>4.3.1 <a name="numbers">Integers and real numbers</a></h3>
<p>Some value types may have integer values (denoted by <span
class="index-def" title="<integer>::definition of"><a
name="value-def-integer" class="value-def"><integer></a></span>)
or real number values (denoted by <span class="index-def"
title="<number>::definition of"><a name="value-def-number"
class="value-def"><number></a></span>). Real numbers and
integers are specified in decimal notation only. An <integer>
consists of one or more digits "0" to "9". A <number> can either
be an <integer>, or it can be zero or more digits followed by a
dot (.) followed by one or more digits. Both integers and real numbers
may be preceded by a "-" or "+" to indicate the sign.
-0 is equivalent to 0 and is not a negative number.</p>
<p>Note that many properties that allow an integer or real number as a
value actually restrict the value to some range, often to a
non-negative value.
</p>
<h3>4.3.2 <a name="length-units">Lengths</a></h3>
<p>Lengths refer to distance measurements.</p>
<p> The format of a length value (denoted by <span class="index-def"
title="<length>::definition of"><a name="value-def-length"
class="value-def"><length></a></span> in this specification) is
a <a href="syndata.html#value-def-number" class="noxref"><span
class="value-inst-number"><number></span></a> (with or without a
decimal point) immediately followed by a unit identifier (e.g., px,
em, etc.). After a zero length, the unit identifier is optional.
</p>
<p> Some properties allow negative length values, but this may
complicate the formatting model and there may be
implementation-specific limits. If a negative length value cannot be
supported, it should be converted to the nearest value that can be
supported.
</p>
<p>If a negative length value is set on a property that does not allow
negative length values, the declaration is ignored.
</p>
<p>In cases where the <a href="cascade.html#usedValue">used</a>
length cannot be supported, user agents must approximate it in the
<a href="cascade.html#actual-value">actual value.</a>
<p><a name="absrel-units">There are two types of length units:
relative and absolute.</a> <a name="x34"><span class="index-def" title="relative
units"><em>Relative length</em></span></a> units specify a length relative
to another length property. Style sheets that use relative units
can more easily scale from one output environment
to another.
</p>
<p>Relative units are:</p>
<ul>
<li><strong>em</strong>: the <a href="fonts.html#propdef-font-size" class="noxref"><span class="propinst-font-size">'font-size'</span></a> of the relevant font</li>
<li><strong>ex</strong>: the <span class="descinst">'x-height'</span> of the relevant font</li>
</ul>
<div class="example"><P style="display:none">Example(s):</P>
<pre><code class="css">
h1 { margin: 0.5em } /* em */
h1 { margin: 1ex } /* ex */
</code></pre>
</div>
<p>The <span class="index-def" title="em (unit)|quad width"><a
name="em-width">'em'</a></span> unit is equal to the computed value of
the <a href="fonts.html#propdef-font-size" class="noxref"><span class="propinst-font-size">'font-size'</span></a> property of
the element on which it is used. The exception is when 'em' occurs in
the value of the 'font-size' property itself, in which case it refers
to the font size of the parent element. It may be used for vertical or
horizontal measurement. (This unit is also sometimes called the
quad-width in typographic texts.)
</p>
<p>The <span class="index-def" title="x-height|ex (unit)"><a
name="ex">'ex'</a></span> unit is defined by the element's first available
font.
The exception is when 'ex' occurs in the value of the <a href="fonts.html#propdef-font-size" class="noxref"><span
class="propinst-font-size">'font-size'</span></a> property, in which case
it refers to the 'ex' of the parent element.
<p>The <span class="descinst-x-height">'x-height'</span> is so called
because it is often equal to the height of the lowercase "x". However,
an 'ex' is defined even for fonts that do not contain an "x".</p>
<p>The x-height of a font can be found in different ways. Some fonts
contain reliable metrics for the x-height. If reliable font metrics are
not available, UAs may determine the x-height from the height of a
lowercase glyph. One possible heuristic is to look at how far the glyph
for the lowercase "o" extends below the baseline, and subtract that value
from the top of its bounding box. In the cases where it is impossible or
impractical to determine the x-height, a value of 0.5em should be used.</p>
<div class="example"><P style="display:none">Example(s):</P>
<p>The rule:
</p>
<pre><code class="css">
h1 { line-height: 1.2em }
</code></pre>
<p>means that the line height of "h1" elements will be 20% greater
than the font size of the "h1" elements. On the other hand:
</p>
<pre><code class="css">
h1 { font-size: 1.2em }
</code></pre>
<p>means that the font-size of "h1" elements will be 20% greater than
the font size inherited by "h1" elements.</p>
</div>
<p>When specified for the root of the <a href="conform.html#doctree">
document tree</a> (e.g., "HTML" in HTML), 'em' and 'ex' refer to
the property's <a href="about.html#initial-value">initial value</a>.
</p>
<p>Child elements do not inherit the relative values specified for
their parent; they inherit the <a
href="cascade.html#computed-value">computed values</a>.</p>
<div class="example"><P style="display:none">Example(s):</P><p>
In the following rules, the computed <a href="text.html#propdef-text-indent" class="noxref"><span
class="propinst-text-indent">'text-indent'</span></a> value of "h1" elements
will be 36px, not 45px, if "h1" is a child of the "body" element.
</p>
<pre><code class="css">
body {
font-size: 12px;
text-indent: 3em; /* i.e., 36px */
}
h1 { font-size: 15px }
</code></pre>
</div>
<p><a name="x39"><span class="index-def" title="absolute length"><em> Absolute