-
Notifications
You must be signed in to change notification settings - Fork 791
Expand file tree
/
Copy pathOverview.html
More file actions
executable file
·1410 lines (1051 loc) · 53.6 KB
/
Overview.html
File metadata and controls
executable file
·1410 lines (1051 loc) · 53.6 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
<
77FB
div data-line-number="871" class="react-line-number react-code-text" style="padding-right:16px">871872
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 profile="http://dublincore.org/documents/2008/08/04/dc-html/ ">
<title>CSS Cascading and Inheritance Level 3</title>
<link href="http://purl.org/dc/terms/" rel=schema.dcterms>
<link href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright"
rel=dcterms.rights>
<meta content="CSS Cascading and Inheritance Level 3" name=dcterms.title>
<meta content=text name=dcterms.type>
<meta content=2013-05-01 name=dcterms.date>
<meta content="Håkon Wium Lie" name=dcterms.creator>
<meta content="Elika J. Etemad" name=dcterms.creator>
<meta content="Tab Atkins Jr." name=dcterms.creator>
<meta content=W3C name=dcterms.publisher>
<meta content="http://dev.w3.org/csswg/css3-cascade/"
name=dcterms.identifier>
<link href="../default.css" rel=stylesheet type="text/css">
<link href="../csslogo.ico" rel="shortcut icon" type="image/x-icon">
<link href="http://www.w3.org/StyleSheets/TR/W3C-ED.css" rel=stylesheet
type="text/css">
<body>
<div class=head> <!--begin-logo-->
<p><a href="http://www.w3.org/"><img alt=W3C height=48
src="http://www.w3.org/Icons/w3c_home" width=72></a> <!--end-logo-->
<h1>CSS Cascading and Inheritance Level 3</h1>
<h2 class="no-num no-toc" id=longstatus-date>Editor's Draft 1 May 2013</h2>
<dl><!--
<dt>This version:
<dd><a href="http://dev.w3.org/csswg/css3-cascade/">http://www.w3.org/TR/2013/WD-css3-cascade-20130501/</a>
-->
<dt>Latest version:
<dd><a
href="http://www.w3.org/TR/css3-cascade/">http://www.w3.org/TR/css3-cascade/</a>
<dt>Editor's draft:
<dd><a
href="http://dev.w3.org/csswg/css3-cascade/">http://dev.w3.org/csswg/css3-cascade/</a>
<dt>Previous version:
<dd><a
href="http://www.w3.org/TR/2005/WD-css3-cascade-20051215/">http://www.w3.org/TR/2005/WD-css3-cascade-20051215/</a>
<dt>Feedback:
<dd><a
href="mailto:www-style@w3.org?subject=%5Bcss-cascade%5D%20feedback">www-style@w3.org</a>
with subject line “<kbd>[css-cascade] <var>… message topic
…</var></kbd>” (<a
href="http://lists.w3.org/Archives/Public/www-style/"
rel=discussion>archives</a>)
<dt>Editors:
<dd class=vcard> <a class="email fn"
href="mailto:howcome@opera.com">Håkon Wium Lie</a> (<span
class=org>Opera Software</span>)
<dd class=vcard> <a class="url fn"
href="http://fantasai.inkedblade.net/contact">Elika J. Etemad</a> (<span
class=org>Mozilla</span>)
<dd class=vcard> <a class="url fn"
href="http://www.xanthir.com/contact/">Tab Atkins Jr.</a> (<span
class=org>Google</span>)
</dl>
<!--begin-copyright-->
<p class=copyright><a
href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright"
rel=license>Copyright</a> © 2013 <a href="http://www.w3.org/"><abbr
title="World Wide Web Consortium">W3C</abbr></a><sup>®</sup> (<a
href="http://www.csail.mit.edu/"><abbr
title="Massachusetts Institute of Technology">MIT</abbr></a>, <a
href="http://www.ercim.eu/"><abbr
title="European Research Consortium for Informatics and Mathematics">ERCIM</abbr></a>,
<a href="http://www.keio.ac.jp/">Keio</a>, <a
href="http://ev.buaa.edu.cn/">Beihang</a>), All Rights Reserved. W3C <a
href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>,
<a
href="http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a>
and <a
href="http://www.w3.org/Consortium/Legal/copyright-documents">document
use</a> rules apply.</p>
<!--end-copyright-->
<hr title="Separator for header">
</div>
<h2 class="no-num no-toc" id=abstract>Abstract</h2>
<p> This CSS module describes how to collate style rules and assign values
to all properties on all elements. By way of cascading and inheritance,
values are propagated for all properties on all elements. <a
href="http://www.w3.org/TR/CSS/">CSS</a> is a language for describing the
rendering of structured documents (such as HTML and XML) on screen, on
paper, in speech, etc.
<h2 class="no-num no-toc" id=status-of-this-document> Status of this
document</h2>
<!--begin-status-->
<p>This is a public copy of the editors' draft. It is provided for
discussion only and may change at any moment. Its publication here does
not imply endorsement of its contents by W3C. Don't cite this document
other than as work in progress.
<p>The (<a
href="http://lists.w3.org/Archives/Public/www-style/">archived</a>) public
mailing list <a
href="mailto:www-style@w3.org?Subject=%5Bcss3-cascade%5D%20PUT%20SUBJECT%20HERE">
www-style@w3.org</a> (see <a
href="http://www.w3.org/Mail/Request">instructions</a>) is preferred for
discussion of this specification. When sending e-mail, please put the text
“css3-cascade” in the subject, preferably like this:
“[<!---->css3-cascade<!---->] <em>…summary of comment…</em>”
<p>This document was produced by the <a
href="http://www.w3.org/Style/CSS/members">CSS Working Group</a> (part of
the <a href="http://www.w3.org/Style/">Style Activity</a>).
<p>This document was produced by a group operating under the <a
href="http://www.w3.org/Consortium/Patent-Policy-20040205/">5 February
2004 W3C Patent Policy</a>. W3C maintains a <a
href="http://www.w3.org/2004/01/pp-impl/32061/status"
rel=disclosure>public list of any patent disclosures</a> made in
connection with the deliverables of the group; that page also includes
instructions for disclosing a patent. An individual who has actual
knowledge of a patent which the individual believes contains <a
href="http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential">Essential
Claim(s)</a> must disclose the information in accordance with <a
href="http://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure">section
6 of the W3C Patent Policy</a>.</p>
<!--end-status-->
<h2 class="no-num no-toc" id=table-of-contents> Table of contents</h2>
<!--begin-toc-->
<ul class=toc>
<li><a href="#introduction"><span class=secno>1. </span>Introduction</a>
<li><a href="#at-import"><span class=secno>2. </span> Importing style
sheets: the ‘<code class=css>@import</code>’ rule</a>
<ul class=toc>
<li><a href="#import-content-type"><span class=secno>2.1. </span>
Content-Type of imported stylesheets</a>
</ul>
<li><a href="#shorthand"><span class=secno>3. </span> Shorthand
Properties</a>
<ul class=toc>
<li><a href="#all-shorthand"><span class=secno>3.1. </span> Resetting
All Properties: the ‘<code class=css>all</code>’ property</a>
</ul>
<li><a href="#cascade-and-inheritance"><span class=secno>4. </span>
Cascading and Inheritance</a>
<ul class=toc>
<li><a href="#filter-declarations"><span class=secno>4.1. </span>
Filtering Declarations</a>
<li><a href="#cascade"><span class=secno>4.2. </span> Cascading
Declarations</a>
<ul class=toc>
<li><a href="#cascading-origins"><span class=secno>4.2.1. </span>
Cascading Origins</a>
<li><a href="#important-rules"><span class=secno>4.2.2. </span>
‘<code class=css>!important</code>’ rules</a>
<li><a href="#preshint"><span class=secno>4.2.3. </span> Precedence of
Non-CSS Presentational Hints</a>
<li><a href="#cascaded-value"><span class=secno>4.2.4. </span> The
Cascaded Value</a>
</ul>
<li><a href="#defaulting"><span class=secno>4.3. </span> Inheritance and
Defaulting</a>
<ul class=toc>
<li><a href="#initial"><span class=secno>4.3.1. </span> Initial value:
the ‘<code class=css>initial</code>’ keyword</a>
<li><a href="#inheritance"><span class=secno>4.3.2. </span>
Inheritance: the ‘<code class=css>inherit</code>’ keyword</a>
<li><a href="#default"><span class=secno>4.3.3. </span> Rolling back
the cascade: the ‘<code class=css>default</code>’ keyword</a>
</ul>
</ul>
<li><a href="#value-stages"><span class=secno>5. </span> Stages of Value
Computation</a>
<ul class=toc>
<li><a href="#specified"><span class=secno>5.1. </span> Finding the
specified value</a>
<li><a href="#computed"><span class=secno>5.2. </span> Finding the
computed value</a>
<li><a href="#used"><span class=secno>5.3. </span> Finding the used
value</a>
<li><a href="#actual"><span class=secno>5.4. </span> Finding the actual
value</a>
<li><a href="#stages-examples"><span class=secno>5.5. </span>
Examples</a>
</ul>
<li><a href="#conformance"><span class=secno>6. </span>Conformance</a>
<li><a href="#changes"><span class=secno>7. </span> Changes</a>
<ul class=toc>
<li><a href="#changes-2012"><span class=secno>7.1. </span> Changes since
the 15 December 2005 Working Draft</a>
</ul>
<li class=no-num><a href="#acknowledgments">Acknowledgments</a>
<li class=no-num><a href="#references">References</a>
<ul class=toc>
<li class=no-num><a href="#normative-references">Normative
references</a>
<li class=no-num><a href="#other-references">Other references</a>
</ul>
<li class=no-num><a href="#index">Index</a>
<li class=no-num><a href="#property-index">Property index</a>
</ul>
<!--end-toc-->
<hr>
<h2 id=introduction><span class=secno>1. </span>Introduction</h2>
<p> One of the fundamental design principles of CSS is <em>cascading</em>,
which allows several style sheets to influence the presentation of a
document. When different declarations try to set a value for the same
element/property combination, the conflicts must somehow be resolved.
<p> The opposite problem arises when no declarations try to set a the value
for an element/property combination. In this case, a value must be found
by way of <a href="#inherit"><em>inheritance</em></a> or by looking at the
property's <a href="#initial-value"><em>initial value</em></a>.
<p> The rules for finding the specified value for all properties on all
elements in the document are described in this specification. The rules
for finding the specified values in the page context and its margin boxes
are described in <a href="#CSS3PAGE"
rel=biblioentry>[CSS3PAGE]<!--{{CSS3PAGE}}--></a>.
<h2 id=at-import><span class=secno>2. </span> Importing style sheets: the
‘<a href="#lsquoatimportrsquo"><code class=css>@import</code></a>’
rule</h2>
<p> The <dfn id=lsquoatimportrsquo>‘<code
class=css>@import</code>’</dfn> rule allows users to import style rules
from other style sheets. Any ‘<a href="#lsquoatimportrsquo"><code
class=css>@import</code></a>’ rules must follow all ‘<code
class=css>@charset</code>’ rules and precede all other at-rules and rule
sets in a style sheet. The ‘<a href="#lsquoatimportrsquo"><code
class=css>@import</code></a>’ keyword must be followed by the URI of the
style sheet to include. A string is also allowed; it will be interpreted
as if it had url(…) around it.
<div class=example>
<p> The following lines are equivalent in meaning and illustrate both
‘<a href="#lsquoatimportrsquo"><code class=css>@import</code></a>’
syntaxes (one with ‘<code class=css>url()</code>’ and one with a bare
string):
<pre><!--
-->@import "mystyle.css";
<!--
-->@import url("mystyle.css");</pre>
</div>
<p> So that user agents can avoid retrieving resources for unsupported
media types, authors may specify media-dependent ‘<a
href="#lsquoatimportrsquo"><code class=css>@import</code></a>’ rules.
Such media-dependent imports include a comma-separated list of “media
queries” after the URI. In the absence of any media query, the import is
unconditional. (Specifying ‘<a href="#all"><code
class=css>all</code></a>’ for the medium has the same effect.) The UA
must import the style sheet if (and only if) the media condition evaluates
to true.
<div class=example>
<p> The following rules illustrate how ‘<a
href="#lsquoatimportrsquo"><code class=css>@import</code></a>’ rules
can be made media-dependent:
<pre><!--
-->@import url("fineprint.css") print;
<!--
-->@import url("bluish.css") projection, tv;
<!--
-->@import url("narrow.css") handheld and (max-width: 400px);</pre>
</div>
<p> The evaluation and full syntax of the expressions after the URL is
defined by the Media Queries specification <a href="#MEDIAQ"
93CD
rel=biblioentry>[MEDIAQ]<!--{{!MEDIAQ}}--></a>.
<p> When the same style sheet is imported or linked to a document in
multiple places, user agents must process (or act as though they do) each
link as though the link were to a separate style sheet.
<h3 id=import-content-type><span class=secno>2.1. </span> Content-Type of
imported stylesheets</h3>
<p> The processing of imported stylesheets depends on the actual type of
the linked resource. If the resource does not have <a
href="http://www.whatwg.org/specs/web-apps/current-work/multipage/fetching-resources.html#content-type">Content-Type
metadata</a>, or the host document is in <a
href="http://www.whatwg.org/specs/web-apps/current-work/multipage/infrastructure.html#quirks-mode">quirks
mode</a> and has the <a
href="http://www.whatwg.org/specs/web-apps/current-work/multipage/origin-0.html#same-origin">same
origin</a> as the imported stylesheet, the type of the linked resource is
<code>text/css</code>. Otherwise, the type is determined from its <a
href="http://www.whatwg.org/specs/web-apps/current-work/multipage/fetching-resources.html#content-type">Content-Type
metadata</a>.
<p> If the linked resource's type is <code>text/css</code>, it must be
interpreted as a CSS stylesheet. Otherwise, it must be interpreted as a
network error.
<h2 id=shorthand><span class=secno>3. </span> Shorthand Properties</h2>
<p> Some properties are <dfn id=shorthand-properties>shorthand
properties</dfn>, meaning that they allow authors to specify the values of
several properties with a single property. A shorthand property sets all
of its longhand sub-properties, exactly as if expanded in place.
<div class=example>
<p> For example, the CSS 2.1 ‘<code class=property>font</code>’
property is a shorthand property for setting ‘<code
class=property>font-style</code>’, ‘<code
class=property>font-variant</code>’, ‘<code
class=property>font-weight</code>’, ‘<code
class=property>font-size</code>’, ‘<code
class=property>line-height</code>’, and ‘<code
class=property>font-family</code>’ all at once. The multiple
declarations of this example:
<pre>
h1 {
font-weight: bold;
font-size: 12pt;
line-height: 14pt;
font-family: Helvetica;
font-variant: normal;
font-style: normal;
}</pre>
<p>can therefore be rewritten as
<pre>h1 { font: bold 12pt/14pt Helvetica }</pre>
</div>
<p> When values are omitted from a shorthand form, unless otherwise
defined, each "missing" sub-property is assigned its <a
href="#initial-value"><i>initial value</i></a>.
<p class=note> This means that a shorthand property declaration always sets
<em title="">all</em> of its subproperties, even those that are not
explicitly set. Carelessly used, this might result in inadvertently
resetting some sub-properties. Carefully used, a shorthand can guarantee a
"blank slate" by resetting sub-properties inadvertently cascaded from
other sources. For example, writing ‘<code class=css>background:
green</code>’ rather than ‘<code class=css>background-color:
green</code>’ ensures that the background color overrides any earlier
declarations that might have set the background to an image.
<p> In some cases, a shorthand might have different syntax or special
keywords that don't directly correspond to values of its sub-properties.
(In such cases, the shorthand will explicitly define the expansion of its
values.)
<p> If a shorthand is specified as one of the <a
href="http://www.w3.org/TR/css3-values/#common-keywords">CSS-wide
keywords</a>, it sets all of its sub-properties to that keyword. (Note
that these keywords cannot be combined with other values in a single
declaration, not even in a shorthand.)
<p> Declaring a shorthand property to be ‘<code
class=css>!important</code>’ is equivalent to declaring all of its
sub-properties to be "!important".
<h3 id=all-shorthand><span class=secno>3.1. </span> Resetting All
Properties: the ‘<a href="#all"><code class=css>all</code></a>’
property</h3>
<table class=propdef>
<tbody>
<tr>
<th>Name:
<td><dfn id=all>all</dfn>
<tr>
<th>Value:
<td>initial | inherit | default
<tr>
<th>Initial:
<td>See individual properties
<tr>
<th>Applies to:
<td>See individual properties
<tr>
<th>Inherited:
<td>See individual properties
<tr>
<th>Percentages:
<td>See individual properties
<tr>
<th>Media:
<td>See individual properties
<tr>
<th>Computed value:
<td>See individual properties
<tr>
<th>Animatable:
<td>See individual properties
</table>
<p> The ‘<a href="#all"><code class=css>all</code></a>’ property is a
shorthand that resets <em title="">all</em> CSS properties. It only
accepts the <a
href="http://www.w3.org/TR/css3-values/#common-keywords">CSS-wide
keywords</a>.
<div class=example>
<p> For example, if an author specifies ‘<code class=css>all:
default</code>’ on an element it will block all inheritance and reset
all properties, as if no rules appeared in the author level of the
cascade.
<p> This can be useful for the root element of a "widget" included in a
page, which does not wish to inherit the styles of the outer page.
</div>
<h2 id=cascade-and-inheritance><span class=secno>4. </span> Cascading and
Inheritance</h2>
<p> The cascading and inheritance process takes a set of declarations as
input, and outputs a specified value for each property on each element.
<h3 id=filter-declarations><span class=secno>4.1. </span> Filtering
Declarations</h3>
<p> In order to find the specified values, implementations must first
identify all declarations that apply to each element. A declaration
applies to an element if:
<ul>
<li> It belongs to a stylesheet that currently applies to this document.
<li> It is not qualified by a conditional rule <a href="#CSS3-CONDITIONAL"
rel=biblioentry>[CSS3-CONDITIONAL]<!--{{!CSS3-CONDITIONAL}}--></a> with a
false condition.
<li> It belongs to a ruleset whose selector matches the element. <a
href="#SELECT" rel=biblioentry>[SELECT]<!--{{!SELECT}}--></a> (Taking <a
href="http://www.w3.org/TR/selectors4/#scoping">scoping</a> into account,
if necessary.)
</ul>
<p> The declarations that apply form, for each property on each element, a
list of potential values. The next section, the cascade, prioritizes these
lists.
<h3 id=cascade><span class=secno>4.2. </span> Cascading Declarations</h3>
<p> The cascade algorithm takes an unordered list of declarations for a
given property on an element and sorts it by precedence as determined
below.
<p> User agents must sort declarations according to the following criteria,
in descending order of priority:
<dl>
<dt id=cascade-origin>Origin
<dd> The origin of a declaration is based on where it comes from and
whether or not it is declared ‘<code class=css>!important</code>’
(see below). The precedence of the various origins is, in descending
order:
<ol>
<li>Transition declarations <a href="#CSS3-TRANSITIONS"
rel=biblioentry>[CSS3-TRANSITIONS]<!--{{!CSS3-TRANSITIONS}}--></a>
<sup><a href="#animations-origin-note">[NOTE]</a></sup>
<li>Important user agent declarations
<li>Important user declarations
<li>Important override declarations <a href="#DOM-LEVEL-2-STYLE"
rel=biblioentry>[DOM-LEVEL-2-STYLE]<!--{{!DOM-LEVEL-2-STYLE}}--></a>
<li>Important author declarations
<li>Animation declarations <a href="#CSS3-ANIMATIONS"
rel=biblioentry>[CSS3-ANIMATIONS]<!--{{!CSS3-ANIMATIONS}}--></a>
<sup><a href="#animations-origin-note">[NOTE]</a></sup>
<li>Normal override declarations <a href="#DOM-LEVEL-2-STYLE"
rel=biblioentry>[DOM-LEVEL-2-STYLE]<!--{{!DOM-LEVEL-2-STYLE}}--></a>
<li>Normal author declarations
<li>Normal user declarations
<li>Normal user agent declarations
</ol>
<p class=note id=animations-origin-note> The precise ordering of
Transition and Animation declarations is still under <a
href="http://lists.w3.org/Archives/Public/www-style/2013Mar/0297.html">discussion</a>.
<p> Declarations from origins earlier in this list win over declarations
from later origins.
<dt id=cascade-scope>Scope
<dd> A declaration can be <dfn id=scoped>scoped</dfn> to a subtree of the
document so that it only affects its <dfn id=scoping-element>scoping
element</dfn> and that element's descendants. For example, <a
href="#HTML5" rel=biblioentry>[HTML5]<!--{{HTML5}}--></a> defines scoped
<code><style></code> elements, whose style sheets are scoped to the
element's parent.
<p> If the <a href="#scoping-element"><i>scoping elements</i></a> of two
declarations have an ancestor/descendant relationship, then for normal
rules the declaration whose <a href="#scoping-element"><i>scoping
element</i></a> is the descendant wins, and for important rules the
declaration whose <a href="#scoping-element"><i>scoping element</i></a>
is the ancestor wins.
<p class=issue> In this definition, an inner scope wins over an outer one
for normal rules, but for important rules the outer one gets the last
word, similar to how the UA/user/author levels relate to each other.
This allows outer scopes to set defaults that are then overridden, but
to override inner scopes in !important cases. An alternative definition
would be to repeat the same ordering for important rules, similar to how
override rules work. This means !important simply jumps everything up
over Animations.
<p> For the purpose of this step, all unscoped declarations are
considered to be <a href="#scoped"><i>scoped</i></a> to the root
element. Normal declarations from style attributes are considered to be
<a href="#scoped"><i>scoped</i></a> to the element with the attribute,
whereas important declarations from style attributes are considered to
be <a href="#scoped"><i>scoped</i></a> to the root element. <a
href="#CSSSTYLEATTR"
rel=biblioentry>[CSSSTYLEATTR]<!--{{!CSSSTYLEATTR}}--></a>
<p class=note> This odd handling of <code>!important</code> style
attribute declarations is to match the behavior defined in CSS Levels 1
and 2, where style attributes simply have higher specificity than any
other author rules. <a href="#CSS21"
rel=biblioentry>[CSS21]<!--{{CSS21}}--></a>
<dt id=cascade-specificity>Specificity
<dd> The <a href="http://www.w3.org/TR/selectors/#specificity">Selectors
module</a> <a href="#SELECT"
rel=biblioentry>[SELECT]<!--{{!SELECT}}--></a> describes how to compute
the specificity of a selector. For the purpose of this step, a ruleset
without a selector (such as the <a
href="http://www.w3.org/TR/css-style-attr/#interpret">contents of a style
attribute</a>) is considered to have a specificity higher than any
selector. The declaration belonging to a ruleset whose selector has the
highest specificity wins.
<dt id=cascade-order>Order of appearance.
<dd> Rules from imported style sheets are treated as if their stylesheets
were substituted in place of the ‘<a href="#lsquoatimportrsquo"><code
class=css>@import</code></a>’ rule. Stylesheets independently linked by
the originating document are treated as if they were concatenated in
linking order, as determined by the host document language. Style
attributes are treated as if their rulesets were concatenated in document
order, after any stylesheets. The last declaration wins.
</dl>
<p> The <dfn id=output-of-the-cascade>output of the cascade</dfn> is a
(potentially empty) sorted list of declarations for each property on each
element.
<h4 id=cascading-origins><span class=secno>4.2.1. </span> Cascading Origins</h4>
<p> Each style rule has an origin, which determines where it enters the
cascade. CSS defines three core origins:
<dl>
<dt id=cascade-origin-author>Author
<dd> The author specifies style sheets for a source document according to
the conventions of the document language. For instance, in HTML, style
sheets may be included in the document or linked externally.
<dt id=cascade-origin-user>User
<dd> The user may be able to specify style information for a particular
document. For example, the user may specify a file that contains a style
sheet or the user agent may provide an interface that generates a user
style sheet (or behaves as if it did).
<dt id=cascade-origin-ua>User agent
<dd> Conforming user agents must apply a default style sheet (or behave as
if they did). A user agent's default style sheet should present the
elements of the document language in ways that satisfy general
presentation expectations for the document language (e.g., for visual
browsers, the EM element in HTML is presented using an italic font). See
e.g. the <a
href="http://www.whatwg.org/specs/web-apps/current-work/multipage/rendering.html#the-css-user-agent-style-sheet-and-presentational-hints">HTML
user agent style sheet</a>.
</dl>
<p> Extensions to CSS define the following additional origins:
<dl>
<dt id=cascade-origin-override>Override
<dd> <a>DOM Level 2 Style</a> <a href="#DOM-LEVEL-2-STYLE"
rel=biblioentry>[DOM-LEVEL-2-STYLE]<!--{{!DOM-LEVEL-2-STYLE}}--></a>
defines an interface for "override" styles, which enter the cascade at a
higher level than other author rules.
<dt id=cascade-origin-animation>Animation
<dd> CSS Animations <a href="#CSS3-ANIMATIONS"
rel=biblioentry>[CSS3-ANIMATIONS]<!--{{CSS3-ANIMATIONS}}--></a> generate
"virtual" rules representing their effects when running.
<dt id=cascade-origin-transition>Transition
<dd> Like CSS Animations, CSS Transitions <a href="#CSS3-TRANSITIONS"
rel=biblioentry>[CSS3-TRANSITIONS]<!--{{CSS3-TRANSITIONS}}--></a>
generate "virtual" rules representing their effects when running.
</dl>
<p> In addition, several origins have twin origins defined the same way,
but which contain the ‘<code class=css>!important</code>’ rules.
<p> The normative list of CSS origins is defined in <a
href="#cascade-origin">a previous section</a>.
<h4 id=important-rules><span class=secno>4.2.2. </span> ‘<code
class=css>!important</code>’ rules</h4>
<p> CSS attempts to create a balance of power between author and user style
sheets. By default, rules in an author's style sheet override those in a
user's style sheet.
<p> However, for balance, an "!important" declaration takes precedence over
a normal declaration. Author and user style sheets may contain
"!important" declarations, with user "!important" rules overriding author
"!important" rules. This CSS feature improves accessibility of documents
by giving users with special requirements (large fonts, color
combinations, etc.) control over presentation.
<p> A declaration is "!important" if the last two tokens in its value are
the delimiter token ‘<code class=css>!</code>’ followed by the
identifier token ‘<code class=css>important</code>’. Declaring a
shorthand property (e.g., ‘<code class=property>background</code>’) to
be "!important" is equivalent to declaring all of its sub-properties to be
"!important".
<p> User agent stylesheets may also contain "!important" rules. These
override all author and user rules.
<div class=example>
<p> The first rule in the user's style sheet in the following example
contains an "!important" declaration, which overrides the corresponding
declaration in the author's style sheet. The second declaration will also
win due to being marked "!important". However, the third rule in the
user's style sheet is not "!important" and will therefore lose to the
second rule in the author's style sheet (which happens to set style on a
shorthand property). Also, the third author rule will lose to the second
author rule since the second rule is "!important". This shows that
"!important" declarations have a function also within author style
sheets.
<pre>
/* From the user's style sheet */
p { text-indent: 1em !important }
p { font-style: italic !important }
p { font-size: 18pt }
/* From the author's style sheet */
p { text-indent: 1.5em !important }
p { font: normal 12pt sans-serif !important }
p { font-size: 24pt }</pre>
</div>
<h4 id=preshint><span class=secno>4.2.3. </span> Precedence of Non-CSS
Presentational Hints</h4>
<p> The UA may choose to honor presentational hints in a source document's
markup, for example the <code>bgcolor</code> attribute or
<code><s></code> element in [[HTML]]. All document language-based
styling must be translated to corresponding CSS rules and either enter the
cascade at the user agent level or be treated as author level rules with a
specificity of zero placed at the start of the author style sheet. A
document language may define whether a presentational hint enters at the
UA or author level of the cascade; if so, the UA must behave accordingly.
For example, <a href="#SVG11" rel=biblioentry>[SVG11]<!--{{SVG11}}--></a>
maps its presentation attributes into the author level.
<p class=note> Presentational hints entering the cascade at the UA level
can be overridden by user styles. Presentational hints entering the
cascade at the author level can be overridden by the author's use of the
‘<a href="#default-keyword"><code class=css>default</code></a>’
keyword. Host languages should choose the appropriate level for
presentational hints with these considerations in mind.
<h4 id=cascaded-value><span class=secno>4.2.4. </span> The Cascaded Value</h4>
<p> The <dfn id=cascaded-value0>cascaded value</dfn> represents the result
of the cascade. It is the value of the highest declaration in the <a
href="#output-of-the-cascade"><i>output of the cascade</i></a> (after any
rollback steps have been performed, see below). If the <a
href="#output-of-the-cascade"><i>output of the cascade</i></a> is an empty
list, the <a href="#cascaded-value0"><i>cascaded value</i></a> is the
‘<a href="#inherit-keyword"><code class=css>inherit</code></a>’
keyword if the property is an <a href="#inherited-properties"><i>inherited
property</i></a> (as defined by its property definition table) or the
‘<a href="#initial-keyword"><code class=css>initial</code></a>’
keyword otherwise.
<h3 id=defaulting><span class=secno>4.3. </span> Inheritance and Defaulting</h3>
<p> In most cases, the <a href="#specified-value"><i>specified
value</i></a> is the <a href="#cascaded-value0"><i>cascaded value</i></a>.
However, the ‘<a href="#initial-keyword"><code
class=css>initial</code></a>’, ‘<a href="#inherit-keyword"><code
class=css>inherit</code></a>’, and ‘<a href="#default-keyword"><code
class=css>default</code></a>’ values are handled specially when they are
the <a href="#cascaded-value0"><i>cascaded value</i></a> of a property.
<h4 id=initial><span class=secno>4.3.1. </span> Initial value: the ‘<a
href="#initial-keyword"><code class=css>initial</code></a>’ keyword</h4>
<p> Each property has an <dfn id=initial-value>initial value</dfn>, defined
in the property's definition table. If the <a
href="#cascaded-value0"><i>cascaded value</i></a> is the <dfn
id=initial-keyword>‘<code class=css>initial</code>’</dfn> keyword, the
property's <a href="#initial-value"><i>initial value</i></a> becomes its
<a href="#specified-value"><i>specified value</i></a>.
<h4 id=inheritance><span class=secno>4.3.2. </span> Inheritance: the ‘<a
href="#inherit-keyword"><code class=css>inherit</code></a>’ keyword</h4>
<p> Some properties are <dfn id=inherited-properties
title="inherited property|inherited properties">inherited
properties</dfn>, as defined in their property definition table. This
means that, unless the cascade results in a value, the value will be
determined by inheritance.
<p> <dfn id=inherit>Inheritance</dfn> propagates property values from
parent elements to their children. The <dfn id=inherited-value>inherited
value</dfn> of a property on an element is the <a
href="#computed-value"><i>computed value</i></a> of the property on the
element's parent element. For the root element, which has no parent
element, the <a href="#inherited-value"><i>inherited value</i></a> is the
<a href="#initial-value"><i>initial value</i></a> of the property.
<p> Pseudo-elements inherit according to a fictional tag sequence described
for each pseudo-element <a href="#SELECT"
rel=biblioentry>[SELECT]<!--{{!SELECT}}--></a>.
<p class=note> Note that inheritance follows the document tree and is not
intercepted by <a
href="http://www.w3.org/TR/CSS21/visuren.html#box-gen">anonymous
boxes</a>, or otherwise affected by manipulations of the box tree.
<p> If the <a href="#cascaded-value0"><i>cascaded value</i></a> of a
property is the <dfn id=inherit-keyword>‘<code
class=css>inherit</code>’</dfn> keyword, the <a
href="#inherited-value"><i>inherited value</i></a> becomes the property's
<a href="#specified-value"><i title="specified value">specified</i></a>
and <a href="#computed-value"><i>computed values</i></a>.
<h4 id=default><span class=secno>4.3.3. </span> Rolling back the cascade:
the ‘<a href="#default-keyword"><code class=css>default</code></a>’
keyword</h4>
<p> CSS Cascading and Inheritance Level 3 introduces the <dfn
id=default-keyword>‘<code class=css>default</code>’</dfn> keyword as a
<a href="http://www.w3.org/TR/css3-values/#common-keywords">CSS-wide
keyword</a> accepted by all properties.
<p> If the <a href="#cascaded-value0"><i>cascaded value</i></a> is the
‘<a href="#default-keyword"><code class=css>default</code></a>’
keyword, then all declarations in the origin level to which it belongs are
discarded from the cascade, resulting in a new <a
href="#cascaded-value0"><i>cascaded value</i></a>. For this purpose, all
author-originating styles (author and override, both normal and important)
are treated as belonging to the same origin level. This continues until
the <a href="#cascaded-value0"><i>cascaded value</i></a> is not ‘<a
href="#default-keyword"><code class=css>default</code></a>’ or until the
<a href="#output-of-the-cascade"><i>output of the cascade</i></a> is
empty.
<p class=issue> This definition might need tweaking to sensibly handle
animations. See <a
href="http://lists.w3.org/Archives/Public/www-style/2012Dec/0270.html">dbaron's
message</a>.
<p class=issue> The ‘<a href="#default-keyword"><code
class=css>default</code></a>’ keyword exposes the exact origin
structure, which was previously only indirectly observable. As a result,
we can never again change what origin a given declaration is in, such as
by splitting one origin into multiple smaller origins. Already, ‘<a
href="#default-keyword"><code class=css>default</code></a>’ explicitly
groups several author-level origins. Should we do more grouping like this?
<h2 id=value-stages><span class=secno>5. </span> Stages of Value
Computation</h2>
<p> Once a user agent has parsed a document and constructed a document
tree, it must assign, to every element in the tree, and correspondingly to
every box in the formatting structure, a value to every property that
applies to the target media type.
<p> The final value of a CSS3 property for a given element or box is the
result of a four-step calculation:
<ul>
<li> First, cascading and inheritance yields the <a
href="#specified-value"><i>specified value</i></a>.
<li> Second, relative values are computed into absolute values as far as
possible without formatting the document, thereby yielding the <a
href=&qu
5E30
ot;#computed-value"><i>computed value</i></a>.
<li> The computed value is transformed into the <a
href="#used-value"><i>used value</i></a> in the formatting process.
<li> Finally, the computed value is transformed to the <a
href="#actual-value"><i>actual value</i></a> based on constraints of
local environment.
</ul>
<h3 id=specified><span class=secno>5.1. </span> Finding the specified value</h3>
<p> The <dfn id=specified-value>specified value</dfn> is the output of the
<a href="#cascade-and-inheritance">cascading and inheritance process</a>.
<p> The cascading and inheritance process guarantees that a <a
href="#specified-value"><i>specified value</i></a> exists for every
property on every element.
<h3 id=computed><span class=secno>5.2. </span> Finding the computed value</h3>
<p> A <a href="#specified-value"><i>specified value</i></a> can be either
absolute (i.e., not relative to another value, as in ‘<code
class=property>red</code>’ or ‘<code class=css>2mm</code>’) or
relative (i.e., relative to another value, as in ‘<code
class=property>auto</code>’, ‘<code class=css>2em</code>’).
<p> For absolute values, no extra processing is needed to find the computed
value. For relative values, on the other hand, computation is necessary to
find the computed value: percentages must be multiplied by a reference
value (each property defines which value that is), values with relative
units (em, ex, vh, vw) must be made absolute by multiplying with the
appropriate reference size, certain keywords (e.g., ‘<code
class=property>smaller</code>’, ‘<code
class=property>bolder</code>’) must be replaced according to their
definitions, and valid relative URLs must be resolved to become absolute.
See examples (f), (g) and (h) in the <a href="#stages-examples">table
below</a>.
<p> The <dfn id=computed-value>computed value</dfn> is the result of
resolving the <a href="#specified-value"><i>specified value</i></a> as
defined in the "Computed Value" line of the property definition table.
Generally, this means resolving the <a
href="#specified-value"><i>specified value</i></a> insofar as possible
without formatting the document.
<p class=note> The <a href="#computed-value"><i>computed value</i></a> is
the value that is transferred from parent to child during <a
href="#inherit"><i>inheritance</i></a>.
<p> The <a href="#computed-value"><i>computed value</i></a> exists even
when the property does not apply (as defined by the "Applies To" line).
However, some properties may define the <a
href="#computed-value"><i>computed value</i></a> of a property for an
element to depend on whether the property applies to that element.
<h3 id=used><span class=secno>5.3. </span> Finding the used value</h3>
<p> <a href="#computed-value"><i>Computed values</i></a> are processed as
far as possible without formatting the document. Some values, however, can
only be determined when the document is being laid out. For example, if
the width of an element is set to be a certain percentage of its
containing block, the width cannot be determined until the width of the
containing block has been determined. The <dfn id=used-value>used
value</dfn> is the result of taking the <a
href="#computed-value"><i>computed value</i></a> and resolving any
remaining dependencies into an absolute value.
<h3 id=actual><span class=secno>5.4. </span> Finding the actual value</h3>
<p> A <a href="#used-value"><i>used value</i></a> is in principle ready to
be used, but a user agent may not be able to make use of the value in a
given environment. For example, a user agent may only be able to render
borders with integer pixel widths and may therefore have to approximate
the computed width. Also, the font size of an element may need adjustment
based on the availability of fonts or the value of the ‘<code
class=property>font-size-adjust</code>’ property. The <dfn
id=actual-value>actual value</dfn> is the used value after any such
approximations have been made.
<p class=note> By probing the actual values of elements, much can be
learned about how the document is laid out. However, not all information
is recorded in the actual values. For example, the actual value of the
‘<code class=property>page-break-after</code>’ property does not
reflect whether there is a page break or not after the element. Similarly,
the actual value of ‘<code class=property>orphans</code>’ does not
reflect how many orphan lines there is in a certain element. See examples
(j) and (k) in the <a href="#stages-examples">table below</a>.
<h3 id=stages-examples><span class=secno>5.5. </span> Examples</h3>
<table class=data>
<thead>
<tr>
<th>
<th>Property
<th>Winning declaration <!-- <th>Cascaded value -->
<th>Specified value
<th>Computed value
<th>Used value
<th>Actual value
<tbody>
<tr>
<td>(a)
<th>‘<code class=property>text-align</code>’
<td><code class=declaration>text-align: left</code> <!-- <td>''left''-->
<td>‘<code class=css>left</code>’
<td>‘<code class=css>left</code>’
<td>‘<code class=css>left</code>’
<td>‘<code class=css>left</code>’
<tr>
<td>(b)
<th>‘<code class=property>border-top-width</code>’, ‘<code
class=property>border-right-width</code>’, ‘<code
class=property>border-bottom-width</code>’, ‘<code
class=property>border-left-width</code>’
<td><code class=declaration>border-width: inherit</code>
<!-- <td>''inherit'' -->
<td class=say>‘<code class=css>4.2px</code>’
<td>‘<code class=css>4.2px</code>’