-
Notifications
You must be signed in to change notification settings - Fork 790
Expand file tree
/
Copy pathOverview.html
More file actions
1878 lines (1478 loc) · 78.9 KB
/
Overview.html
File metadata and controls
1878 lines (1478 loc) · 78.9 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><meta content="text/html; charset=utf-8" http-equiv=Content-Type>
<title>CSS Image Values and Replaced Content Module Level 3</title>
<link href="../default.css" rel=stylesheet type="text/css">
<link href="http://www.w3.org/StyleSheets/TR/W3C-ED" rel=stylesheet
type="text/css">
<style>
p { margin: .5em 0; }
</style>
<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 1 December
2010</h2>
<dl>
<dt>This version:</dt>
<!-- <dd><a href="http://www.w3.org/TR/2010/CR-css3-images-20101201/">http://www.w3.org/TR/2010/CR-css3-images-20101201/</a></dd> -->
<dd><a
href="http://dev.w3.org/csswg/css3-images/">http://dev.w3.org/csswg/css3-images/</a>
<!-- <dt>Latest version:</dt>
<dd><a href="http://www.w3.org/TR/css3-images/">http://www.w3.org/TR/css3-images/</a></dd>
<dt>Previous version:</dt>
<dd><a href="http://www.w3.org/TR/2008/CR-css3-namespace-20080523/">http://www.w3.org/TR/2008/CR-css3-namespace-20080523/</a></dd> -->
<dt>Editor:
<dd><a href="http://fantasai.inkedblade.net/contact">Elika J. Etemad</a>
<dd><a href="http://www.xanthir.com/contact">Tab Atkins Jr.</a>
</dl>
<!--begin-copyright-->
<p class=copyright><a
href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright"
rel=license>Copyright</a> © 2010 <a
href="http://www.w3.org/"><acronym title="World Wide Web
Consortium">W3C</acronym></a><sup>®</sup> (<a
href="http://www.csail.mit.edu/"><acronym title="Massachusetts Institute
of Technology">MIT</acronym></a>, <a href="http://www.ercim.eu/"><acronym
title="European Research Consortium for Informatics and
Mathematics">ERCIM</acronym></a>, <a
href="http://www.keio.ac.jp/">Keio</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 Image Values and Replaced Content module has two parts: First,
it defines the syntax for <image> values in CSS. <image>
values can be a single URI to an image, a list of URIs denoting a series
of fallbacks, or gradients. Second, it defines properties used to control
the interaction of replaced content and the CSS layout algorithms. These
properties can affect the used image resolution for bitmaps, the replaced
object's orientation, and whether and how to preserve the object's aspect
ratio.
<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="/Style/CSS/members">CSS
Working Group</a> (part of the <a href="/Style/">Style Activity</a>).
<p>This document was produced by a group operating under the <a
href="/Consortium/Patent-Policy-20040205/">5 February 2004 W3C Patent
Policy</a>. W3C maintains a <a href="/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="/Consortium/Patent-Policy-20040205/#def-essential">Essential
Claim(s)</a> must disclose the information in accordance with <a
href="/Consortium/Patent-Policy-20040205/#sec-Disclosure">section 6 of the
W3C Patent Policy</a>.</p>
<!--end-status-->
<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>
<li><a href="#conformance"><span class=secno>2. </span>Conformance</a>
<li><a href="#resolution-units-the-ltresolutiongt-valu"><span
class=secno>3. </span>Resolution Units: the <resolution> value
type</a>
<li><a href="#image"><span class=secno>4. </span>Image Values: the
<image> value type</a>
<ul class=toc>
<li><a href="#url"><span class=secno>4.1. </span>Image References and
Image Slices: the ‘<code class=css>url()</code>’
notation</a>
<li><a href="#image-notation"><span class=secno>4.2. </span>Image
Fallbacks: the ‘<code class=css>image()</code>’
notation</a>
<li><a href="#element-reference"><span class=secno>4.3. </span>Using
Elements as Images: The ‘<code class=css>element()</code>’
and ‘<code class=css>element-ref()</code>’ functions</a>
</ul>
<li><a href="#gradients"><span class=secno>5. </span>Gradients</a>
<ul class=toc>
<li><a href="#linear-gradients"><span class=secno>5.1. </span>Linear
Gradients</a>
<li><a href="#radial-gradients"><span class=secno>5.2. </span>Radial
Gradients</a>
<li><a href="#color-stop-syntax"><span class=secno>5.3.
</span><code>color-stop</code> Syntax</a>
<li><a href="#interpolating-gradients"><span class=secno>5.4.
</span>Interpolating Gradients</a>
</ul>
<li><a href="#sizing"><span class=secno>6. </span>Sizing Images and
Objects in CSS</a>
<ul class=toc>
<li><a href="#image-resolution"><span class=secno>6.1. </span>Overriding
Image Resolutions: the ‘<code
class=property>image-resolution</code>’ property</a>
<li><a href="#image-orientation"><span class=secno>6.2. </span>Orienting
an Image on the Page: the ‘<code
class=property>image-orientation</code>’ property</a>
<li><a href="#object-fit"><span class=secno>6.3. </span>The ‘<code
class=property>object-fit</code>’ Property</a>
<li><a href="#object-position"><span class=secno>6.4. </span>The
‘<code class=property>object-position</code>’ Property</a>
</ul>
<li><a href="#serialization"><span class=secno>7. </span>Serialization</a>
<ul class=toc>
<li><a href="#serializing-resolution"><span class=secno>7.1.
</span>Serializing a <resolution></a>
<li><a href="#serializing-url-notation"><span class=secno>7.2.
</span>Serializing the ‘<code class=css>url()</code>’
notation</a>
<li><a href="#serializing-image-notation"><span class=secno>7.3.
</span>Serializing the ‘<code class=css>image()</code>’
notation</a>
<li><a href="#serializing-gradients"><span class=secno>7.4.
</span>Serializing Gradients</a>
<li><a href="#serializing-properties"><span class=secno>7.5.
</span>Serializing new properties</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="#informative-references">Informative
references</a>
</ul>
</ul>
<!--end-toc-->
<div>
<h2 id=intro><span class=secno>1. </span>Introduction</h2>
<p><em>This section is non-normative.</em></p>
<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 URI value. This module introduces
additional notations that allow a 2D image to be given as a list of URIs
denoting fallbacks, as a slice of a larger image (sprite), and as a
gradient.</p>
</div>
<div>
<h2 id=conformance><span class=secno>2. </span>Conformance</h2>
<p>A document or implementation cannot conform to CSS Image Values Level 3
alone, but can claim conformance to CSS Image Values Level 3 if it
satisfies the conformance requirements in this specification when
implementing CSS or another host language that normatively references
this specification.</p>
<p>Conformance to CSS Namespaces is defined for two classes:
<dl>
<dt><dfn id=style-sheet>style sheet</dfn>
<dd>A <a href="http://www.w3.org/TR/CSS21/conform.html#style-sheet">CSS
style sheet</a> (or a complete unit of another host language that
normatively references CSS Namespaces).
<dt><dfn id=interpreter>interpreter</dfn>
<dd>Someone or something that interprets the semantics of a style sheet.
(CSS <a href="http://www.w3.org/TR/CSS21/conform.html#user-agent">user
agents</a> fall under this category.)
</dl>
<p>The conformance requirements are expressed with a combination of
descriptive assertions and RFC 2119 terminology. The key words "MUST",
"MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT",
"RECOMMENDED", "MAY", and "OPTIONAL" in the normative parts of this
document are to be interpreted as described in RFC 2119. However, for
readability, these words do not appear in all uppercase letters in this
specification. All of the text of this specification is normative except
sections explicitly marked as non-normative, examples, and notes. <a
href="#RFC2119" rel=biblioentry>[RFC2119]<!--{{!RFC2119}}--></a></p>
<p>Examples in this specification are introduced with the words "for
example" or are set apart from the normative text with
<code>class="example"</code>, like this:
<div class=example>
<p>This is an example of an informative example.</p>
</div>
<p>Informative notes begin with the word "Note" and are set apart from the
normative text with <code>class="note"</code>, like this:
<p class=note>Note, this is an informative note.</p>
</div>
<div>
<h2 id=resolution-units-the-ltresolutiongt-valu><span class=secno>3.
</span>Resolution Units: the <resolution> value type</h2>
<p>This specification defines the following units as part of the <dfn
id=ltresolutiongt><resolution></dfn> value type:
<dl>
<dt>dpi
<dd>dots per inch
<dt>dpcm
<dd>dots per centimeter
<dt>dppx
<dd>dots per ‘<code class=css>px</code>’ unit
</dl>
<p class=note>The default resolution of raster images in CSS is
‘<code class=css>1dppx</code>’.</p>
</div>
<div>
<h2 id=image><span class=secno>4. </span>Image Values: the <image>
value type</h2>
<p>The <image> value type denotes a 2D image. It is defined as
<pre
class=prod><dfn id=ltimagegt><image></dfn> = <url> | <image-list> | <gradient></pre>
<p>Image values 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>.
<div>
<h3 id=url><span class=secno>4.1. </span>Image References and Image
Slices: the ‘<code class=css>url()</code>’ notation</h3>
<p>The simplest way to indicate an image is to reference an image file by
URI. This is 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:</p>
<pre>background-image: url(wavy.png);</pre>
</div>
<p>A portion of an image may be referenced (clipped out and used as a
standalone image) by use of fragment identifiers. <span class=issue>Need
a spec to reference here. Expecting to get one from <a
href="http://www.w3.org/2008/WebVideo/Fragments/">Media Fragments
WG</a>.</span>
<div class=example>
<p>For example,</p>
<pre>background-image: url('logos.png#xywh=10,30,60,20')</pre>
<p>uses the 60 pixel by 20 pixel rectangle of <code>logos.png</code>
beginning at the point 10 pixels in from the left, 30 pixels down from
the top.
<p class=note>Note that quotation marks are required here, because
unquoted commas are not allowed in ‘<code
class=css>url()</code>’ syntax.</p>
</div>
</div>
<div>
<h3 id=image-notation><span class=secno>4.2. </span>Image Fallbacks: the
‘<code class=css>image()</code>’ notation</h3>
<p>The ‘<code class=css>image()</code>’ notation allows an
author to specify multiple images, each one a fallback for the previous.
The UA must use only the first image that it can load and display. The
syntax for ‘<code class=css>image()</code>’ is defined as
<pre class=prod><dfn id=ltimage-listgt><image-list></dfn> = <!--
-->image( [ <image-decl> , ]* [ <image-decl> | <color> | <gradient> ] )</pre>
<p>where <image-decl> is given by
<pre class=prod><dfn id=ltimage-declgt><image-decl></dfn> = <!--
-->[ <string> | <url-token> ] [ snap? && <resolution> ]?</pre>
<p><url-token> is given as
<code>[!#$%&*-~]|{nonascii}|{escape}</code> (i.e. the contents of
‘<code class=css>url()</code>’) using the productions in the
<a href="http://www.w3.org/TR/CSS21/syndata.html#tokenization">CSS2.1
tokenization</a>. <strong>The <url-token> must not contain
unescaped brackets, commas, white space characters, single quotes (') or
double quotes ("); if it does the ‘<code
class=css>image()</code>’ containing it is invalid.</strong>
<p>Each string or url-token represents the URI of an image. If a
resolution is given, then the image must be rendered at the specified
resolution. If the ‘<code class=css>snap</code>’ keyword is
also specified, and the image is a raster image, then the image must be
rendered at the resolution closest to the specified resolution that
would result in no pixel rounding. <span class=issue>I don't think "no
pixel rounding" is the right terminology here... basically we want to
avoid blurry images.</span></p>
<p>The optional color at the end of the list is the <dfn
id=fallback-color>fallback color</dfn>. It is used if, and only if, none
of the images can be loaded and displayed (e.g. because they are in
unsupported formats, or cannot be found, or are corrupted in some way,
or because image loading is disabled in the UA). It is treated as a
single-color image with no intrinsic dimensions.
<div class=example>
<p>For example, 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>’ and display it at 150dpi;
failing that to display ‘<code class=css>wavy.gif</code>’;
and finally, if none of the images can be loaded and displayed, to use
the color ‘<code class=css>blue</code>’ to create a
dimensionless background image.
<pre>background-image: image(wavy.svg, 'wavy.png' 150dpi, "wavy.gif", blue);</pre>
<p>The ‘<code class=property>background-image</code>’
property specifies that dimensionless images must stretch to cover the
entire background positioning area <a href="#CSS3BG"
rel=biblioentry>[CSS3BG]<!--{{CSS3BG}}--></a>, so if none of the
specified images can be displayed the background will be painted blue.
As with any image, this fallback will be painted over the ‘<code
class=property>background-color</code>’ (if any).
</div>
<p>If the URL for the image ends in a file extension (a period followed
by letters) of four ascii letters ([a-zA-Z]) or less, then the UA
<em>may</em> skip trying to load images whose file extension matches an
image format it knows it does not support. For example, a UA that knows
it supports JPEG and GIF, but expects to encounter many PNG and SVG
images may choose to skip over images with filenames ending in
‘<code class=css>.png</code>’ or ‘<code
class=css>.svg</code>’ without loading them to check their MIME
type. However it must not skip over images with filenames ending in
extensions it doesn't recognize.
</div>
<div>
<h3 id=element-reference><span class=secno>4.3. </span>Using Elements as
Images: The ‘<code class=css>element()</code>’ and
‘<code class=css>element-ref()</code>’ functions</h3>
<p>The ‘<code class=css>element()</code>’ and ‘<code
class=css>element-ref()</code>’ functions allow an author to
specify an element in the document that should be used as an image. This
is useful for many things; for example, in HTML one may use these
functions to refer to a <canvas> element to get a scriptable
background for another element.</p>
<div>
<h4 class=no-toc id=the-element-function><span class=secno>4.3.1.
</span>The ‘<code class=css>element()</code>’ function</h4>
<p>The ‘<code class=css>element()</code>’ function allows
the author to refer to an element in the document by its id and treat
it as an image, to be used in properties like background-image. As the
referenced element changes, for example, by the user typing into a
<textarea> element or a script drawing into a <canvas> element in
HTML, the image produced by the element() function stays in sync,
allowing dynamic and interesting effects to be produced.</p>
<p>The ‘<code class=css>element()</code>’ function takes a
single argument, which must be an ID Selector. If no element in the
document matches the selector, the function represents a fully
transparent image with no intrinsic dimensions, equivalent to
<code>image(transparent)</code>. Otherwise, the function represents an
image with width and height equal to the width and height of the
matched element, with an appearance exactly equivalent to that of the
referenced element. Whether or not the referenced element is currently
being rendered on-screen, for media types where this is relevant, must
not affect the appearance of the image represented by the function; the
image must always be equivalent to how the element would appear when
rendered on-screen. If the document changes so that which element is
matched, or whether an element is matched at all, changes, the image
represented by the function must change accordingly.</p>
<p>If the argument passed to ‘<code
class=css>element()</code>’ isn't an id selector, but is a valid
selector otherwise, the function represents a fully transparent image
with no intrinsic dimensions. If the argument isn't a valid selector,
it is a syntax error.</p>
<p class=issue>I'm currently defining this to only take an id selector,
but I'd like for it to take arbitrary selectors, and represent the
first matched element. This is necessary for the re-use of this
function in other specifications like Positioned Layout. Should I just
bite the bullet and make it a generic selector now?</p>
<div class=example> TODO: create reasonable example</div>
</div>
<div>
<h4 class=no-toc id=the-element-ref-function><span class=secno>4.3.2.
</span>The ‘<code class=css>element-ref()</code>’ function</h4>
<p>The ‘<code class=css>element-ref()</code>’ function does
essentially the same thing as the ‘<code
class=css>element()</code>’ function - it allows the author to
use an element as an image. The difference is in how it references the
element - rather than taking a selector, it just takes an identifier,
which is mapped to some element by the host language.</p>
<p>The ‘<code class=css>element-ref()</code>’ function takes
a single argument, which must be an IDENT. The host language for the
document may expose a method of associating elements with identifiers
for the purpose of this function; CSS does not define how this occurs.
The identifiers for this function exist in a unique namespace and must
not overlap with other identifiers used elsewhere in CSS. If an element
is associated with the identifier passed to the function, the function
represents an image in an identical manner to the ‘<code
class=css>element()</code>’ function, with the element associated
with the identifier in place of the element matched by the selector. If
no element is associated with the identifier passed to the function,
the function represents a fully transparent image with no intrinsic
dimensions. If the element associated with the identifier, or whether
an element is associated with the identifier at all, changes, the image
represented by the function must change accordingly.</p>
<p>If the argument passed to ‘<code
class=css>element-ref()</code>’ isn't an IDENT, it is a syntax
error.</p>
<div class=example> TODO: Create html example using canvas</div>
</div>
</div>
<div>
<h2 id=gradients><span class=secno>5. </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 two functions 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. Gradients are a type of image, and can be used anywhere an image
can, such as in the <code>background-image</code> or
<code>list-style-image</code> properties. For official purposes, the
syntax of a <a href="#ltgradient"><code><gradient></code></a> is:</p>
<pre
class=prod><dfn id=ltgradient><gradient></dfn> = [ <linear-gradient> | <radial-gradient> ]</pre>
<p>where <a
href="#ltlinear-gradient"><code><linear-gradient></code></a> and <a
href="#ltradial-gradient"><code><radial-gradient></code></a> are
defined in their applicable sections below.</p>
<div class=example>
<p>As with the other <image> types defined in this specification,
gradients can be used in any property that accepts images. For example:</p>
<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 class=note>In many places this section references a box, such as "the
box's top-left corner" or "the box's right side". In all of these
circumstances, the "box" refers to the ‘<a
href="#css-view-box"><code class=css>CSS View Box</code></a>’ (see
the "Sizing Images and Objects in CSS" section of this spec for
clarification). A gradient has no intrinsic dimensions. This means that,
for example, if you use a gradient in a background-image, the "box" will
simply be the size of the background area. If you use a gradient in a
list-style-image, the "box" will be a 1em square.</p>
<div>
<h3 id=linear-gradients><span class=secno>5.1. </span>Linear Gradients</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 perdendicular 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>
<div>
<h4 class=no-toc id=linear-gradient-syntax><span class=secno>5.1.1.
</span><code>linear-gradient()</code> syntax</h4>
<pre
class=prod><code><dfn id=ltlinear-gradient><linear-gradient></dfn> = linear-gradient(
[
[ [top | bottom] || [left | right] ]
||
<angle>
,]?
<color-stop>[, <color-stop>]+
);</code></pre>
<p>The first argument to the function specifies the
<strong>gradient-line</strong>, which gives the gradient a direction
and determines how color-stops are positioned. It may be omitted; if
so, it defaults to "<code>top</code>".</p>
<p>The gradient-line may be specified in two different ways. The first
is by specifying the angle the gradient-line should assume; this uses
the standard algebraic notation for angles where 0deg points to the
right, 90deg points up, and positive angles go counterclockwise. The
starting-point and ending-point of the gradient-line are determined by
extending a line in both direction from the center of the box at the
angle specified. In the direction of the angle, the ending-point is
the point on the gradient-line line where a line drawn perpendicular
to the gradient-line would intersect the corner of the box in that
direction. The starting-point is determined identically, except in the
opposite direction of the angle.</p>
<p>The second way is to simply provide a side or corner of the box that
the gradient should start at; the gradient will then automatically
angle itself to extend from the specified side or corner to the
opposite side or corner in a straight line. To be precise, the
gradient is converted to the angle form described in the previous
paragraph at used-value time. If a <code>left</code>,
<code>bottom</code>, <code>right</code>, or <code>top</code> is given,
the used value of the gradient is 0deg, 90deg, 180deg, or 270 deg,
respectively. If a corner is given, the used value of the gradient is
the angle necessary to place the starting-point of the gradient in
that corner of the box.</p>
<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-poin
508C
t 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
gradient-line from the rules above. This shows the starting and
ending-point of the gradient-line, along with the actual gradient,
produced by an element with ‘<code class=css>background:
linear-gradient(45deg, white, black);</code>’.</p>
<p>Notice how, though the starting-point and ending-point are outside
of the box, they're positioned precisely right so that the gradient
is pure white <em>exactly</em> at the corner, and pure black
<em>exactly</em> at the opposite corner. That's intentional, and
will always be true for linear gradients.</p>
</div>
</div>
<p>The gradient's color stops are typically placed between the
starting-point and ending-point on the gradient-line, but this isn't
required - the gradient-line extends infinitely in both directions.
The starting-point and ending-point are merely arbitrary distance
markers - the starting-point defines where 0%, 0px, etc are located
when specifying color-stops, and the ending-point defines where 100%
is located. Color stops are allowed to have positions before 0% or
after 100%.</p>
</div>
<h4 class=no-toc id=linear-gradient-examples><span class=secno>5.1.2.
</span>Linear Gradient Examples</h4>
<p>All of the following <code>linear-gradient()</code> examples are
presumed to be backgrounds applied to a box that is 200px wide and
100px tall.</p>
<div class=example>
<p>Below are various ways of specifying a basic vertical gradient:</p>
<pre><code>linear-gradient(yellow, blue);
linear-gradient(top, yellow, blue);
linear-gradient(bottom, blue, yellow);
linear-gradient(-90deg, yellow, blue);
linear-gradient(270deg, yellow, blue);
linear-gradient(top, yellow 0%, blue 100%);</code></pre>
<p><img alt="" src=linear1.png></p>
</div>
<div class=example>
<p>This gradient goes from the upper-left to the lower-right corner.</p>
<pre><code>linear-gradient(top left, yellow, blue);</code></pre>
<p><img alt="" src=linear2.png></p>
</div>
<div class=example>
<p>This demonstrates the use of an angle in the gradient. Compare this
image with the previous example. In both gradients, the top-left of
the box is pure yellow, and the bottom-right of the box is pure blue.
The difference is in the angle that the gradient follows.</p>
<pre><code>linear-gradient(-45deg, yellow, blue);
linear-gradient(315deg, yellow, blue);</code></pre>
<p><img alt="" src=linear3.png></p>
</div>
<div class=example>
<p>This demonstrates a 3-color gradient, and how to specify the
location of a stop explicitly:</p>
<pre><code>linear-gradient(yellow, blue 20%, #0f0);</code></pre>
<p><img alt="" src=linear4.png></p>
</d
BB34
iv>
</div>
<div>
<h3 id=radial-gradients><span class=secno>5.2. </span>Radial Gradients</h3>
<p>In a radial gradient, rather than colors smoothly fading from one
side of the box to the other as with linear gradients, they instead
emerge from a single point and smoothly spread outward in a circular or
elliptical shape.</p>
<p>A radial gradient is specified by first pinpointing the center of the
gradient, where the 0% ellipse will be, then specifying the size and
shape of the 100% ellipse, ending with a list of color-stops just like
a linear-gradient. Between the center and the ending-ellipse, and past
the ending-ellipse, concentric ellipses are drawn and colored according
to the specified color-stops.</p>
<h4 class=no-toc id=radial-gradient-syntax><span class=secno>5.2.1.
</span><code>radial-gradient()</code> Syntax</h4>
<pre
class=prod><code><dfn id=ltradial-gradient><radial-gradient></dfn> = radial-gradient(
[<bg-position>,]?
[
[<shape> || <size>]
|
[<length> | <percentage>]{2}
,]?
<color-stop>[, <color-stop>]+
)</code></pre>
<p>The first argument to the function specifies the center of the
ellipse. <code><bg-position></code> is taken from the Backgrounds
and Borders Module, and has the same definition. It specifies the
center of the gradient. If omitted, it defaults to <code>center</code>.
Color-stop positions are measured along an imaginary line extending
from the center of the gradient to the right.</p>
<p>The second argument to the function specifies the size and shape of
the ending-ellipse. This can be specified in two ways, with different
characteristics:</p>
<dl>
<dt>Implicitly
<dd>
<p>The size and shape of the ending-ellipse can be defined
<em>implicitly</em> with a size and shape keyword. The <a
href="#ltshape"><code><shape></code></a> is defined as</p>
<pre><code><dfn id=ltshape><shape></dfn> = [ circle | ellipse ]</code></pre>
<p><code>circle</code> indicates that the ending-ellipse will be a
circle with a constant radius. <code>ellipse</code> indicates that
the gradient-shape will be an axis-aligned ellipse (that is, its
major and minor radiuses will be horizontal and vertical, not
necessarily in that order).</p>
<p>The <a href="#ltsize"><code><size></code></a>keyword is defined
as</p>
<pre><code><dfn id=ltsize><size></dfn> = [ closest-side | closest-corner | farthest-side | farthest-corner | contain | cover ]</code></pre>
<p>If <code><shape></code> is <code>circle</code> and
<code><size></code> is <code>closest-side</code>, the
ending-shape is a circle sized so that it exactly meets the side of
the box closest to its center. For example, if the box was 100px wide
and 200px tall, and the starting-point of the gradient-line was
<code>'10% 10%'</code>, then the closest side is the left side of the
box (it is 10px from the starting-point, while the top is 20px from
it, and the right and bottom sides are much further). The
gradient-shape would be a circle with a radius of 10px. If
<code><shape></code> is <code>ellipse</code> and
<code><size></code> is <code>closest-side</code>, the
gradient-shape is an ellipse sized so that it exactly meets the
vertical and horizontal sides of the box closest to its center. Using
the same box and starting-point as the previous example, the
gradient-shape would be an ellipse with a 20px vertical radius and a
10px horizontal radius. (If necessary, such as if the starting-point
is outside of the box, extend the sides of the box so that there is a
line the ellipse can meet.)</p>
<p><code>farthest-side</code> is identical to
<code>closest-side</code>, except that the gradient-shape is sized to
meet the side of the box that is farthest from its center (or the
farthest vertical and horizontal sides, in the case of
<code>ellipse</code>). <code>closest-corner</code> and
<code>farthest-corner</code> size the gradient-shape so that it
exactly meets the closest or farthest corner of the box from its
center, respectively. If <code><shape></code> is
<code>ellipse</code>, the gradient-shape has the same ratio of width
to height that it would if <code>closest-side</code> or
<code>farthest-side</code> were specified, as appropriate.
<code>contain</code> is a synonym for <code>closest-side</code>, and
<code>cover</code> is a synonym for <code>farthest-corner</code>.</p>
<p>If this implicit form is used, then it is converted to an
equivalent explicit form (described below) at used-value time.</p>
<dt>Explicitly
<dd>
<p>Alternately, the ending-shape's size and shape can be defined
explicitly, by providing two lengths or percentages. These measure
the length of the horizontal and vertical axes of the ellipse,
respectively. (The axis length is the length from the center of the
ellipse to the edge, similar to the radius of a circle, not the
diameter.)</p>
<p>Percentages used in the first value are relative to the width of
the box, while percentages used in the second value are relative to
the height of the box.</p>
<p>Both of the values must be positive - specifying either as zero or
negative is a syntax error.</p>
</dl>
<p>If this argument is omitted, it defaults to <code>ellipse
cover</code>.</p>
<p>In certain circumstances the given parameters may define a degenerate
shape - a circle or ellipse with a radius of 0. In these instances the
gradient image is just a solid color equal to the color of the last
color-stop in the rule. The following combinations of values will
trigger this: <code>closest-side</code> if the starting-point is on a
box edge, <code>closest-corner</code> if the starting-point is on a box
corner, and <code>ellipse</code> and <code>closest-corner</code> if the
starting-point is on a box edge.</p>
<p>The ending-point of the gradient-line is determined by extending a
line from the starting-point in the direction specified by the
<code><angle></code> in the first argument. The ending-point is
where this line intersects the gradient-shape.</p>
<p><a href="#ltcolor-stopgt"><code><color-stop></code></a> is
defined identically to its treatment in <code>linear-gradient()</code>.
Color-stops are placed on an imaginary line extending from the center
of the gradient, with the 0% point at the center of the gradient, and
100% at the point where the line intersects the ending-ellipse. The
color of each ellipse is equal to the color of the line where the
ellipse intersects it. Distances past 100% can be specified, and simply
indicate a color-stop placed on the line a corresponding distance from
the center. Negative distances are allowed in a radial gradient and
work the same as in linear gradients with respect to setting the color
of the gradient-line, but colors before the starting-point of the
gradient-line are not displayed. For example, <code>radial-gradient(red
-50px, yellow 100px)</code> would produce an elliptical gradient which
starts with a reddish-orange color in the center (the color 1/3 between
red and yellow) and transitions to yellow at 100px wide.</p>
<h4 class=no-toc id=radial-gradient-examples><span class=secno>5.2.2.
</span>Radial Gradient Examples</h4>
<p>All of the following examples are applied to a box that is 200px wide
and 100px tall.</p>
<div class=example>
<p>These examples demonstrate the basic syntax for radial gradients:</p>
<pre><code>radial-gradient(yellow, green);
radial-gradient(center, ellipse cover, yellow 0%, green 100%);
radial-gradient(50% 50%, farthest-corner, yellow, green);</code></pre>
<p><img alt="" src=radial1.png></p>
<pre><code>radial-gradient(circle, yellow, green);</code></pre>
<p><img alt="" src=radial2.png></p>
<pre><code>radial-gradient(red, yellow, green);</code></pre>
<p><img alt="" src=radial3.png></p>
</div>
<div class=example>
<p>This image shows a gradient originating from somewhere other than
the center of the box:</p>
<pre><code>radial-gradient(bottom left, farthest-side, red, yellow 50px, green);</code></pre>
<p><img alt="" src=radial4.png></p>
</div>
<div class=example>
<p>Here we illustrate a ‘<code
class=property>contain</code>’ gradient.</p>
<pre><code>radial-gradient(20px 30px, contain, red, yellow, green);
radial-gradient(20px 30px, 20px 30px, red, yellow, green);</code></pre>
<p><img alt="" src=radial6.png></p>
<pre><code>radial-gradient(20px 30px, circle contain, red, yellow, green);
radial-gradient(20px 30px, 20px 20px, red, yellow, green);</code></pre>
<p><img alt="" src=radial7.png></p>
</div>
</div>
<!-- Removed for lack of a use-case; we'll just leave it as a vendor-prefix for now.
<div>
<h3>Repeating Gradients</h3>
<p>In addition to the <code>linear-gradient()</code> and <code>radial-gradient()</code> functions, this specification defines <code>repeating-linear-gradient()</code> and <code>repeating-radial-gradient()</code> functions. These two functions take the same values and are interpreted the same as their respective non-repeating siblings defined previously. However, the color-stops are repeated infinitely in both directions, with their positions shifted by multiples of the difference between the last color-stop's position and the first color-stop's position. For example, <code>repeating-linear-gradient(red 10px, blue 50px)</code> is equivalent to <code>linear-gradient(..., red -30px, blue 10px, red 10px, blue 50px, red 50px, blue 90px, ...)</code>. Note that the last color-stop and first color-stop will always coincide at the boundaries of each group, which may produce sharp transitions if the gradient does not start and end with the same color.</p>
<div class=example>
<p>Repeating gradient syntax is basically identical to that of non-repeating gradients:</p>
<pre><code>repeating-linear-gradient(red, blue 20px, red 40px)</code></pre>
<p><img src="repeating1.png" alt=""></p>
<pre><code>repeating-radial-gradient(red, blue 20px, red 40px)</code></pre>
<p><img src="repeating2.png" alt=""></p>
<pre><code>repeating-radial-gradient(20px 30px, circle contain, red, yellow, green 100%, yellow 150%, red 200%)</code></pre>
<p><img src="repeating3.png" alt=""></p>
</div>
<p>If the difference in the first and last color-stops is 0 (for example, in the rule <code>linear-gradient(red 10px, blue 10px)</code>), the gradient defines a solid-color image with the color of the last color-stop in the rule (in this case, then, it would simply define a blue image).</p>
</div>
-->
<div>
<h3 id=color-stop-syntax><span class=secno>5.3.
</span><code>color-stop</code> Syntax</h3>
<p>The <dfn id=ltcolor-stopgt><code><color-stop></code></dfn> is
defined as:</p>
<pre
class=prod><code><dfn id=ltcolor-stop><color-stop></dfn> = <color> [ <percentage> | <length> ]?</code></pre>
<p>Color-stops are points placed along the line defined by the
gradient-line at the beginning of the rule. Color-stops must be
specified in order. Percentages refer to the length of the
gradient-line, with 0% being at the starting point and 100% being at
the ending point. Lengths are measured from the starting-point in the
direction of the ending-point. Color-stops are usually placed between
the starting-point and ending-point, but that's not required; the
gradient-line extends infinitely in both directions, and a color-stop
can be placed at any position on the line.</p>
<p>At each color-stop, the line is the color of the color-stop. Between
two color-stops, the line's color is linearly interpolated between the
colors of the two color-stops, with the interpolation taking place in
premultiplied RGBA space. Before the first color-stop, the line is the
color of the first color-stop. After the last color-stop, the line is
the color of the last color-stop.</p>
<p>The following steps must be applied <em>in order</em> to process the
list of color-stops. After applying these rules, all color-stops will
have a definite position and they will be in ascending order:</p>
<ol>
<li>If the first color-stop does not have a position, its position
defaults to 0%. If the last color-stop does not have a position, its
position defaults to 100%.
<li>If a color-stop has a position that is less than the specified
position of any color-stop before it in the list, its position is
changed to be equal to the largest specified position of any
color-stop before it.
<li>If any color-stop still does not have a position, then, for each
run of adjacent color-stops without positions, set their positions so
that they are evenly spaced between the preceding and following
color-stops with positions.
</ol>
<p>If multiple color-stops have the same position, they produce an
infinitesimal transition from the one specified first in the rule to
the one specified last. In effect, the color suddenly changes at that
position rather than smoothly transitioning.</p>
<p class=note>It is recommended that authors not mix different types of
units, such as px, em, or %, in a single rule, as this can cause a
color-stop to unintentionally try to move before an earlier one. For
example, the rule <code>background-image: linear-gradient(red, yellow
100px, blue 50%)</code> would work as expected as long as the
background area is at least 200px tall. If it was 150px tall, however,
the blue color-stop's position would be equivalent to "75px", which
precedes the yellow color-stop, and would be corrected to a position of
100px.</p>
</div>
<div>
<h3 id=interpolating-gradients><span class=secno>5.4.
</span>Interpolating Gradients</h3>
<p>Gradient images can be interpolated directly in CSS transitions and
animations, smoothly animating from one gradient to another. There are
only a few restrictions on what gradients are allowed to be
interpolated:</p>
<ol>
<li>Both the starting and ending gradient must be of the same type;
either both linear gradients or both radial gradients.
<li>Both the starting and ending gradient must have the same number of
color-stops. (Remember, you can always pad a gradient with additional
color-stops placed atop each other if you need to play with the number
of color-stops.)
</ol>
<p>If the two gradients satisfy both of those constraints, they must be
interpolated as described below. If not, they must be interpolated the
same as images in general.</p>
<p>To interpolate two gradients, first convert each to their used value.
This ensures that linear gradients have their direction specified as an
angle, and radial gradients have their size and shape specified as two
lengths. Then, interpolate each component of the gradient independently
as specified by the interpolation function being used. For linear
gradients, the angle and the color-stops are the only components. For
radial gradients, the components are the horizontal position of the