-
Notifications
You must be signed in to change notification settings - Fork 791
Expand file tree
/
Copy pathOverview.html
More file actions
executable file
·3094 lines (2421 loc) · 132 KB
/
Overview.html
File metadata and controls
executable file
·3094 lines (2421 loc) · 132 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">
<html lang=en>
<head
profile="http://dublincore.org/documents/2008/08/04/dc-html/ http://www.w3.org/2006/03/hcard">
<meta content="text/html; charset=utf-8" http-equiv=Content-Type>
<title>CSS Image Values and Replaced Content Module Level 3</title>
<link href="http://purl.org/dc/terms/" rel=schema.dc>
<link href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright"
rel=dc.rights>
<meta content="CSS Image Values and Replaced Content Module Level 3"
name=dc.title>
<meta content=text name=dc.type>
<meta content=2013-04-10 name=dc.date>
<meta content="Elika J. Etemad" name=dc.creator>
<meta content="Tab Atkins Jr." name=dc.creator>
<meta content=W3C name=dc.publisher>
<meta content="http://dev.w3.org/csswg/css3-images/" name=dc.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 Image Values and Replaced Content Module Level 3</h1>
<h2 class="no-num no-toc" id=longstatus-date>Editor's Draft 10 April 2013</h2>
<dl>
<dt>This Version:
<dd><a
href="http://dev.w3.org/csswg/css3-images/">http://dev.w3.org/csswg/css3-images/</a>
<!-- <dd><a href="http://dev.w3.org/csswg/css3-images/">http://www.w3.org/TR/2013/WD-css3-images-20130410/</a>-->
<
133E
div id="LC41" class="react-file-line html-div" data-testid="code-cell" data-line-number="41" style="position:relative"> <dt>Latest Version:
<dd><a
href="http://www.w3.org/TR/css3-images/">http://www.w3.org/TR/css3-images/</a>
<dt>Editor's Draft:
<dd><a
href="http://dev.w3.org/csswg/css3-images/">http://dev.w3.org/csswg/css3-images/</a>
<dt>Previous Version:
<dd><a
href="http://www.w3.org/TR/2012/WD-css3-images-20120112/">http://www.w3.org/TR/2012/WD-css3-images-20120112/</a>
<dt>Disposition of Last Call Comments:
<dd><a
href="http://dev.w3.org/csswg/css3-images/issues-lc-2012">http://dev.w3.org/csswg/css3-images/issues-lc-2012</a>
<dt>Issue Tracking:
<dd><a
href="http://www.w3.org/Style/CSS/Tracker/products/27">http://www.w3.org/Style/CSS/Tracker/products/27</a>
<dt>Feedback:
<dd><a
href="mailto:www-style@w3.org?subject=%5Bcss-images%5D%20feedback">www-style@w3.org</a>
with subject line “<kbd>[css-images] <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="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>CSS is a language for describing the rendering of structured documents
(such as HTML and XML) on screen, on paper, in speech, etc. This module
contains the features of CSS level 3 relating to the <image> type and
replaced elements. It includes and extends the functionality of CSS
level 2 <a href="#CSS21" rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>,
which builds on CSS level 1 <a href="#CSS1"
rel=biblioentry>[CSS1]<!--{{CSS1}}--></a>. The main extensions compared to
level 2 are the generalization of the <url> type to the <image>
type, several additions to the ‘<a href="#image-type"><code
class=css><image></code></a>’ type, a generic sizing algorithm for
images and other replaced content in CSS, and several properties
controlling the interaction of replaced elements and CSS's layout models.
<h2 class="no-num no-toc" id=status>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-images%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-images” in the subject, preferably like this:
“[<!---->css3-images<!---->] <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-->
<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>7 February 2012</strong>.
<p>The following features are at risk: …
<ol>
<li>The <a href="#image-notation">image()</a> notation
<li>The ‘<a href="#object-fit"><code
class=property>object-fit</code></a>’, ‘<a
href="#object-position"><code
class=property>object-position</code></a>’, ‘<a
href="#image-orientation"><code
class=property>image-orientation</code></a>’, and ‘<a
href="#image-resolution"><code
class=property>image-resolution</code></a>’ properties
</ol>
<h2 class="no-num no-toc" id=contents>Table of contents</h2>
<!--begin-toc-->
<ul class=toc>
<li><a href="#intro"><span class=secno>1. </span> Introduction</a>
<ul class=toc>
<li><a href="#placement"><span class=secno>1.1. </span> Module
Interactions</a>
<li><a href="#values"><span class=secno>1.2. </span> Values</a>
</ul>
<li><a href="#resolution-units"><span class=secno>2. </span> Resolution
Units: the <resolution> type</a>
<li><a href="#image-values"><span class=secno>3. </span> Image Values: the
<image> type</a>
<ul class=toc>
<li><a href="#url-notation"><span class=secno>3.1. </span> Image
References and Image Slices: the ‘<code class=css><url></code>’
type and ‘<code class=css>url()</code>’ notation</a>
<li><a href="#image-notation"><span class=secno>3.2. </span> Image
Fallbacks and Annotations: the ‘<code class=css>image()</code>’
notation</a>
<ul class=toc>
<li><a href="#image-fragments"><span class=secno>3.2.1. </span> Image
Fragments</a>
<li><a href="#image-fallbacks"><span class=secno>3.2.2. </span> Image
Fallbacks</a>
<li><a href="#color-images"><span class=secno>3.2.3. </span>
Solid-color Images</a>
</ul>
</ul>
<li><a href="#gradients"><span class=secno>4. </span> Gradients</a>
<ul class=toc>
<li><a href="#linear-gradients"><span class=secno>4.1. </span> Linear
Gradients: the ‘<code class=css>linear-gradient()</code>’
notation</a>
<li><a href="#radial-gradients"><span class=secno>4.2. </span> Radial
Gradients: the ‘<code class=css>radial-gradient()</code>’
notation</a>
<li><a href="#repeating-gradients"><span class=secno>4.3. </span>
Repeating Gradients: the ‘<code
class=css>repeating-linear-gradient()</code>’ and ‘<code
class=css>repeating-radial-gradient()</code>’ notations</a>
<li><a href="#color-stop-syntax"><span class=secno>4.4. </span> Gradient
Color-Stops</a>
</ul>
<li><a href="#sizing"><span class=secno>5. </span> Sizing Images and
Objects in CSS</a>
<ul class=toc>
<li><a href="#sizing-terms"><span class=secno>5.1. </span> Object-Sizing
Terminology</a>
<li><a href="#object-negotiation"><span class=secno>5.2. </span>
CSS⇋Object Negotiation</a>
<li><a href="#concrete-size-resolution"><span class=secno>5.3. </span>
Concrete Object Size Resolution</a>
<ul class=toc>
<li><a href="#default-sizing"><span class=secno>5.3.1. </span> Default
Sizing Algorithm</a>
<li><a href="#cover-contain"><span class=secno>5.3.2. </span> Cover
and Contain Constraint Sizing</a>
</ul>
<li><a href="#object-sizing-examples"><span class=secno>5.4. </span>
Examples of CSS Object Sizing</a>
<li><a href="#the-object-fit"><span class=secno>5.5. </span> Sizing
Objects: the ‘<code class=property>object-fit</code>’ property</a>
<li><a href="#the-object-position"><span class=secno>5.6. </span>
Positioning Objects: the ‘<code
class=property>object-position</code>’ property</a>
</ul>
<li><a href="#image-processing"><span class=secno>6. </span> Image
Processing</a>
<ul class=toc>
<li><a href="#the-image-resolution"><span class=secno>6.1. </span>
Overriding Image Resolutions: the ‘<code
class=property>image-resolution</code>’ property</a>
<li><a href="#the-image-orientation"><span class=secno>6.2. </span>
Orienting an Image on the Page: the ‘<code
class=property>image-orientation</code>’ property</a>
</ul>
<li><a href="#conformance"><span class=secno>7. </span> Conformance</a>
<ul class=toc>
<li><a href="#conventions"><span class=secno>7.1. </span> Document
Conventions</a>
<li><a href="#conformance-classes"><span class=secno>7.2. </span>
Conformance Classes</a>
<li><a href="#partial"><span class=secno>7.3. </span> Partial
Implementations</a>
<li><a href="#experimental"><span class=secno>7.4. </span> Experimental
Implementations</a>
<li><a href="#testing"><span class=secno>7.5. </span>Non-Experimental
Implementations</a>
<li><a href="#cr-exit-criteria"><span class=secno>7.6. </span> CR Exit
Criteria</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>
<li class=no-num><a href="#changes">Changes Since Last Call</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-->
<h2 id=intro><span class=secno>1. </span> Introduction</h2>
<p><em>This section is not normative.</em>
<p>In CSS Levels 1 and 2, image values, such as those used in the ‘<code
class=property>background-image</code>’ property, could only be given by
a single URL value. This module introduces additional ways of representing
2D images, for example as <a href="#image-notation">a list of URIs
denoting fallbacks</a>,
<!-- as <a href="#element-reference">a reference to an element</a>, --> or
as <a href="#gradients">a gradient</a>.
<p>This module also defines several properties for <a
href="#image-processing">manipulating raster images</a> and for <a
href="#object-fit">sizing</a> or <a
href="#object-position">positioning</a> replaced elements such as images
within the box determined by the CSS layout algorithms. It also defines in
a generic way CSS's <a href="#sizing">sizing algorithm</a> for images and
other replaced elements.
<h3 id=placement><span class=secno>1.1. </span> Module Interactions</h3>
<p>This module defines and extends the ‘<a href="#image-type"><code
class=css><image></code></a>’ value type defined in <a
href="#CSS3VAL" rel=biblioentry>[CSS3VAL]<!--{{!CSS3VAL}}--></a>.
Furthermore it replaces the ‘<code class=css><url></code>’ type in
the ‘<code class=property>background-image</code>’ and ‘<code
class=property>list-style-image</code>’ definitions in CSS1 and CSS2 and
adds ‘<a href="#image-type"><code class=css><image></code></a>’ as
an alternative to ‘<code class=css><url></code>’ in the ‘<code
class=property>content</code>’ property's value. It is presumed that CSS
specifications beyond CSS2.1 will use the ‘<a href="#image-type"><code
class=css><image></code></a>’ notation in place of ‘<code
class=css><url></code>’ where 2D images are expected. (See e.g. <a
href="#CSS3BG" rel=biblioentry>[CSS3BG]<!--{{CSS3BG}}--></a>.)
<p>Of the properties defined in this module, only ‘<a
href="#image-resolution"><code
class=property>image-resolution</code></a>’ applies to
<code>::first-line</code> and <code>::first-letter</code>.
<h3 id=values><span class=secno>1.2. </span> Values</h3>
<p>This specification follows the <a
href="http://www.w3.org/TR/CSS21/about.html#property-defs">CSS property
definition conventions</a> from <a href="#CSS21"
rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>. Value types not defined in
this specification are defined in CSS Level 2 Revision 1 <a
href="#CSS21" rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>. Other CSS
modules may expand the definitions of these value types: for example <a
href="#CSS3COLOR" rel=biblioentry>[CSS3COLOR]<!--{{CSS3COLOR}}--></a>,
when combined with this module, expands the definition of the <color>
value type as used in this specification.
<p>In addition to the property-specific values listed in their definitions,
all properties defined in this specification also accept the <a
href="http://www.w3.org/TR/CSS21/cascade.html#value-def-inherit">inherit</a>
keyword as their property value. For readability it has not been repeated
explicitly.
<h2 id=resolution-units><span class=secno>2. </span> Resolution Units: the
<resolution> type</h2>
<p>This specification defines the following units as part of the <dfn
id=resolution-type><resolution></dfn> value type:
<dl>
<dt><dfn id=lsquodpirsquo>‘<code class=css>dpi</code>’</dfn>
<dd>dots per inch
<dt><dfn id=lsquodpcmrsquo>‘<code class=css>dpcm</code>’</dfn>
<dd>dots per centimeter
<dt><dfn id=lsquodppxrsquo>‘<code class=css>dppx</code>’</dfn>
<dd>dots per ‘<code class=css>px</code>’ unit
</dl>
<p>The ‘<a href="#resolution-type"><code
class=css><resolution></code></a>’ unit represents the size of a
single "dot" in a graphical representation by indicating how many of these
dots fit in a CSS ‘<code class=property>in</code>’, ‘<code
class=property>cm</code>’, or ‘<code class=property>px</code>’. For
uses, see e.g. the ‘<code class=css>resolution</code>’ media query in
<a href="#MEDIAQ" rel=biblioentry>[MEDIAQ]<!--{{MEDIAQ}}--></a> or the
‘<a href="#image-resolution"><code
class=property>image-resolution</code></a>’ property defined below.
<p class=note>Note that due to the 1:96 fixed ratio of CSS ‘<code
class=css>in</code>’ to CSS ‘<code class=css>px</code>’, ‘<code
class=css>1dppx</code>’ is equivalent to ‘<code
class=css>96dpi</code>’. This corresponds to the default resolution of
images displayed in CSS: see ‘<a href="#image-resolution"><code
class=property>image-resolution</code></a>’.
<div class=example>
<p>The following @media rule uses Media Queries <a href="#MEDIAQ"
rel=biblioentry>[MEDIAQ]<!--{{MEDIAQ}}--></a> to assign some special
style rules to devices that use two or more device pixels per CSS
‘<code class=css>px</code>’ unit:
<pre>@media (min-resolution: 2dppx) { ... }</pre>
</div>
<!-- ====================================================================== -->
<h2 id=image-values><span class=secno>3. </span> Image Values: the
<image> type</h2>
<p>The ‘<a href="#image-type"><code class=css><image></code></a>’
value type denotes a 2D image. It can be a <a href="#url-notation">url
reference</a>, <a href="#image-notation">image notation</a>,
<!-- <a href="#element-reference">element reference</a>, --> or <a
href="#gradients">gradient notation</a>. Its syntax is:
<pre class=prod><dfn id=image-type><image></dfn> = <i><url></i> | <a
href="#image-list-type"><i><image-list></i></a> | <a
href="#gradient-type"><i><gradient></i></a></pre>
<p>An ‘<a href="#image-type"><code class=css><image></code></a>’ can
be used in many CSS properties, including the ‘<code
class=property>background-image</code>’, ‘<code
class=property>list-style-image</code>’, ‘<code
class=property>cursor</code>’ properties <a href="#CSS21"
rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a> (where it replaces the
‘<code class=css><url></code>’ component in the property's value).
<p>In some cases, an image is invalid, such as a ‘<code
class=css><url></code>’ pointing to a resource that is not a valid
image format. An <dfn id=invalid-image>invalid image</dfn> is rendered as
a solid-color ‘<code class=css>transparent</code>’ image with no
intrinsic dimensions. However, <a href="#invalid-image"><i>invalid
images</i></a> have special behavior in some contexts, such as the
‘<code class=css>image()</code>’ notation.</p>
<!-- ====================================================================== -->
<h3 id=url-notation><span class=secno>3.1. </span> Image References and
Image Slices: the ‘<code class=css><url></code>’ type and ‘<code
class=css>url()</code>’ notation</h3>
<p>The simplest way to indicate an image is to reference an image file by
URL. This can be done with the <a
href="http://www.w3.org/TR/CSS21/syndata.html#uri">‘<code
class=css>url()</code>’ notation</a>, defined in <a href="#CSS21"
rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>.
<div class=example>
<p>In the example below, a background image is specified with ‘<code
class=css>url()</code>’ syntax:
<pre>background-image: url(wavy.png);</pre>
</div>
<p>If the UA cannot download, parse, or otherwise successfully display the
contents at the URL as an image, it must be treated as an <a
href="#invalid-image"><i>invalid image</i></a>.</p>
<!-- ====================================================================== -->
<h3 id=image-notation><span class=secno>3.2. </span> Image Fallbacks and
Annotations: the ‘<code class=css>image()</code>’ notation</h3>
<p>The ‘<code class=css>image()</code>’ function allows an author to:
<ul>
<li>use <a href="http://www.w3.org/TR/media-frags/">media fragments</a> to
clip out a portion of an image
<li>specify fallback images in case the preferred image can't be decoded
or is a type that the browser doesn't recognize
<li>use a solid color as an image
</ul>
<p>The ‘<code class=css>image()</code>’ notation is defined as:
<pre class=prod><dfn
id=image-list-type><image-list></dfn> = image( [ <image-decl> , ]* [ <image-decl> | <color> ] )
<dfn
id=image-decl-type><image-decl></dfn> = [ <url> | <string> ]</pre>
<p>Each ‘<code class=css><string></code>’ or ‘<code
class=css><url></code>’ inside ‘<code class=css>image()</code>’
represents an image, just as if the <a href="#url-notation">‘<code
class=css>url()</code>’ notation</a> had been used. As usual for URLs in
CSS, relative URLs are resolved to an absolute URL (as described in Values
& Units <a href="#CSS3VAL"
rel=biblioentry>[CSS3VAL]<!--{{!CSS3VAL}}--></a>) when a specified
‘<code class=css>image()</code>’ value is computed.
<h4 id=image-fragments><span class=secno>3.2.1. </span> Image Fragments</h4>
<p>When a URL specified in ‘<code class=css>image()</code>’ represents
a portion of a resource (e.g. by the use of <a
href="http://www.w3.org/TR/media-frags/#naming-space">media fragment
identifiers</a>) that portion is clipped out of its context and used as a
standalone image.
<div class=example>
<p>For example, given the following image* and CSS:</p>
<a href=sprites.svg> <img alt="[9 circles, with 0 to 8 eighths filled in]"
height=20 src=sprites.svg width=180> </a>
<pre>background-image: image('sprites.svg#xywh=40,0,20,20')</pre>
<p>...the background of the element will be the portion of the image that
starts at (40px,0px) and is 20px wide and tall, which is just the circle
with a quarter filled in.
<p><small>* SVG-in-<img> support required. Click the picture to view
the SVG directly.</small>
</div>
<p>So that authors can take advantage of CSS's forwards-compatible parsing
rules to provide a fallback for image slices, implementations that support
the ‘<code class=css>image()</code>’ notation <em>must</em> support
the <code>xywh=#,#,#,#</code> form of media fragment identifiers for
images specified via ‘<code class=css>image()</code>’. <a
href="#MEDIA-FRAGS"
rel=biblioentry>[MEDIA-FRAGS]<!--{{!MEDIA-FRAGS}}--></a>
<div class=example>
<p>Note that image fragments can also be used with the ‘<code
class=css>url()</code>’ notation. However, a legacy UA that doesn't
understand the media fragments notation will ignore the fragment and
simply display the entirety of the image.
<p>Since the ‘<code class=css>image()</code>’ notation requires UAs to
support media fragments, authors can take advantage of CSS's
forward-compatible parsing rules to provide a fallback when using an
image fragment URL:
<pre>
<!-- -->background-image: url('swirl.png'); /* old UAs */
<!-- -->background-image: image('sprites.png#xywh=10,30,60,20'); /* new UAs */</pre>
</div>
<h4 id=image-fallbacks><span class=secno>3.2.2. </span> Image Fallbacks</h4>
<p>Multiple ‘<a href="#image-decl-type"><code
class=css><image-decl>s</code></a>’ can be given separated by commas,
in which case the function represents the first image that's not an <a
href="#invalid-image"><i>invalid image</i></a>. The final argument can
specify a ‘<code class=css><color></code>’ to serve as an ultimate
fallback; this can be used, e.g. for ‘<code
class=property>background-image</code>’, to ensure adequate contrast if
none of the preceding ‘<a href="#image-decl-type"><code
class=css><image-decl>s</code></a>’ can be used. If the final
argument is a ‘<code class=css><color></code>’, it represents a
solid-color image of the given color with no <a
href="#intrinsic-dimensions"><i>intrinsic dimensions</i></a>. If all of
the provided ‘<a href="#image-decl-type"><code
class=css><image-decl>s</code></a>’ are <a
href="#invalid-image"><i>invalid images</i></a> and a fallback color was
not provided as the last argument, the entire ‘<code
class=css>image()</code>’ function must be treated as an <a
href="#invalid-image"><i>invalid image</i></a>.
<div class=example>
<p>The rule below would tell the UA to load ‘<code
class=css>wavy.svg</code>’ if it can; failing that to load ‘<code
class=css>wavy.png</code>’; failing that to display ‘<code
class=css>wavy.gif</code>’. For example, the browser might not
understand how to render SVG images, and the PNG may be temporarily 404
(returning an HTML 404 page, which the browser can't decode as an image)
due to a server move, so the GIF is used until one of the previous
problems corrects itself.
<pre>background-image: image("wavy.svg", 'wavy.png' , "wavy.gif");</pre>
</div>
<div class=example>
<p>The fallback color can be used to ensure that text is still readable
even when the image fails to load. For example, the following code works
fine if the image is rectangular and has no transparency:
<pre>
body { color: black; background: white; }
p.special { color: white; background: url("dark.png") black; }</pre>
<p>When the image doesn't load, the background color is still there to
ensure that the white text is readable. However, if the image has some
transparency, the black will be visible behind it, which is probably not
desired. The ‘<code class=css>image()</code>’ function addresses
this:
<pre>
body { color: black; background: white; }
p.special { color: white; background: image("dark.png", black); }</pre>
<p>Now, the black won't show at all if the image loads, but if for
whatever reason the image fails, it'll pop in and prevent the white text
from being set against a white background.
</div>
<p>If a URL uses a fragment identifier syntax that the implementation does
not understand, or does not consider valid for that type of image, the URL
must be treated as representing an <a href="#invalid-image"><i>invalid
image</i></a>. <span class=note>This error-handling is limited to image(),
and not in the definition of URL, for legacy compat reasons.</span>
<div class=example>
<p>For example, if a future specification defined a way to refer to a
specific frame of an animated GIF with a fragment identifier, an author
could write the following to get newer browsers to use the GIF's frame,
and older browsers to instead download the fallback image:
<pre>background-image: image('cat_meme.gif#frame=5', 'lolcat.png');</pre>
</div>
<!-- XXX SVG fragment example with spriting / fallbacks (once SVG can provide this) -->
<h4 id=color-images><span class=secno>3.2.3. </span> Solid-color Images</h4>
<div class=example>
<p>At times, one may need a solid-color image for a property or function
that does not accept the ‘<code class=css><color></code>’ type
directly. The ‘<code class=css>image()</code>’ function can be used
for this: by specifying <em>only</em> a color without any URLs, the
function immediately falls back to representing a solid-color image of
the chosen color.
<pre>background-image: image(rgba(0,0,255,.5)), url("bg-image.png");</pre>
<p>In the above, the background is the image "bg-image.png", overlaid with
partially-transparent blue.
</div>
<!-- Removed per WG decision, commenting it out so I can more easily punt it to Images 4
<h4 id='bidi-images'>
Bidi-sensitive Images</h4>
<p>Along with each ''<image-decl>'', the author may specify a directionality, similar to adding a <code>dir</code> attribute to an element in HTML. The ''image()'' function takes on the directionality of the used ''<image-decl>'', if any. If a directional image is used on or in an element with opposite <a href="http://www.w3.org/TR/CSS21/visuren.html#propdef-direction">direction</a>, the image must be flipped in the inline direction (as if it was transformed by, e.g., <code>scaleX(-1)</code>, if the inline direction is the X axis).</p>
<div class='example'>
<p>A list may use an arrow for a bullet that points into the content. If the list can contain both LTR and RTL text, though, the bullet may be on the left or the right, and an image designed to point into the text on one side will point out of the text on the other side. This can be fixed with code like:</p>
<pre>
<ul style="list-style-image: image("arrow.png" ltr);">
<li dir='ltr'>My bullet is on the left!</li>
<li dir='rtl'>MY BULLET IS ON THE RIGHT!</li>
</ul></pre>
<p>This should render something like:</p>
<pre>
⇒ My bullet is on the left!
!THGIR EHT NO SI TELLUB YM ⇐</pre>
<p>In LTR list items, the image will be used as-is. In the RTL list items, however, it will be flipped in the inline direction, so it still points into the content.</p>
</div>
-->
<!-- ====================================================================== -->
<!-- removed per WG decision
<h3 id='element-notation'>
Using Elements as Images: the ''element()'' notation</h3>
<p>The ''element()'' function allows an author to use an element in the document as an image. As the referenced element changes appearance, the image changes as well. This can be used, for example, to create live previews of the next/previous slide in a slideshow, or to reference a canvas element for a fancy generated gradient or even an animated background.</p>
<p class='note'>Note that the ''element()'' function only reproduces the <em>appearance</em> of the referenced element, not the actual content and its structure. Authors should only use this for decorative purposes, and must not use ''element()'' to reproduce an element with significant content across the page. Instead, just insert multiple copies of the element into the document.</p>
<p>The syntax for ''element()'' is:</p>
<pre class=prod><dfn id='element-reference-type'><element-reference></dfn> = element( <id-selector> )</pre>
<p>where ''<id-selector>'' is an ID selector [[!SELECT]].</p>
<p>The ''element()'' function references the element matched by its argument. If multiple elements are matched, the function references the first such element.</p>
<p>The image represented by the ''element()'' function can vary based on whether the element is visible in the document:</p>
<dl>
<dt>an <i title="element-not-rendered">element that is rendered</i> and is not a descendant of a replaced element</dt>
<dd>
<p>The function represents an image with its intrinsic size equal to the <dfn>decorated bounding box</dfn> of the referenced element:
<ul>
<li>for an element rendered using a CSS rendering model, the <i>decorated bounding box</i> is the smallest axis-aligned rectangle that contains the <a href="http://www.w3.org/TR/2011/CR-css3-background-20110215/#border-image-area">border image areas</a> of all the fragments of the principal box</li>
<li>for an element rendered using the SVG rendering model, <a href="http://www.w3.org/TR/SVGTiny12/intro.html#TermDecoratedBoundingBox">the decorated bounding box is defined by SVG</a></li>
</ul>
<p class=note>Note: Because images clip anything outside their bounds by default, this means that decorations that extend outside the <i>decorated bounding box</i>, like box shadows, may be clipped.</p>
<p>The image is constructed by rendering the referenced element and its descendants (at the same size that they would be in the document) over an infinite ''transparent'' canvas, positioned so that the edges of the <i>decorated bounding box</i> are flush with the edges of the image.</p>
<p>If the referenced element has a transform applied to it or an ancestor, the transform must be ignored when rendering the element as an image. [[!CSS-TRANSFORMS]]</p>
<p>If the referenced element is broken across pages, the element is displayed as if the page content areas were joined flush in the pagination direction, with pages' edges corresponding to the initial containing block's start edge aligned. <span class='note'>Elements broken across lines or columns are just rendered with their <i>decorated bounding box</i>.</span></p>
<p>Implementations may either re-use existing bitmap data generated for the referenced element or regenerate the display of the element to maximize quality at the image's size (for example, if the implementation detects that the referenced element is an SVG fragment); in the latter case, the layout of the referenced element in the image must not be changed by the regeneration process. That is, the image must look identical to the referenced element, modulo rasterization quality.</p>
<div class='example'>
<p>As a somewhat silly example, a <code><p></code> element can be reused as a background elsewhere in the document:</p>
<pre>
<style>
#src { color: white; background: lime; width: 300px; height: 40px; }
#dst { color: black; background: element(#src); padding: 20px; margin: 20px 0; }
</style>
<p id='src'>I'm an ordinary element!</p>
<p id='dst'>I'm using the previous element as my background!</p></pre>
<img src="element-function.png" alt="">
</div>
</dd>
<dt>an <i title='element-not-rendered'>element that is not rendered</i>, but which <i title='paint-source'>provides a paint source</i></dt>
<dd>
<p>The function represents an image with the intrinsic size and appearance of the <i title=paint-source>paint source</i>. The host language defines the size and appearance of paint sources.</p>
<div class='example'>
<p>For example, the ''element()'' function can reference an SVG <code><pattern></code> element in an HTML document:</p>
<pre>
<!DOCTYPE html>
<svg>
<defs>
<pattern id='pattern1'>
<path d='...'>
</pattern>
</defs>
</svg>
<p style="background: element(#pattern1)">
I'm using the pattern as a background!
If the pattern is changed or animated,
my background will be updated too!
</p></pre>
<p>HTML also defines that a handful of elements, such as <code><canvas></code>, <code><img></code>, and <code><video></code>, provide a paint source. This means that CSS can, for example, reference a canvas that's being drawn into, but not displayed in the page:</p>
<pre>
<!DOCTYPE html>
<script>
var canvas = document.querySelector('#animated-bullet');
canvas.width = 20; canvas.height = 20;
drawAnimation(canvas);
</script>
<canvas id='animated-bullet' style='display:none'></canvas>
<ul style="list-style-image: element(#animated-bullet);">
<li>I'm using the canvas as a bullet!</li>
<li>So am I!</li>
<li>As the canvas is changed over time with Javascript,
we'll all update our bullet image with it!</li>
</ul></pre>
</div>
</dd>
<dt>anything else</dt>
<dd>
<p>The function represents an <i>invalid image</i>.</p>
<div class='example'>
<p>For example, all of the following ''element()'' uses will result in a transparent background:</p>
<pre>
<!DOCTYPE html>
<p id='one' style="display:none;">one</p>
<iframe src="http://example.com">
<p id='two'>I'm fallback content!</p>
</iframe>
<ul>
<li style="background: element(#one);">
A display:none element isn't rendered, and a P element
doesn't provide a paint source.
</li>
<li style="background: element(#two);">
The descendants of a replaced element like an IFRAME
can't be used in element() either.
</li>
<li style="background: element(#three);">
There's no element with an id of "three", so this also
gets rendered as a transparent image.
</li>
</ul></pre>
</div>
</dd>
</dl>
<p>An element is <dfn id='element-not-rendered' title='element-not-rendered'>not rendered</dfn> if it does not have an associated box. This can happen, for example, if the element or an ancestor is ''display:none''. Host languages may define additional ways in which an element can be considered not rendered; for example, in SVG, any descendant of a <code><defs></code> element is considered to be not rendered.</p>
<div class='example'>
<p>The ''element()'' function can be put to many uses. For example, it can be used to show a preview of the previous or next slide in a slideshow:</p>
<pre>
<!DOCTYPE html>
<script>
function navigateSlides() {
var currentSlide = ...;
document.querySelector('#prev-slide').id = '';
document.querySelector('#next-slide').id = '';
currentSlide.previousElementSibling.id = 'prev-slide';
currentSlide.nextElementSibling.id = 'next-slide';
}
</script>
<style>
#prev-preview, #next-preview {
position: fixed;
...
}
#prev-preview { background: element(#prev-slide); }
#next-preview { background: element(#next-slide); }
</style>
<a id='prev-preview'>Previous Slide</a>
<a id='next-preview'>Next Slide</a>
<section class='slide'>...</section>
<section class='slide current-slide'>...</section>
...</pre>
<p>In this example, the <code>navigateSlides</code> function updates the ids of the next and previous slides, which are then displayed in small floating boxes alongside the slides. Since you can't interact with the slides through the ''element()'' function (it's just an image), you could even use <code>click</code> handlers on the preview boxes to help navigate through the page.
</div>
<h4 id='paint-sources'>
Paint Sources</h4>
<p>Host languages may define that some elements provide a <dfn title="paint-source">paint source</dfn>. Paint sources have an intrinsic width, height, and appearance, separate from the process of rendering, and so may be used as images even when they're <i title='element-not-rendered'>not rendered</i>.</p>
<p>In HTML, the <code><img></code>, <code><video></code>, and <code><canvas></code> elements provide paint sources (defined in each element's section in <a href='http://www.whatwg.org/specs/web-apps/current-work/multipage/'>HTML5</a>).</p>
<p>In SVG, any element that provides a <a href='http://www.w3.org/TR/SVG/pservers.html'>paint server</a> provides a paint source. <span class='note'>Note: In SVG1.1, the <code><linearGradient></code>, <code><radialGradient></code>, and <code><pattern></code> elements provide paint sources.</span> They are drawn as described in the spec, with the coordinate systems defined as follows:</p>
<dl>
<dt>objectBoundingBox</dt>
<dd>The coordinate system has its origin at the top left corner of the rectangle defined by the <i>concrete object size</i> that it's being drawn into, and the same width and height as the <i>concrete object size</i>. A single <a href="http://www.w3.org/TR/SVG/coords.html#Units">user coordinate</a> is the width and height of the <i>concrete object size</i>.</dd>
<dt>userSpaceOnUse</dt>
<dd>The coordinate system has its origin at the top left corner of the rectangle defined by the <i>concrete object size</i> that it's being drawn into, and the same width and height as the <i>concrete object size</i>. <a href="http://www.w3.org/TR/SVG/coords.html#Units">User coordinates</a> are sized equivalently to the CSS ''px'' unit.</dd>
</dl>
<p class='note'>It is expected that a future version of this module will define ways to refer to paint sources in external documents, or ones that are created solely by script and never inserted into a document at all.</p>
<h4 id='element-cycles'>
Cycle Detection</h4>
<p>The ''element()'' function can produce nonsensical circular relationships,
such as an element using itself as its own background. These relationships
can be easily and reliably detected and resolved, however, by keeping
track of a dependency graph and using common cycle-detection algorithms.</p>
<p>The dependency graph consists of edges such that:</p>
<ul>
<li>every element depends on its children</li>
<li>for any element A with a property using the ''element()'' function pointing to an element B, A depends on B</li>
<li>if a host language defines a way for elements to refer to the rendering of other elements, the referencing element depends on the referenced element. For example, in SVG, a <use> element depends on the element it referenced.</li>
</ul>
<p>If the graph contains a cycle, any ''element()'' functions participating in the cycle must represent a fully transparent image with no intrinsic dimensions.</p>
-->
<h2 id=gradients><span class=secno>4. </span> Gradients</h2>
<p>A gradient is an image that smoothly fades from one color to another.
These are commonly used for subtle shading in background images, buttons,
and many other things. The gradient notations described in this section
allow an author to specify such an image in a terse syntax, so that the UA
can generate the image automatically when rendering the page. The syntax
of a <a href="#gradient-type"><i><gradient></i></a> is:
<pre class=prod><dfn id=gradient-type><gradient></dfn> = [
<a
href="#linear-gradient-type"><i><linear-gradient></i></a> | <a
href="#radial-gradient-type"><i><radial-gradient></i></a> |
<a
href="#repeating-linear-gradient-type"><i><repeating-linear-gradient></i></a> | <a
href="#repeating-radial-gradient-type"><i><repeating-radial-gradient></i></a> ]</pre>
<div class=example>
<p>As with the other <a href="#image-type"><i><image></i></a> types
defined in this specification, gradients can be used in any property that
accepts images. For example:
<ul>
<li><code>background: linear-gradient(white, gray);</code>
<li><code>list-style-image: radial-gradient(circle, #006, #00a 90%,
#0000af 100%, white 100%)</code>
</ul>
</div>
<p>A gradient is drawn into a box with the dimensions of the <a
href="#concrete-object-size"><i>concrete object size</i></a>, referred to
as the <dfn id=gradient-box>gradient box</dfn>. However, the gradient
itself has no <a href="#intrinsic-dimensions"><i>intrinsic
dimensions</i></a>.
<div class=example>
<p>For example, if you use a gradient as a background, by default the
gradient will draw into a <a href="#gradient-box"><i>gradient box</i></a>
the size of the element's padding box. If ‘<code
class=property>background-size</code>’ is explicitly set to a value
such as ‘<code class=css>100px 200px</code>’, then the <a
href="#gradient-box"><i>gradient box</i></a> will be 100px wide and 200px
tall. Similarly, for a gradient used as a ‘<code
class=property>list-style-image</code>’, the box would be a 1em square,
which is the <a href="#default-object-size"><i>default object
size</i></a> for that property.
</div>
<!-- ====================================================================== -->
<h3 id=linear-gradients><span class=secno>4.1. </span> Linear Gradients:
the ‘<code class=css>linear-gradient()</code>’ notation</h3>
<p>A linear gradient is created by specifying a gradient line and then
several colors placed along that line. The image is constructed by
creating an infinite canvas and painting it with lines perpendicular to
the gradient line, with the color of the painted line being the color of
the gradient line where the two intersect. This produces a smooth fade
from each color to the next, progressing in the specified direction.</p>
<!-- ====================================================================== -->
<h4 class=no-toc id=linear-gradient-syntax><span class=secno>4.1.1. </span>
linear-gradient() syntax</h4>
<p>The linear gradient syntax is:
<pre class=prod><code>
<dfn
id=linear-gradient-type><linear-gradient></dfn> = linear-gradient(
[ [ <angle> | to <side-or-corner> ] ,]?
<color-stop>[, <color-stop>]+
)
<dfn
id=side-or-corner><side-or-corner></dfn> = [left | right] || [top | bottom]</code></pre>
<p>The first argument to the function specifies the <dfn
id=gradient-line>gradient line</dfn>, which gives the gradient a direction
and determines how color-stops are positioned. It may be omitted; if so,
it defaults to ‘<code class=css>to bottom</code>’.
<p>The <a href="#gradient-line"><i title="gradient line">gradient
line's</i></a> direction may be specified in two ways:
<dl>
<dt>using angles
<dd>For the purpose of this argument, ‘<code class=css>0deg</code>’
points upward, and positive angles represent clockwise rotation, so
‘<code class=css>90deg</code>’ point toward the right.
<dt>using keywords
<dd>
<p>If the argument is ‘<code class=css>to top</code>’, ‘<code
class=css>to right</code>’, ‘<code class=css>to bottom</code>’, or
‘<code class=css>to left</code>’, the angle of the <a
href="#gradient-line"><i>gradient line</i></a> is ‘<code
class=css>0deg</code>’, ‘<code class=css>90deg</code>’, ‘<code
class=css>180deg</code>’, or ‘<code class=css>270deg</code>’,
respectively.
<p> If the argument instead specifies a corner of the box such as
‘<code class=css>to top left</code>’, the <a
href="#gradient-line"><i>gradient line</i></a> must be angled such that
it points into the same quadrant as the specified corner, and is
perpendicular to a line intersecting the two neighboring corners of the
<a href="#gradient-box"><i>gradient box</i></a>. <span class=note>This
causes a color-stop at 50% to intersect the two neighboring corners (see
<a href="#corner-gradient-example">example</a>).</span>
</dl>
<p>Starting from the center of the <a href="#gradient-box"><i>gradient
box</i></a>, extend a line at the specified angle in both directions. The
ending point is the point on the <a href="#gradient-line"><i>gradient
line</i></a> where a line drawn perpendicular to the <a
href="#gradient-line"><i>gradient line</i></a> would intersect the corner
of the <a href="#gradient-box"><i>gradient box</i></a> in the specified
direction. The starting point is determined identically, but in the
opposite direction.
<p class=note>It is expected that the next level of this module will
provide the ability to define the gradient's direction relative to the
current text direction and writing-mode.
<div class=example>
<div style="overflow: hidden"> <img
alt="[An image showing a box with a background shading gradually from white in the bottom-left corner to black in the top-right corner. There is a line, illustrating the gradient line, angled at 45 degrees and passing through the center of the box. The starting point and ending point of the gradient line are indicated by the intersection of the gradient line with two additional lines that pass through the bottom-left and top-right corners of the box.]"
src=gradient-diagram.png style="float: right; margin-left: 1em;">
<p>This example illustrates visually how to calculate the <a
href="#gradient-line"><i>gradient line</i></a> from the rules above.
This shows the starting and ending point of the <a
href="#gradient-line"><i>gradient line</i></a>, along with the actual
gradient, produced by an element with ‘<code class=css>background:
linear-gradient(45deg, white, black);</code>’.