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
1567 lines (1286 loc) · 60.3 KB
/
Overview.src.html
File metadata and controls
1567 lines (1286 loc) · 60.3 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; }
</style>
<link rel="stylesheet" type="text/css" href="../default.css">
<link rel="stylesheet" type="text/css" href="http://www.w3.org/StyleSheets/TR/W3C-[STATUS].css">
</head>
<body>
<div class="head">
<!--logo-->
<h1>CSS Values and Units Module Level 3</h1>
<h2 class="no-num no-toc">[LONGSTATUS] [DATE]</h2>
<dl>
<dt>This version:</dt>
<dd><a href="[VERSION]">[VERSION]</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 href="http://www.w3.org/TR/2011/WD-css3-values-20110906/">http://www.w3.org/TR/2011/WD-css3-values-20110906/</a></dd>
<dt>Issue Tracking:</dt>
<dd><a 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="http://lists.w3.org/Archives/Public/www-style/">www-style@w3.org</a> with subject line “<kbd>[[SHORTNAME]] <var>… message topic …</var></kbd>”
<dt>Editors:</dt>
<dd><a href="mailto:howcome@opera.com">Håkon Wium Lie</a> (Opera Software)
<dd><a href="http://www.xanthir.com/contact">Tab Atkins</a> (Google)
<dd><a href="http://fantasai.inkedblade.net/contact">Elika J. Etemad</a> (Mozilla)
</dl>
<!--copyright-->
<hr title="Separator for header">
</div>
<h2 class="no-num no-toc" id="abstract">Abstract</h2>
<p>This CSS3 module describes the common values and units that CSS
properties accept and the syntax used for describing them in CSS
property definitions.</p>
<h2 class="no-num no-toc" id="status">Status of this document</h2>
<!--status-->
<p>This specification is a <strong>Last Call Working Draft</strong>. All
persons are encouraged to review this document and <strong>send comments
to the <a href="http://lists.w3.org/Archives/Public/www-style/">www-style</a>
mailing list</strong> as described above. The <strong>deadline for
comments</strong> is <strong>29 March 2012</strong>.
<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 following features are at-risk and may be dropped during the
CR period: ''calc()'', ''cycle()'', ''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 located near its first appearance
in the specification.
</ol>
<p>Some property value definitions also include the slash (/) and/or the
comma (,) as literals. These represent their corresponding tokens.
<p>All CSS properties also accept the keyword values ''inherit'' and
''initial'' as their property value, but for readability these are not
listed explicitly in the property value syntax definitions. These
keywords cannot be combined with other component values in same
declaration; such a declaration is invalid. 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.
<li>A 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.
<li>A hash mark (#) indicates that the preceding type, word, or
group occurs one or more times, separated by comma tokens.
</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>Component values are specified in terms of tokens, as described in <a
href="http://www.w3.org/TR/CSS21/syndata.html#tokenization">Chapter 4</a>
of [[!CSS21]].
As the grammar allows spaces between tokens in the components of the
<code>value</code> production, spaces may appear between tokens in
property values.
<p class=note>Note: In many cases, spaces will in fact be
<em>required</em> between tokens 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>#
<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> 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 ''initial'' and ''inherit'' keywords,
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]]
<h3 id="identifiers">
User-defined Identifiers: the ''<identifier>'' type</h3>
<p>Some properties accept arbitrary user-defined identifiers as a
component value. This generic data type is denoted by
<dfn id="identifier-value"><var><identifier></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).
<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.</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>.
For unrestricted values, UAs must support at least up to ±2<sup>27</sup>-1;
unsupported values must be clamped to the closest supported value.
When arithmetic is performed with numeric types
(for example, in the calc() expression, or when doing unit conversions),
if the result is outside the UAs's supported range,
it must also be clamped to the closest supported value.
<p>
UAs must support at least 3 digits of precision after the decimal point in numeric values.
<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>.
Integers may be immediately preceded by ''-'' or ''+'' to indicate the
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 <var><integer></var>, 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>.
Like integers, numbers may also be immediately preceded by ''-'' or ''+''
to indicate the 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>,
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>
<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>. A zero length may be represented
instead as the <var><number></var> ''0''. (In other words,
for zero lengths the unit identifier is optional.)</p>
<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>viewport's width
<tr><td>''vh''
<td>viewport's height
<tr><td>''vmin''
<td>minimum of the viewport's height and width
</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 computed 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 font's x-height. 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 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'' units</h4>
<p>The viewport-percentage lengths are relative to the size of the initial
containing block. When the height or width of the viewport is changed,
they are scaled accordingly.
<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''.
</dl>
<p class='note'>Note that Paged Media defines how the initial containing block
transforms across varying page widths. This also affects these units.</p>
<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 frequency 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">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>Some values use a <dfn>functional notation</dfn> to type values and to lump values together.
The syntax starts with the name of the function
immediately followed by a left parenthesis
followed by the argument(s) to the notation
followed by a right parenthesis.
If a function takes a list of arguments,
the arguments are separated by a comma (',')
with optional whitespace before and after the comma.
<pre class="example">
<!-- -->background: url(http://www.example.org/image);
<!-- -->color: rgb(100, 200, 50 );
<!-- -->content: counter(list-item) ". ";
<!-- -->width: calc(50% - 2em);</pre>
<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.</p>
<p>
The computed value of a calc() expression is the expression
with all components computed,
with all multiplication/division subexpressions resolved,
and with all addition/subtraction subexpressions resolved where both sides are the same type.
<span class='note'>
Thus, the computed value of a calc() expression can be represented
as either a number
or a tuple of a dimension and a percentage.
</span>
<!-- http://lists.w3.org/Archives/Public/www-style/2010May/0001.html
This has notes on how we should handle things when calc() is extended to
handle unit mult/div. Related to this is <unit>mod<unit>, which can return
0 and thus introduce computed-time division-by-zero. -->
<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>
p {
margin: calc(1rem - 2px) calc(1rem - 1px);
}</pre>
</div>
<div class="example">
<p>The following sets the 'font-size' so that exactly 40em fits within the viewport, ensuring that roughly the same amount of text always fills the screen no matter the screen size.</p>
<pre>
:root {
font-size: calc(100vw / 40);
}</pre>
<p>If the rest of the design is specified using the ''rem'' unit, the entire layout will scale to match the viewport width.</p>
</div>
<div class='example'>
<p>
The following example stacks two centered background images,
with one offset slightly from the other.
<pre>
.foo {
background: url(top.png), url(bottom.png);
background-repeat: no-repeat;
background-position: calc(50% + 20px) calc(50% + 20px), 50% 50%;
}
</pre>
</div>
<div class='example'>
<p>
This example shows how to place color-stops on a gradient an equal distance from either end.
<pre>
.foo {
background-image: linear-gradient(to right, silver,
white 50px,
white calc(100% - 50px),
silver);
}
</pre>
</div>
<p>
Given the complexities of width and height calculations on table cells and table elements,
math expressions involving percentages for widths and heights on
table columns, table column groups, table rows, table row groups, and table cells
in both auto and fixed layout tables
MAY be treated as if 'auto' had been specified.
<h4 id='calc-syntax'>
Syntax</h4>
<p>The expression language of these functions is described by
the grammar and prose below.
<pre>
math : calc S*;
calc : "calc(" S* sum S* ")";
sum : product [ S+ [ "+" | "-" ] S+ product ]*;
product : unit [ S* [ "*" | "/" ] S* unit ]*;
unit : ["+"|"-"]? [ NUMBER | DIMENSION | PERCENTAGE | "(" S* sum S* ")" ];</pre>
<p class='note'>Note that the grammar requires spaces around binary ''+''
and ''-'' operators. The ''*'' and ''/'' operators do not require
spaces.</p>
<p>Additionally, the following redefinition is made to the informative
grammar appearing in
<a href="http://www.w3.org/TR/CSS2/grammar.html">CSS 2.1 Appendix G</a>:</p>
<pre>
term
: unary_operator?
[ NUMBER S* | PERCENTAGE S* | LENGTH S* | EMS S* | EXS S* | ANGLE S* |
TIME S* | FREQ S* ]
| STRING S* | IDENT S* | URI S* | hexcolor | function<ins> | math</ins>
;</pre>