forked from w3c/csswg-drafts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOverview.src.html
More file actions
1873 lines (1550 loc) · 73 KB
/
Overview.src.html
File metadata and controls
1873 lines (1550 loc) · 73 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//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>CSS Values and Units Module Level 3</title>
<style type="text/css">
code, small { white-space: nowrap }
.say { color: gray; }
pre.value { font: inherit; white-space: pre-wrap; margin: 0; padding: 0; }
#propvalues td { text-align: right; }
#propvalues td + td { text-align: left; }
dt + dt::before { content: ", "; }
dt { display: inline; }
:not(code) var { font-style: normal; color: #005A9C; }
td > small { display: block; }
</style>
<link rel="stylesheet" type="text/css" href="../default.css">
<link href="../csslogo.ico" rel="shortcut icon" type="image/x-icon">
<link rel="stylesheet" type="text/css" href="http://www.w3.org/StyleSheets/TR/W3C-[STATUS].css">
</head>
<body class="h-entry">
<div class="head">
<!--logo-->
<h1 class="p-name">CSS Values and Units Module Level 3</h1>
<h2 class="no-num no-toc">[LONGSTATUS] <span class="dt-updated"><span class="value" title="[CDATE]">[DATE]</span></span></h2>
<dl>
<dt>This version:</dt>
<!--<dd><a class="u-url" href="[VERSION]">http://www.w3.org/TR/[YEAR]/CR-css3-values-[CDATE]/</a></dd>-->
<dd><a class="u-url" href="http://dev.w3.org/csswg/css-values/">http://dev.w3.org/csswg/css-values/</a></dd>
<dt>Latest version:</dt>
<dd><a href="[LATEST]">[LATEST]</a></dd>
<dt>Editor's draft:
<dd><a href="http://dev.w3.org/csswg/[SHORTNAME]/">http://dev.w3.org/csswg/[SHORTNAME]/</a>
<dt>Previous version:</dt>
<dd><a rel="previous" href="http://www.w3.org/TR/2013/CR-css3-values-20130730/">http://www.w3.org/TR/2013/CR-css3-values-20130730/</a></dd>
<dt>Issue Tracking:</dt>
<dd><a rel="issues" href="http://www.w3.org/Style/CSS/Tracker/products/33">http://www.w3.org/Style/CSS/Tracker/products/33</a>
<dt>Feedback:</dt>
<dd><a href="mailto:www-style@w3.org?subject=%5Bcss3-values%5D%20feedback">www-style@w3.org</a>
with subject line “<kbd>[css3-values] <var>… message topic …</var></kbd>”
(<a rel="discussion" href="http://lists.w3.org/Archives/Public/www-style/">archives</a>)
<dt>Editors:</dt>
<dd class="p-author h-card vcard">
<a class="p-name fn u-url url" rel="author"
href="mailto:howcome@opera.com">Håkon Wium Lie</a>
(<span class="p-org org">Opera Software</span>)
<dd class="p-author h-card vcard">
<a class="p-name fn u-url url" rel="author"
href="http://www.xanthir.com/contact">Tab Atkins</a>
(<span class="p-org org">Google</span>)
<dd class="p-author h-card vcard">
<a class="p-name fn u-url url" rel="author"
href="http://fantasai.inkedblade.net/contact">Elika J. Etemad</a>
(<span class="p-org org">Mozilla</span>)
</dl>
<!--copyright-->
<hr title="Separator for header">
</div>
<h2 class="no-num no-toc" id="abstract">Abstract</h2>
<p><span class="p-summary">This CSS3 module describes the common values and units that CSS
properties accept and the syntax used for describing them in CSS
property definitions.</span></p>
<h2 class="no-num no-toc" id="status">Status of this document</h2>
<!--status-->
<p>All features described in this specification that also
exist in CSS 2.1 [[!CSS21]] are intended to be backwards compatible.
If you notice a conflict between this draft and CSS 2.1 [[!CSS21]],
please inform the editors!
<p>The CR period will last at least until 4 May 2013. At the
time of publication, no test suite and implementation report have yet
been made. They will be made available from the <a
href="/Style/CSS/Test/" >CSS test suites page.</a> See the section <a
href="#cr-exit-criteria">“CR exit criteria”</a> for details.
<p>See the section <a href="#changes">“Changes”</a> for changes made
to this specification since the last Candidate Recommendation.
<p>The following features are at-risk and may be dropped during the
CR period: ''calc()'', ''toggle()'', ''attr()''.
<h2 class="no-num no-toc" id="contents">Table of contents</h2>
<!--toc-->
<h2>Introduction</h2>
<p>The value definition field of each CSS property can contain keywords,
data types (which appear between ''<'' and ''>''), and information on how
they can be combined.
Generic data types (<var><length></var> being the most widely used)
that can be used by many properties are described in this specification,
while more specific data types (e.g., <var><spacing-limit></var>)
are described in the corresponding modules.
<h3 id="placement">
Module Interactions</h3>
<p>This module replaces and extends the data type definitions in [[!CSS21]]
sections
<a href="http://www.w3.org/TR/CSS21/about.html#value-defs">1.4.2.1</a>,
<a href="http://www.w3.org/TR/CSS21/syndata.html#values">4.3</a>,
and <a href="http://www.w3.org/TR/CSS21/aural.html#aural-intro">A.2</a>.
<h2 id="value-defs">
Value Definition Syntax</h2>
<p>The syntax described here is used to define the set of valid values
for CSS properties. A property value can have one or more components.
<h3 id="component-types">
Component value types</h3>
<p>Component value types are designated in several ways:
<ol>
<li><a href="#keywords">keyword</a> values (such as ''auto'', ''disc'', etc.),
which appear literally, without quotes (e.g. <code>auto</code>)
<li>basic data types, which appear between ''<'' and ''>''
(e.g., <var><length></var>, <var><percentage></var>, etc.).
<li>types that have the same range of values as a property bearing
the same name
(e.g., <var><'border-width'></var> <var><'background-attachment'></var>, etc.).
In this case, the type name is the property name (complete with quotes)
between the brackets. Such a type does <em>not</em>
include <a href="#common-keywords">CSS-wide keywords</a> such as ''inherit''.
<li>non-terminals that do not share the same name as a property. In this
case, the non-terminal name appears between ''<'' and ''>'', as in
<var><spacing-limit></var>. Notice the distinction between
<var><border-width></var> and <var><'border-width'></var>:
the latter is defined as the value of the 'border-width' property,
the former requires an explicit expansion elsewhere.
The definition of a non-terminal is typically located near its first appearance
in the specification.
</ol>
<p>
Some property value definitions also include the slash (/),
the comma (,),
and/or parentheses as literals.
These represent their corresponding tokens.
Other non-keyword literal characters that may appear in a component value,
such as “+”,
must be written enclosed in single quotes.
<p>
All CSS properties also accept the <a href="#common-keywords">CSS-wide keyword values</a>
as the sole component of their property value.
For readability these are not listed explicitly in the property value syntax definitions.
For example, the full value definition of <a href="http://www.w3.org/TR/css3-background/#border-color">'border-color'</a>
is ''<color>{1,4} | inherit | initial | unset''
(even though it is listed as ''<color>{1,4}'').
<p class="note">
Note: This implies that, in general,
combining these keywords with other component values in the same declaration
results in an invalid declaration.
For example,
''background: url(corner.png) no-repeat, inherit;'' is invalid.
<h3 id="component-combinators">
Component value combinators</h3>
<p>Component values can be arranged into property values as follows:
<ul>
<li>Several juxtaposed words mean that all of them must occur, in the
given order.
<li>A double ampersand (&&) separates two or more components,
all of which must occur, in any order.
<li>A double bar (||) separates two or more options:
one or more of them must occur, in any order.
<li>A bar (|) separates two or more alternatives:
exactly one of them must occur.
<li>Brackets ([ ]) are for grouping.
</ul>
<p>Juxtaposition is stronger than the double ampersand, the double
ampersand is stronger than the double bar, and the double bar
is stronger than the bar. Thus, the following lines are equivalent:
<pre>
<!----> a b | c || d && e f
<!---->[ a b ] | [ c || [ d && [ e f ]]]</pre>
<h3 id="component-multipliers">
Component value multipliers</h3>
<p>Every type, keyword, or bracketed group may be followed by one of
the following modifiers:</p>
<ul>
<li>An asterisk (*) indicates that the preceding type, word, or
group occurs zero or more times.
<li>A plus (+) indicates that the preceding type, word, or group
occurs one or more times.
<li>A question mark (?) indicates that the preceding type, word, or
group is optional (occurs zero or one times).
<li>A single number in curly braces ({<var>A</var>})
indicates that the preceding type, word, or group occurs <var>A</var> times.
<li>A comma-separated pair of numbers in curly braces ({<var>A</var>,<var>B</var>})
indicates that the preceding type, word, or group occurs at least
<var>A</var> and at most <var>B</var> times.
The <var>B</var> may be omitted ({<var>A</var>,})
to indicate that there must be at least <var>A</var> repetitions,
with no upper bound on the number of repetitions.
<li>A hash mark (#) indicates that the preceding type, word, or
group occurs one or more times, separated by comma tokens.
It may optionally be followed by the curly brace forms, above,
to indicate precisely how many times the repetition occurs,
like ''<length>#{1,4}''.
</ul>
<p>For repeated component values (indicated by ''*'', ''+'', or ''#''), UAs must support at least 20 repetitions of the component. If a property value contains more than the supported number of repetitions, the declaration must be ignored as if it were invalid.</p>
<h3 id="component-whitespace">
Component values and white space</h3>
<p>Unless otherwise specified,
white space and/or comments may appear before, after, and/or between
components in a property value
or subcomponents in a <a href="#functional-notation">functional notation</a>
that is defined using these component
<a href="#component-combinators">combinators</a> and
<a href="#component-multipliers">multipliers</a>.
<p class=note>Note: In many cases, spaces will in fact be
<em>required</em> between components in order to distinguish them from
each other. For example, the value ''1em2em'' would be parsed as a
single <code>DIMEN</code> token with the number ''1'' and the identifier
''em2em'', which is an invalid unit. In this case, a space would be
required before the ''2'' to get this parsed as the two lengths ''1em''
and ''2em''.
<h3 id="value-examples">
Property value examples</h3>
<p>Below are some examples of properties with their corresponding value
definition fields
<div class=example>
<table class="data" id="propvalues">
<thead>
<tr><th>Property
<th>Value definition field
<th>Example value
</thead>
<tbody>
<tr><td>'orphans'
<td><integer>
<td>''3''
<tr><td>'text-align'
<td>left | right | center | justify
<td>''center''
<tr><td>'padding-top'
<td><length> | <percentage>
<td>''5%''
<tr><td>'outline-color'
<td><color> | invert
<td>''#fefefe''
<tr><td>'text-decoration'
<td>none | underline || overline || line-through || blink
<td>''overline underline''
<tr><td>'font-family'
<td>[ <family-name> | <generic-family> ]#
<td>''"Gill Sans", Futura, sans-serif''
<tr><td>'border-width'
<td>[ <length> | thick | medium | thin ]{1,4}
<td>''2px medium 4px''
<tr><td>'text-shadow'
<td>[ inset? && [ <length>{2,4} && <color>? ] ]# | none
<td>''3px 3px rgba(50%, 50%, 50%, 50%), lemonchiffon 0 0 4px inset''
<tr><td>'voice-pitch'
<td><pre class="value"><frequency> && absolute |
<!-- -->[[x-low | low | medium | high | x-high] ||
<!-- --> [<frequency> | <semitones> | <percentage>]]</pre>
<td>''-2st x-low''
</tbody>
</table>
</div>
<h2 id="textual-values">
Textual Data Types</h2>
<p>An <dfn>identifier</dfn> (or <dfn><ident></dfn>) is a sequence of characters conforming to
the <code>IDENT</code> token in the
<a href="http://www.w3.org/TR/CSS21/syndata.html#tokenization">grammar</a>. [[!CSS21]]
Identifiers cannot be quoted; otherwise they would be interpreted
as a string.
<h3 id="keywords">
Pre-defined Keywords</h3>
<p>In the value definition fields, keywords with a pre-defined meaning
appear literally. Keywords are CSS <i>identifiers</i> and are interpreted
case-insensitively within the ASCII range (i.e., [a-z] and [A-Z] are
equivalent).</p>
<div class="example">
<p>For example, here is the value definition for the 'border-collapse'
property:</p>
<pre>Value: collapse | separate</pre>
<p>And here is an example of its use:</p>
<pre>table { border-collapse: separate }</pre>
</div>
<h4 id="common-keywords">
CSS-wide keywords: ''initial'' and ''inherit''</h4>
<p>As defined <a href="#component-types">above</a>,
all properties accept the <dfn>CSS-wide keywords</dfn>,
which represent value computations common to all CSS properties.
<p>The <dfn>''inherit''</dfn> keyword is
<a href="http://www.w3.org/TR/CSS21/cascade.html#value-def-inherit">defined</a>
in [[!CSS21]].
<p>The <dfn>''initial''</dfn> keyword represents the specified value that
is designated as the property's initial value. [[CSS3CASCADE]]
<p>Other CSS specifications can define additional CSS-wide keywords.
For example, [[CSS3CASCADE]] adds an ''unset'' keyword to this set.
<!-- Make it easier to add CSS-wide keywords by defining a grammar production. -->
<h3 id='custom-idents'>
Author-defined Identifiers: the ''<custom-ident>'' type</h3>
<p>
Some properties accept arbitrary author-defined identifiers as a component value.
This generic data type is denoted by <dfn id="identifier-value"><var><custom-ident></var></dfn>,
and represents any valid CSS <i>identifier</i>
that does not otherwise appear as a pre-defined keyword in that property's value definition.
Such identifiers are fully case-sensitive,
even in the ASCII range
(e.g. ''example'' and ''EXAMPLE'' are two different, unrelated user-defined identifiers).
<p>
The <a href='#common-keywords'>CSS-wide keywords</a> are not valid <var><custom-ident>s</var>.
The ''default'' keyword is reserved
and is also not a valid <var><custom-ident>s</var>.
<p>
Reserved keywords are reserved in all ASCII case permutations.
<h3 id="strings">
Quoted Strings: the ''<string>'' type</h3>
<p>Strings are denoted by <dfn id="string-value"><var><string></var></dfn>
and consist of a sequence of characters delimited by double quotes or
single quotes. They correspond to the <code>STRING</code> token in the
<a href="http://www.w3.org/TR/CSS21/syndata.html#tokenization">grammar</a>.
[[!CSS21]]
<div class=example>
<p>Double quotes cannot occur inside double quotes, unless escaped
(as <code>"\""</code> or as <code>"\22"</code>). Analogously for single quotes (<code>'\''</code> or <code>'\27'</code>).
<pre>
<!-- -->content: "this is a 'string'.";
<!-- -->content: "this is a \"string\".";
<!-- -->content: 'this is a "string".';
<!-- -->content: 'this is a \'string\'.';</pre>
</div>
<p>It is possible to break strings over several lines, for aesthetic or
other reasons, but in such a case the newline itself has to be escaped
with a backslash (\). The newline is subsequently removed from the
string. For instance, the following two selectors are exactly the
same:</p>
<div class="example">
<p style="display:none">Example(s):</p>
<pre>
<!-- -->a[title="a not s\
<!-- -->o very long title"] {/*...*/}
<!-- -->a[title="a not so very long title"] {/*...*/}</pre>
</div>
<p>Since a string cannot directly represent a newline, to include a
newline in a string, use the escape "\A". (Hexadecimal A is the line
feed character in Unicode (U+000A), but represents the generic notion
of "newline" in CSS.)</p>
<h3 id="urls">
Resource Locators: the ''<url>'' type</h3>
<p>A <dfn>URL</dfn> is a pointer to a resource and is a
<a href="http://www.w3.org/TR/CSS21/syndata.html#uri">specially-parsed</a>
<a href="#functional-notation">functional notation</a> denoted by
<dfn id="url-value"><var><url></var></dfn>. It corresponds to the
<code>URI</code> token in the
<a href="http://www.w3.org/TR/CSS21/syndata.html#tokenization">grammar</a>.
[[!CSS21]]
<div class="example">
<p>Below is an example of a URL being used as a background image:
<pre>body { background: url("http://www.example.com/pinkish.gif") }</pre>
<p>The same example can be written without quotes:
<pre>body { background: url(http://www.example.com/pinkish.gif) }</pre>
</div>
<p class="note">Note that in some CSS syntactic contexts (as defined
by that context), a URL can be represented as a <var><string></var>
rather than by <var><URL></var>. An example of this is the
<a href="http://www.w3.org/TR/CSS21/cascade.html#at-import">''@import'' rule</a>.
<p>Parentheses, whitespace characters, single quotes (') and
double quotes (") appearing in a URL must be escaped with a backslash
so that the resulting value is a valid <code>URL</code> token,
e.g. ''url(open\(parens)'', ''url(close\)parens)''.
Depending on the type of URL, it might also be possible to write these
characters as URI-escapes (e.g. ''url(open%28parens)'' or
''url(close%29parens)'') as described in [[URI]].
Alternatively a URL containing such characters may be represented as
a quoted <a href="#strings">string</a> within the ''url()'' notation.
<p>In order to create modular style sheets that are not dependent on
the absolute location of a resource, authors should use relative URIs.
Relative URIs (as defined in [[!URI]]) are resolved to full URIs
using a base URI. RFC 3986, section 3, defines the normative
algorithm for this process. For CSS style sheets, the base URI is that
of the style sheet, not that of the source document.
<p>When a <i><url></i> appears in the computed value of a property,
it is resolved to an absolute URL, as described in the preceding
paragraph.
The computed value of a URI that the UA cannot resolve to an absolute
URI is the specified value.</p>
<div class="example">
<p>For example, suppose the following rule:
<pre>body { background: url("tile.png") }</pre>
<p>is located in a style sheet designated by the URL:</p>
<pre>http://www.example.org/style/basic.css</pre>
<p>The background of the source document's <var><body></var>
will be tiled with whatever image is described by the resource
designated by the URL:
<pre>http://www.example.org/style/tile.png</pre>
<p>The same image will be used regardless of the URL of the source
document containing the <var><body></var>.
</div>
<h2 id="numeric-types">
Numeric Data Types</h2>
<p>
Properties may restrict numeric values to some range.
If the value is outside the allowed range,
the declaration is invalid and must be <a href="http://www.w3.org/TR/CSS21/conform.html#ignore">ignored</a>.
<p>
CSS theoretically supports infinite precision and infinite ranges for all value types;
however in reality implementations have finite capacity.
UAs should support reasonably useful ranges and precisions.
<!--
The recommended minimum ranges and precision,
and the required rounding and clamping rules,
are given in <a href="#required-ranges">Appendix A</a>.
-->
<h3 id="integers">
Integers: the ''<integer>'' type</h3>
<p>Integer values are denoted by
<dfn id="integer-value"><var><integer></var></dfn>.
An <dfn>integer</dfn> is one or more decimal digits ''0'' through ''9''
and corresponds to a subset of the <code>NUMBER</code> token in the
<a href="http://www.w3.org/TR/CSS21/syndata.html#tokenization">grammar</a>.
The first digit of an integer may be immediately preceded by ''-'' or ''+''
to indicate the integer's sign.
<h3 id="numbers">
Numbers: the ''<number>'' type</h3>
<p>Number values are denoted by
<dfn id="number-value"><var><number></var></dfn>.
A <dfn>number</dfn> is either an <integer> or
zero or more decimal digits followed by a dot (.) followed by one or more decimal digits.
It corresponds to the <code>NUMBER</code> token in the
<a href="http://www.w3.org/TR/CSS21/syndata.html#tokenization">grammar</a>.
As with integers, the first character of a number may be immediately preceded by ''-'' or ''+''
to indicate the number's sign.
<h3 id="percentages">
Percentages: the ''<percentage>'' type</h3>
<p>A <dfn>percentage</dfn> value is denoted by
<dfn id="percentage-value"><var><percentage></var></dfn>,
and consists of a <i><number></i> immediately followed by a percent
sign ''%''. It corresponds to the <code>PERCENTAGE</code> token in the
<a href="http://www.w3.org/TR/CSS21/syndata.html#tokenization">grammar</a>.
<p>Percentage values are always relative to another value, for example a
length. Each property that allows percentages also defines the value to which
the percentage refers. The value may be that of another property for the same
element, a property for an ancestor element, or a value of the formatting
context (e.g., the width of a <i>containing block</i>). When a percentage
value is set for a property of the <i>root</i> element and the percentage
is defined as referring to the inherited value of some property, the
resultant value is the percentage times the <i>initial value</i> of that
property.</p>
<h3 id='dimensions'>
Numbers with Units: the ''<dimension>'' type</h3>
<p>
A <dfn data-export>dimension</dfn> value is denoted by
<dfn data-dfn-type=type><dimension></dfn>
and consists of a <i><number></i> representing the value
immediately followed by an <i><ident></i> representing the unit.
It corresponds to the <i><dimension-token</i> syntax production.
<p>
The <i><dimension></i> type is only used when writing very generic grammars;
in most cases, a more specific type based on the unit is used instead,
such as <i><length></i> or <i><time></i>.
<h2 id="lengths">
Distance Units: the ''<length>'' type</h2>
<p>Lengths refer to distance measurements and are denoted by
<dfn id="length-value"><var><length></var></dfn> in the
property definitions.
A length is a <i>dimension</i>.
However, for zero lengths the unit identifier is optional
(i.e. can be syntactically represented as the <var><number></var> ''0'').
<p>A <dfn>dimension</dfn> is a <i>number</i> immediately followed by a
unit identifier. It corresponds to the <code>DIMENSION</code> token in the
<a href="http://www.w3.org/TR/CSS21/syndata.html#tokenization">grammar</a>.
[[!CSS21]] Like keywords, unit identifiers are case-insensitive within
the ASCII range.
<p>Properties may restrict the length value to some range.
If the value is outside the allowed range, the declaration is invalid
and must be <a href="http://www.w3.org/TR/CSS21/conform.html#ignore">ignored</a>.
<p>While some properties allow negative length values, this may
complicate the formatting and there may be implementation-specific
limits. If a negative length value is allowed but cannot be supported,
it must be converted to the nearest value that can be supported.</p>
<p>In cases where the <!--FIXME: href--><a>used</a> length cannot be
supported, user agents must approximate it in the
<!--FIXME: href--><a>actual</a> value.
<p>There are two types of length units: relative and absolute.
<h3 id="relative-lengths">
Relative lengths</h3>
<p><dfn title="relative length">Relative length units</dfn> specify a
length relative to another length. Style sheets that use relative
units can more easily scale from one output environment to another.
<p>The relative units are:</p>
<table class="data">
<caption>Informative Summary of Relative Units</caption>
<thead>
<tr><th>unit<th>relative to
</thead>
<tbody>
<tr><td>''em''
<td>font size of the element
<tr><td>''ex''
<td><i>x-height</i> of the element's font
<tr><td>''ch''
<td>width of the "0" (ZERO, U+0030) glyph in the element's font
<tr><td>''rem''
<td>font size of the root element
<tr><td>''vw''
<td>1% of viewport's width
<tr><td>''vh''
<td>1% viewport's height
<tr><td>''vmin''
<td>1% of viewport's smaller dimension
<tr><td>''vmax''
<td>1% of viewport's larger dimension
</tbody>
</table>
<p>Child elements do not inherit the relative values as specified for
their parent; they inherit the <!--FIXME: href--><a>computed values</a>.
<h4 id="font-relative-lengths">
Font-relative lengths: the ''em'', ''ex'', ''ch'', ''rem'' units</h4>
<p>Aside from ''rem'' (which refers to the font-size of the root element),
the font-relative lengths refer to the font metrics of the
element on which they are used.
The exception is when they occur in the value of the 'font-size' property
itself, in which case they refer to the computed font metrics of the parent element
(or the computed font metrics corresponding to the initial values of the 'font'
property, if the element has no parent).
<dl>
<dt><dfn title="em">em unit</dfn>
<dd><p>Equal to the computed value of the 'font-size' property of
the element on which it is used.
<div class="example">
<p>The rule:</p>
<pre>h1 { line-height: 1.2em }</pre>
<p>means that the line height of <code>h1</code> elements will be
20% greater than the font size of <code>h1</code> element. On the
other hand:
<pre>h1 { font-size: 1.2em }</pre>
<p>means that the font size of <code>h1</code> elements will be 20%
greater than the computed font size inherited by <code>h1</code> elements.</p>
</div>
<dt><dfn title="ex">ex unit</dfn>
<dd><p>Equal to the used x-height of the <a href="http://www.w3.org/TR/css3-fonts/#first-available-font">first available font</a>. [[!CSS3-FONTS]]
The x-height is so called because it is often equal to the height of the lowercase "x".
However, an ''ex'' is defined even for fonts that do not contain an "x".
<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 must be assumed.
<dt><dfn title="ch">ch unit</dfn>
<dd><p>Equal to the used advance measure of the "0" (ZERO, U+0030) glyph
found in the font used to render it.
<dt><dfn title="rem">rem unit</dfn>
<dd><p>Equal to the computed value of 'font-size' on the root element.
<p>When specified on the 'font-size' property of the root element, the
''rem'' units refer to the property's <em>initial value</em>.</p>
</dl>
<h4 id="viewport-relative-lengths">
Viewport-percentage lengths: the ''vw'', ''vh'', ''vmin'', ''vmax'' units</h4>
<p>
The viewport-percentage lengths are relative to the size of the
<a href="http://www.w3.org/TR/CSS21/visudet.html#containing-block-details">initial containing block</a>.
When the height or width of the initial containing block is changed,
they are scaled accordingly.
However, when the value of 'overflow' on the root element is ''auto'',
any scroll bars are assumed not to exist.
<span class='note'>Note that the initial containing block's size is affected by the presence of scrollbars on the viewport.</span>
<p>
For paged media, the exact definition of the viewport-percentage lengths
is deferred to [[!CSS3PAGE]].
<dl>
<dt><dfn title="vw">vw unit</dfn>
<dd>Equal to 1% of the width of the initial containing block.
<div class="example">
<p>In the example below, if the width of the viewport is 200mm,
the font size of <code>h1</code> elements will be
16mm (i.e. (8×200mm)/100).
<pre>h1 { font-size: 8vw }</pre>
</div>
<dt><dfn title="vh">vh unit</dfn>
<dd>Equal to 1% of the height of the initial containing block.
<dt><dfn title="vmin">vmin unit</dfn>
<dd>Equal to the smaller of ''vw'' or ''vh''.
<dt><dfn title="vmax">vmax unit</dfn>
<dd>Equal to the larger of ''vw'' or ''vh''.
</dl>
<h3 id="absolute-lengths">
Absolute lengths: the ''cm'', ''mm'', ''in'', ''pt'', ''pc'', ''px'' units</h3>
<p>The <dfn>absolute length units</dfn> are fixed in relation to
each other and anchored to some physical measurement.
They are mainly useful when the output environment is known.
The absolute units consist of the physical units (in, cm, mm, pt, pc)
and the px unit:
<table class="data">
<thead>
<tr><th>unit<th>definition
</thead>
<tbody>
<tr><td>''cm''
<td>centimeters
<tr><td>''mm''
<td>millimeters
<tr><td>''in''
<td>inches; 1in is equal to 2.54cm
<tr><td>''px''
<td>pixels; 1px is equal to 1/96th of 1in
<tr><td>''pt''
<td>points; 1pt is equal to 1/72nd of 1in
<tr><td>''pc''
<td>picas; 1pc is equal to 12pt
</tbody>
</table>
<pre class="example">
h1 { margin: 0.5in } /* inches */
h2 { line-height: 3cm } /* centimeters */
h3 { word-spacing: 4mm } /* millimeters */
h4 { font-size: 12pt } /* points */
h4 { font-size: 1pc } /* picas */
p { font-size: 12px } /* px */</pre>
<p>For a CSS device, these dimensions are either anchored (i) by
relating the physical units to their physical measurements, or
(ii) by relating the pixel unit to the <i>reference pixel</i>.
For print media and similar high-resolution devices, the anchor unit
should be one of the standard physical units (inches, centimeters, etc).
For lower-resolution devices, and devices with unusual viewing distances,
it is recommended instead that the anchor unit be the pixel unit. For
such devices it is recommended that the pixel unit refer to the whole
number of device pixels that best approximates the reference pixel.
<p class="note">Note that if the anchor unit is the pixel unit,
the physical units might not match their physical measurements.
Alternatively if the anchor unit is a physical unit, the pixel
unit might not map to a whole number of device pixels.</p>
<p class="note">Note that this definition of the pixel unit and
the physical units differs from previous versions of CSS. In
particular, in previous versions of CSS the pixel unit and the
physical units were not related by a fixed ratio: the physical
units were always tied to their physical measurements while the
pixel unit would vary to most closely match the reference pixel.
(This change was made because too much existing content relies
on the assumption of 96dpi, and breaking that assumption breaks
the content.)
<p>The <dfn>reference pixel</dfn> is the
visual angle of one pixel on a device with a pixel density of 96dpi
and a distance from the reader of an arm's length. For a nominal arm's
length of 28 inches, the visual angle is therefore about 0.0213
degrees. For reading at arm's length, 1px thus corresponds to about
0.26 mm (1/96 inch).
<p>The image below illustrates the effect of viewing distance on
the size of a reference pixel: a reading distance of 71 cm
(28 inches) results in a reference pixel of 0.26 mm,
while a reading distance of 3.5 m (12 feet) results in
a reference pixel of 1.3 mm.
<div class="figure">
<p><img src="pixel1.png"
alt="This diagram illustrates how the definition of a pixel
depends on the users distance from the viewing surface
(paper or screen).
The image depicts the user looking at two planes, one
28 inches (71 cm) from the user, the second 140 inches
(3.5 m) from the user. An expanding cone is projected
from the user's eye onto each plane. Where the cone
strikes the first plane, the projected pixel is 0.26 mm
high. Where the cone strikes the second plane, the
projected pixel is 1.4 mm high.">
<p class="caption">Showing that pixels must become larger if the
viewing distance increases
</div>
<p>This second image illustrates the effect of a device's resolution
on the pixel unit: an area of 1px by 1px is covered by a single dot
in a low-resolution device (e.g. a typical computer display), while
the same area is covered by 16 dots in a higher resolution device
(such as a printer).
<div class="figure">
<p><img src="pixel2.png"
alt='This diagram illustrates the relationship between the
reference pixel and device pixels (called "dots" below).
The image depicts a high resolution (large dot density)
laser printer output on the left and a low resolution
monitor screen on the right. For the laser printer, one
square reference pixel is implemented by 16 dots. For
the monitor screen, one square reference pixel is
implemented by a single dot.'>
<p class="caption">Showing that more device pixels (dots) are needed to
cover a 1px by 1px area on a high-resolution device than on a low-res one
</div>
<h2 id="other-units">
Other Units</h2>
<h3 id="angles">
Angles: the ''<angle>'' type and ''deg'', ''grad'', ''rad'', ''turn'' units</h3>
<p>Angle values are <i>dimensions</i> denoted by
<dfn id="angle-value"><angle></dfn>.
The angle unit identifiers are:
<dl>
<dt><dfn title="deg">deg</dfn>
<dd>Degrees. There are 360 degrees in a full circle.
<dt><dfn title="grad">grad</dfn>
<dd>Gradians, also known as "gons" or "grades". There are 400 gradians
in a full circle.
<dt><dfn title="rad">rad</dfn>
<dd>Radians. There are 2π radians in a full circle.
<dt><dfn title="turn">turn</dfn>
<dd>Turns. There is 1 turn in a full circle.
</dl>
<p>For example, a right angle is '90deg' or '100grad' or '0.25turn' or
approximately '1.570796326794897rad'.</p>
<h3 id="time">
Times: the ''<time>'' type and ''s'', ''ms'' units</h3>
<p>Time values are <i>dimensions</i> denoted by
<dfn id="time-value"><time></dfn>.
The time unit identifiers are:
<dl>
<dt><dfn title="s">s</dfn>
<dd>Seconds.
<dt><dfn title="ms">ms</dfn>
<dd>Milliseconds. There are 1000 milliseconds in a second.
</dl>
<p>Properties may restrict the time value to some range.
If the value is outside the allowed range, the declaration is invalid
and must be <a href="http://www.w3.org/TR/CSS21/conform.html#ignore">ignored</a>.
<h3 id="frequency">
Frequencies: the ''<frequency>'' type and ''Hz'', ''kHz'' units</h3>
<p>Frequency values are <i>dimensions</i> denoted by
<dfn id="frequency-value"><frequency></dfn>.
The frequency unit identifiers are:</p>
<dl>
<dt><dfn title="Hz">Hz</dfn>
<dd>Hertz. It represents the number of occurrences per second.
<dt><dfn title="kHz">kHz</dfn>
<dd>KiloHertz. A kiloHertz is 1000 Hertz.
</dl>
<p>For example, when representing sound pitches, 200Hz (or 200hz)
is a bass sound, and 6kHz (or 6khz) is a treble sound.</p>
<h3 id="resolution">
Resolutions: the <var><resolution></var> type and ''dpi'', ''dpcm'', ''dppx'' units</h3>
<p>Resolution units are <i>dimensions</i> denoted by <dfn id="resolution-value"><resolution></dfn>. The resolution unit identifiers are:</p>
<dl>
<dt><dfn>dpi</dfn></dt>
<dd>dots per inch</dd>
<dt><dfn>dpcm</dfn></dt>
<dd>dots per centimeter</dd>
<dt><dfn>dppx</dfn></dt>
<dd>dots per ''px'' unit</dd>
</dl>
<p>The <var><resolution></var> unit represents the size of a single "dot" in a
graphical representation by indicating how many of these dots fit in a
CSS 'in', 'cm', or 'px'.
For uses, see e.g. the ''resolution'' media query in [[MEDIAQ]]
or the 'image-resolution' property defined in [[CSS3-IMAGES]].
<p class="note">Note that due to the 1:96 fixed ratio of CSS ''in'' to
CSS ''px'', ''1dppx'' is equivalent to ''96dpi''. This corresponds to
the default resolution of images displayed in CSS: see 'image-resolution'.
<div class="example">
<p>The following @media rule uses Media Queries [[MEDIAQ]] to assign
some special style rules to devices that use two or more device pixels
per CSS ''px'' unit:
<pre>@media (min-resolution: 2dppx) { ... }</pre>
</div>
<h2 id="defined-elsewhere">
Data Types Defined Elsewhere</h2>
<p>Some data types are defined in their own modules. The two common
ones are <var><color></var> and <var><image></var>.
<h3 id="colors">
Colors: the ''<color>'' type</h3>
<p>The <dfn id="color-value"><var><color></var></dfn> data type is
<a href="http://www.w3.org/TR/CSS21/syndata.html#color-units">defined</a>
in [[!CSS21]] and
<a href="http://www.w3.org/TR/css3-color/#colorunits">extended</a> in [[!CSS3COLOR]].
UAs that support CSS Color Level 3 or its successor must interpret <var><color></var>
as defined therein.
<h3 id="images">
Images: the ''<image>'' type</h3>
<p>The <dfn id="image-value"><var><image></var></dfn> data type is
defined herein as equivalent to <var><url></var>.
It is <a href="http://www.w3.org/TR/css3-images/#image-values">extended</a> in
[[!CSS3-IMAGES]]: UAs that support CSS Image Values Level 3 or its successor must interpret
<var><image></var> as defined therein.
<h3 id="position">
2D Positioning: the ''<position>'' type</h3>
<p>The <dfn id="position-value"><var><position></var></dfn> data type is
defined herein as equivalent to the <a href="http://www.w3.org/TR/CSS21/colors.html#propdef-background-position"><var><'background-position'></var></a> syntax defined in [[!CSS21]]. It specifies the position of a object area (e.g. background image) inside a positioning area (e.g. background positioning area).
It is <a href="http://www.w3.org/TR/css3-background/#the-background-position">extended</a> in
[[!CSS3BG]]: UAs that support CSS Backgrounds & Borders Level 3 or its successor must interpret
<var><position></var> as defined therein.
<h2 id="functional-notation">
Functional Notations</h2>
<p>
A <dfn>functional notation</dfn> is a type of component value
that can represent more complex types or invoke special processing.
The syntax starts with the name of the function
immediately followed by a left parenthesis
(i.e. a <code>FUNCTION</code> token)
followed by the argument(s) to the notation
followed by a right parenthesis.
White space is allowed, but optional, immediately inside the parentheses.
Functions can take multiple arguments,
which are formatted similarly to a CSS property value.
<p>
Some legacy functional notations, such as ''rgba()'', use commas unnecessarily,
but generally commas are only used to separate items in a list,
or pieces of a grammar that would be ambiguous otherwise.
If a comma is used to separate arguments,
whitespace is optional before and after the comma.
<div class="example">
<pre>
<!-- -->background: url(http://www.example.org/image);
<!-- -->color: rgb(100, 200, 50 );
<!-- -->content: counter(list-item) ". ";
<!-- -->width: calc(50% - 2em);</pre>
</div>
<h3 id="calc-notation">
Mathematical Expressions: ''calc()''</h3>
<p>The <dfn>calc()</dfn> function
allows mathematical expressions with addition (''+''), subtraction (''-''),
multiplication (''*''), and division (''/'') to be used
as component values. The ''calc()'' expression represents the result of the
mathematical calculation it contains, using standard operator precedence
rules. It can be used wherever
<var><length></var>,
<var><frequency></var>,
<var><angle></var>,
<var><time></var>,
<var><number></var>, or
<var><integer></var>
values are allowed.
Components of a ''calc()'' expression can be literal values,
''attr()'' or ''calc()'' expressions, or <var><percentage></var> values
that resolve to one of the preceding types.
<div class="example">
<pre>
section {
float: left;
margin: 1em; border: solid 1px;
width: calc(100%/3 - 2*1em - 2*1px);
}</pre>
</div>
<div class="example">
<pre>