-
Notifications
You must be signed in to change notification settings - Fork 790
Expand file tree
/
Copy pathOverview.src.html
More file actions
1181 lines (941 loc) · 55 KB
/
Overview.src.html
File metadata and controls
1181 lines (941 loc) · 55 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 http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>CSS Image Values and Replaced Content Module Level 3</title>
<link rel="stylesheet" type="text/css" href="http://dev.w3.org/csswg/default.css">
<link rel="stylesheet" type="text/css" href="http://www.w3.org/StyleSheets/TR/W3C-ED">
</head>
<body>
<div class="head">
<!--logo-->
<h1>CSS Image Values and Replaced Content Module Level 3</h1>
<h2 class="no-num no-toc">[LONGSTATUS] [DATE]</h2>
<dl>
<dt>This version:</dt>
<dd><a href="[VERSION]">http://www.w3.org/TR/[YEAR]/ED-css3-images-[CDATE]/</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>Editor's draft:</dt>
<dd><a href="http://dev.w3.org/csswg/css3-images/">http://dev.w3.org/csswg/css3-images/</a>
<dt>Previous version:</dt>
<dd><a href="http://www.w3.org/TR/2011/WD-css3-images-20110217/">http://www.w3.org/TR/2011/WD-css3-images-20110217/</a></dd>
<dd><a href="http://www.w3.org/TR/2009/WD-css3-images-20090723/">http://www.w3.org/TR/2009/WD-css3-images-20090723/</a></dd>
<dt>Editors:</dt>
<dd><a href="http://fantasai.inkedblade.net/contact">Elika J. Etemad</a> (Invited Expert)</dd>
<dd><a href="http://www.xanthir.com/contact">Tab Atkins Jr.</a> (Google)</dd>
</dl>
<!--begin-copyright-->
<p>[Here will be included the file "../copyright.inc"]</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 <i><image></i> values in CSS.
<i><image></i> values can be a single URI to an image, a list of
URIs denoting a series of fallbacks, a reference to an element in the document, 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.</p>
<p>The following properties and values are 'at-risk', which means they may be removed from this specification if they do not achieve two interoperable implementations in a reasonable amount of time:</p>
<ol>
<li>The element() function</li>
<li>The object-fit and object-position properties</li>
</ol>
<!-- ====================================================================== -->
<h2 class="no-num no-toc" id="status">
Status of this document</h2>
<!--status-->
<!-- ====================================================================== -->
<h2 class="no-num no-toc" id="contents">
Table of contents</h2>
<!--toc-->
<!-- ====================================================================== -->
<h2 id="intro">
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
'background-image' 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
reference to an element in the document, and as a gradient.</p>
<!-- ====================================================================== -->
<h2 id="conformance">
Conformance</h2>
<p>A document or implementation cannot conform to CSS Image Values & Replaced Content Level 3
alone, but can claim conformance to CSS Image Values & Replaced Content 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 Image Values & Replaced Content Level 3 is defined for three classes:
<dl>
<dt><dfn>minimal</dfn></dt>
<dd>A device that does not implement CSS Transitions, CSS Animations, nor
CSSOM may ignore the chapters on Serializing and Interpolating values for
the purpose of claiming conformance.</dd>
<dt><dfn>transition-capable</dfn></dt>
<dd>A device that implements CSS Transitions or CSS Animations must conform
to the <i>minimal</i> class, and additionally must implement the chapter
on Interpolation.</dd>
<dt><dfn>CSSOM-capable</dfn></dt>
<dd>A device that implements CSSOM must conform to the <i>minimal</i> class,
and additionally must implement the chapter on Serialization.</dd>
</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. [[!RFC2119]]</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>
<!-- ====================================================================== -->
<h2 id='resolution-units'>
Resolution Units: the <resolution> value type</h2>
<p>This specification defines the following units as part of the <dfn><resolution></dfn>
value type:</p>
<dl>
<dt><dfn>dpi</dfn></dt>
<dd>dots per inch</dd>
<dt><dfn>dpcm</dfn></dt>
<dd>dots per centimeter</dd>
<dt><dfn>dppx</dfn></dt>
<dd>dots per ''px'' unit</dd>
</dl>
<p>The <resolution> unit represents the size of a single "dot" of an image. For raster images,
a dot is an image pixel. A <resolution> defines how many of these dots fit in a CSS 'in', 'cm', or 'px' so that
images can be sized accordingly. The default resolution of raster images in CSS is ''1dppx'',
which is equivalent to ''96dpi''. The concept of "resolution" does not apply to vector image
formats like SVG; generally, this means that any attempt to change the resolution of a vector
image is simply meaningless. Individual uses of the <resolution> value define precisely
what effects they have on raster and vector images.</p>
<div class='example'>
<p>Printers tend to have substantially higher resolution than computer monitors; due to this,
an image that looks fine on the screen may look pixellated when printed out. A
<resolution> may be used in the 'image-resolution' property to embed a high-resolution
image into the document that maintains an appropriate size, ensuring attractive display
both on screen and on paper:</p>
<pre class='css'><code>
img.high-res {
image-resolution: 300dpi;
}</code></pre>
<p>With this set, an image meant to be 5 inches wide that was saved at 300dpi will actually
display as 5 inches wide; without this set, the image would display as approximately 15.6 inches
wide since the image is 15000 image pixels across, and by default there are 96 image pixels per
inch.</p>
</div>
<!-- ====================================================================== -->
<h2 id="image">
Image Values: the <image> value type</h2>
<p>The <image> value type denotes a 2D image. It is defined as
<pre class="prod"><dfn><image></dfn> = <url> | <image-list> | <element-reference> | <image-combination> | <gradient></pre>
<p>Image values can be used in many CSS properties, including the
'background-image', 'list-style-image', 'cursor' properties [[!CSS21]].
<!-- ====================================================================== -->
<h3 id="url">
Image References and Image Slices: the ''url()'' 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">''url()'' notation</a>,
defined in [[!CSS21]].
<div class="example">
<p>In the example below, a background image is specified with ''url()''
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
<a href="http://www.w3.org/TR/media-frags/#naming-space">media fragment identifiers</a>.
[[!MEDIA-FRAGS]]
<div class="example">
<p>For example, given the following image* and CSS:</p>
<a href="sprites.svg">
<img src="sprites.svg" height="20" width="180" alt="[9 circles, with 0 to 8 eighths filled in]">
</a>
<pre>background-image: url('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>
<p><small>* SVG-in-<img> support required. Click the picture to view the SVG directly.</small></p>
</div>
<p class="note">Note that a legacy UA that doesn't understand the media
fragments notation will ignore the fragment and simply display the
entirety of an image specified with ''url''. However, since URLs with
media fragment identifiers can also be used in the ''image()'' notation
defined below, authors can take advantage of CSS's forward-compatible
parsing rules to provide a fallback when using an image fragment URL:</p>
<div class="example">
<p>In the example below, the ''image()'' notation is used together with
the media fragment syntax, so that UAs that don't support media fragments
fail to parse the second declaration and use the first.</p>
<pre>
<!-- -->background-image: url('swirl.png'); /* old UAs */
<!-- -->background-image: image('sprites.png#xywh=10,30,60,20'); /* new UAs */</pre>
</div>
<!-- ====================================================================== -->
<h3 id='element-reference'>
Using Elements as Images: the ''element()'' notation</h3>
<p>The ''element()'' function allows an author to reference an element in
the document that should be used as an 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 effects such as
script-animated background images or previews of the next slide in a slideshow.
The syntax for ''element()'' is defined as:</p>
<pre class=prod><dfn><element-reference></dfn> = element( [<id-selector> | <identifier> ] )</pre>
<p>where <id-selector> is an ID selector [[!SELECT]], and <identifier>
is an identifer [[!CSS3VAL]].</p>
<p>If the argument to the ''element()'' function is an ID selector, the
function references the element matched by the selector. If it's an identifier,
the function references the element whose <dfn>CSS element reference identifier</dfn>
is the given identifier. (CSS does not define how an element acquires a
<i>CSS element reference identifier</i>; that is determined by the host language.)
If no element in the document matches the selector, or no element has the
identifier as its <i>CSS element reference identifier</i>, the function
represents a fully transparent image with no intrinsic dimensions, equivalent
to <code>image(transparent)</code>. 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 ''element()'' function refers to an element, then it represents
an image with width and height equal to the width and height of the margin
box of the referenced element. The image must be constructed by rendering
the referenced element and its descendants at the same size that the element
would be in its document, over an infinite transparent black background,
positioned so that the edges of the margin box of the element is flush with
the edges of the image. <span class=note>If the element has decorations
or descendants that extend outside the margin box, these will be clipped
to the margin box in the generated image by default. ''background-repeat:extend''
may allow the author to override this behavior so that decorations and
descendants outside the margin box are still painted.</span> If the
referenced element or an ancestor of the referenced element has a transform
applied to it, the transform must be ignored for the purpose of constructing
this image (transforms on descendants must be unaffected).</p>
<p>If the argument passed to ''element()'' isn't an ID selector or an ident,
it is a syntax error.</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>
TODO: copy an example from the MozHacks article
</div>
<!-- ====================================================================== -->
<h4 class="no-num no-toc" id='element-cycles'>
Detecting and Resolving Circular Relationships Introduced by ''element()''</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>Populate the dependency graph initially by having every element depend
on each of its children. Then, whenever a property on an element A uses
the ''element()'' function to refer to an element B, add an edge to the
graph by having A depend on B. If a dependency cycle is detected, any
''element()'' functions that produced a dependency in the cycle represent
a fully transparent image with no intrinsic dimensions.</p>
<p class=issue>Someone else needs to review this and make sure that I'm
not missing any cycles.</p>
<h2 id="gradients">
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.
The syntax of a <i><gradient></i> is:</p>
<pre class=prod><dfn><gradient></dfn> = [ <linear-gradient> | <radial-gradient> | <repeating-linear-gradient> | <repeating-radial-gradient> ]</pre>
<p>where <i><linear-gradient></i>, <i><radial-gradient></i>,
<i><repeating-linear-gradient></i>, and <i><repeating-radial-gradient></i> are
defined in their applicable sections below.</p>
<p>Gradients are a type of image, and can be used anywhere an image can,
such as in the 'background-image' or 'list-style-image' properties.
<div class=example>
<p>As with the other <i><image></i> 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>
<li><code>list-style-image: radial-gradient(circle, #006, #00a 90%, #0000af 100%, white 100%)</code></li>
</ul>
</div>
<p>A gradient is drawn into a box with the dimensions of the <i>concrete
object size</i>. Elsewhere in this section this rectangle is simply
called the "box".
<p>A gradient has no <i>intrinsic dimensions</i>. This means that, for
example, if you use a gradient in the 'background-image' property (with
'background-size' at the default value and 'background-repeat' not equal to
'round'), the box will simply be the size of the background sizing
area. Similarly, for a gradient used as a list-style-image, the box
would be a 1em square.
<p class=issue>It has been suggested that several of the controls offered by gradients are unnecessary. Repeating gradients could potentially be done by hooking into ‘background-repeat’, sizing and positioning radial gradients could be done by hooking into ‘background-size’ and ‘background-position’, etc.</p>
<!-- ====================================================================== -->
<h3 id='linear-gradients'>
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>
<!-- ====================================================================== -->
<h4 class='no-toc' id='linear-gradient-syntax'>
linear-gradient() syntax</h4>
<pre class=prod><code><dfn><linear-gradient></dfn> = linear-gradient(
[[ <angle> | upward | rightward | leftward | downward ],]?
<color-stop>[, <color-stop>]+
);</code></pre>
<p>The first argument to the function specifies the <dfn>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 "downward".</p>
<p>The <i>gradient-line</i> may be specified in two different ways. The
first is by specifying the angle the <i>gradient-line</i> should assume;
for the purposes of this argument, 0deg points upwards, 90deg points toward
the right, and positive angles go clockwise.
The starting-point and ending-point of the <i>gradient-line</i> are
determined by extending a line in both directions from the center of the
box at the angle specified. In the direction of the angle, the ending-point
is the point on the <i>gradient-line</i> where a line drawn perpendicular
to the <i>gradient-line</i> 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>Alternately, a keyword may be used to indicate the <i title="gradient-line">gradient-line's</i> direction. The "upward" keyword places the starting-point of the gradient-line in the center of the bottom edge of the box and the ending-point of the <i>gradient-line</i> in the center of the top edge of the box, similar to how a value of "0deg" works. The "rightward", "downward", and "leftward" keywords are defined the same, <i>mutatis mutandis</i>.</p>
<div class=example>
<div style="overflow: hidden">
<img style="float: right; margin-left: 1em;" src='gradient-diagram.png' 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.]">
<p>This example illustrates visually how to calculate the
<i>gradient-line</i> from the rules above. This shows the starting
and ending-point of the <i>gradient-line</i>, along with the actual
gradient, produced by an element with
''background: linear-gradient(45deg, white, black);''.</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 <i>gradient-line</i>, but this isn't required - the
<i>gradient-line</i> 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>
<!-- ====================================================================== -->
<h4 class='no-toc' id='linear-gradient-examples'>
Linear Gradient Examples</h4>
<p>All of the following ''linear-gradient()'' 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(downward, yellow, blue);
linear-gradient(180deg, yellow, blue);
linear-gradient(upward, blue, yellow);
linear-gradient(downward, yellow 0%, blue 100%);</code></pre>
<p><img src="linear1.png" alt="" ></p>
</div>
<div class=example>
<p>This demonstrates the use of an angle in the gradient. Note that, though the angle is not exactly the same as the angle between the corners, the <i>gradient-line</i> is still sized so as to make the gradient yellow exactly at the upper-left corner, and blue exactly at the lower-right corner.</p>
<pre><code>linear-gradient(135deg, yellow, blue);
linear-gradient(-45deg, blue, yellow);</code></pre>
<p><img src="linear3.png" alt="" ></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 src="linear4.png" alt="" ></p>
</div>
<!-- ====================================================================== -->
<h3 id='radial-gradients'>
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'>
radial-gradient() Syntax</h4>
<pre class=prod>
<dfn><radial-gradient></dfn> = radial-gradient(
[<bg-position>,]?
[[
[<shape> || <size>]
|
[<length> | <percentage>]{2}
],]?
<color-stop>[, <color-stop>]+
)
</pre>
<p>The first argument to the function specifies the center of the ellipse.
<i><bg-position></i> 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 ''center''. 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</dt>
<dd>
<p>The size and shape of the ending-ellipse can be defined
<em>implicitly</em> with a size and shape keyword. The <i><shape></i>
is defined as </p>
<pre><code><dfn><shape></dfn> = [ circle | ellipse ]</code></pre>
<p>''circle'' indicates that the ending-ellipse will be a circle with
a constant radius. ''ellipse'' 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 <i><size></i> keyword is defined as </p>
<pre><code><dfn><size></dfn> = [ closest-side | closest-corner | farthest-side | farthest-corner | contain | cover ]</code></pre>
<p>If <i><shape></i> is ''circle'' and <i><size></i> is ''closest-side'',
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 center of the gradient was ''10% 10%'',
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 thus be a
circle with a radius of 10px. If <i><shape></i> is ''ellipse'' and
<i><size></i> is ''closest-side'', 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>''farthest-side'' is identical to ''closest-side'', 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, if
the shape is ''ellipse''). ''closest-corner'' and ''farthest-corner''
size the gradient-shape so that it exactly meets the closest or farthest
corner of the box from its center, respectively. If <i><shape></i>
is ''ellipse'', the gradient-shape has the same ratio of width to height
that it would if ''closest-side'' or ''farthest-side'' were specified,
as appropriate. ''contain'' is a synonym for ''closest-side'', and
''cover'' is a synonym for ''farthest-corner''.</p>
</dd>
<dt>Explicitly</dt>
<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 non-negative. Specifying either as
''0'' is allowed, but produces a degenerate shape. The handling of
degenerate ending-shapes is specified later in this specification.</p>
</dd>
</dl>
<p>If this argument is omitted, it defaults to ''ellipse cover''.</p>
<p>If only one argument is provided before the color-stops, and it could
be interpreted as either a position or an explicit size (for example, in
''radial-gradient(10% 10%, red, blue)''), it must be interpreted as a position.</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:
''closest-side'' if the starting-point is on a box edge, ''closest-corner''
if the starting-point is on a box corner, and ''ellipse closest-corner''
if the starting-point is on a box edge.</p>
<p>Color-stops are placed on an imaginary line extending from the center
of the gradient toward the right, 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
<i>gradient-line</i>, but colors before the starting-point of the <i>gradient-line</i>
are not displayed. For example, ''radial-gradient(red -50px, yellow 100px)''
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'>
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 src="radial1.png" alt="" ></p>
<pre><code>radial-gradient(circle, yellow, green);</code></pre>
<p><img src="radial2.png" alt="" ></p>
<pre><code>radial-gradient(red, yellow, green);</code></pre>
<p><img src="radial3.png" alt="" ></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 src="radial4.png" alt="" ></p>
</div>
<div class=example>
<p>Here we illustrate a 'contain' 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 src="radial6.png" alt="" ></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 src="radial7.png" alt="" ></p>
</div>
<!-- ====================================================================== -->
<h3 id='repeating-gradients'>
Repeating Gradients</h3>
<p>In addition to the ''linear-gradient()'' and ''radial-gradient()'' functions,
this specification defines ''repeating-linear-gradient()'' and
''repeating-radial-gradient()'' functions. These two functions take the
same values and are interpreted the same as their respective non-repeating
siblings defined previously:</p>
<pre class=prod><code><dfn><repeating-linear-gradient></dfn> = repeating-linear-gradient(
[[ <angle> | upward | rightward | downward | leftward ],]?
<color-stop>[, <color-stop>]+
)
<dfn><repeating-radial-gradient></dfn> = repeating-radial-gradient(
[<bg-position>,]?
[[
[<shape> || <size>]
|
[<length> | <percentage>]{2}
],]?
<color-stop>[, <color-stop>]+
)</code></pre>
<p>When rendered, however, the color-stops are repeated infinitely in both
directions, with their positions shifted by multiples of the difference
between the last specified color-stop's position and the first specified
color-stop's position. For example, ''repeating-linear-gradient(red 10px, blue 50px)''
is equivalent to ''linear-gradient(..., red -30px, blue 10px, red 10px, blue 50px, red 50px, blue 90px, ...)''.
Note that the last color-stop and first color-stop will always coincide at
the boundaries of each group, which will 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 distance between the first and last color-stops is zero, the gradient must be rendered as a solid-color image equal to the "average" color of the gradient, determined by linearly blending the colors of all the color-stops in premultipied sRGBA space.</p>
<p>If the distance between the first and last color-stops is non-zero, but is small enough that the implementation knows that the physical resolution of the output device is insufficient to faithfully render the gradient, the gradient must be rendered as a solid-color image equal to the weighted average color of the gradient, as determined by the following algorithm:</p>
<ol>
<li>Define <var>list</var> as an initially-empty list of premultiplied RGBA colors, and <var>total-length</var> as the distance between first and last color stops.</li>
<li>For each adjacent pair of color-stops, define <var>weight</var> as half the distance between the two color-stops, divided by <var>total-length</var>. Add two entries to <var>list</var>, the first obtained by representing the color of the first color-stop in premultiplied sRGBA and scaling all of the components by <var>weight</var>, and the second obtained in the same way with the second color-stop.</li>
<li>Sum the entries of <var>list</var> component-wise to produce the average color.</li>
</ol>
<p class='note'>As usual, implementations may use whatever algorithm they wish, so long as it produces the same result as the above.</p>
<div class='example'>
<p class='issue'>TODO fill in examples here of the 0-length or too-small-length cases.</p>
</div>
<!-- ====================================================================== -->
<h3 id='color-stop-syntax'>
Gradient Color-Stops</h3>
<pre class=prod><code><dfn><color-stop></dfn> = <color> [ <percentage> | <length> ]?</code></pre>
<p>Color-stops are points placed along the line defined by the <i>gradient-line</i>
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>
<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>
<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.</li>
</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
''background-image: linear-gradient(red, yellow 100px, blue 50%)'' 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>
<p class=note>The definition and implications of "premultiplied" color spaces
are given elsewhere in the technical literature, but a quick primer is given
here to illuminate the process. Given a color expressed as an rgba() 4-tuple,
one can convert this to a premultiplied representation by multiplying the
red, green, and blue components by the alpha component. For example, a
partially-transparent blue may be given as rgba(0,0,255,.5), which would
then be expressed as [0, 0, 127.5, .5] in its premultiplied representation.
Interpolating colors using the premultiplied representations rather than
the plain rgba representations tends to produce more attractive transitions,
particularly when transitioning from a fully opaque color to fully transparent.
Note that transitions where either the transparency or the color are held constant (for example, transitioning between rgba(255,0,0,100%) and rgba(0,0,255,100%) or rgba(255,0,0,100%) and rgba(255,0,0,0%)) have identical results whether the color interpolation is done in premultiplied or non-premultiplied color-space. Differences only arise when both the color and transparency differ between the two endpoints.</p>
<!-- ====================================================================== -->
<h2 id="sizing">
Sizing Images and Objects in CSS</h2>
<p>Images used in CSS may come from a number of sources, from defined image
formats (such as gif, jpeg, etc), dedicated markup formats (such as SVG), and
CSS-specific formats (such as the linear-gradient() value type defined in this
specification). As well, a document may contain many other types of objects,
such as video, plugins, or nested documents. These images and objects (just
<dfn>objects</dfn> hereafter) may offer many types of sizing information to CSS, or none
at all. This section defines generically the size negotiation model between
the object and the CSS layout algorithms.</p>
<!-- ====================================================================== -->
<h3 id="sizing-terms">
Object-Sizing Terminology</h3>
<p>In order to define this handling, we define a few terms, to make it
easier to refer to various concepts:</p>
<dl>
<dt><dfn>intrinsic dimensions</dfn></dt>
<dd>
<p>An object's intrinsic dimensions are its preferred, natural width,
height, and aspect ratio, if they exist. There can be an <dfn>intrinsic height</dfn>
and <dfn>intrinsic width</dfn>, defining a definite rectangle. (Most bitmap
images fall into this category.) There can be an <dfn>intrinsic aspect ratio</dfn>
defining the relation of the width to the height, but no definite size.
(SVG images designed to scale may fall into this category.) There can be
just an intrinsic height or width. Or there can be no intrinsic dimensions
at all, implying that the object has no preferred size or aspect ratio.
(Embedded documents are often assumed to have no intrinsic size, as are
CSS gradients, defined in this specification.)</p>
<p>If an object (such as an icon) has multiple sizes, then the largest
size is used. If it has multiple aspect ratios of that size (or of no
size), then the aspect ratio closest to the aspect ratio of the
<i>default object size</i> is used.</p>
</dd>
<dt><dfn>specified size</dfn></dt>
<dd>The specified size of an object is given by CSS, such as through the
'object-fit' or 'background-size' properties. The specified size can be a
definite width and height, a set of constraints, or a combination thereof.</dd>
<dt><dfn>concrete object size</dfn></dt>
<dd>The <i>concrete object size</i> is the result of transforming the <i>intrinsic dimensions</i>
into a concrete size, based on the <i>specified size</i> and the
<i>default object size</i>. A <i>concrete object size</i> always has a definite height
and width.</dd>
<dt><dfn>default object size</dfn></dt>
<dd>
<p>The <i>default object size</i> is a rectangle with a definite height and
width used to determine the <i>concrete object size</i> when both the
<i>intrinsic dimensions</i> and <i>specified size</i> are missing dimensions.
It varies based on the context in which that the image is being laid out.</p>
<div class="example">
<p>Below are some examples of default object sizing areas:
<dl>
<dt>'background-image'</dt>
<dd>The <i>default object size</i> is the size of the element's
<a href="http://www.w3.org/TR/css3-background/#background-positioning-area">background
positioning area</a>. [[CSS3BG]]</dd>
<dt>'list-style-image'</dt>
<dd>The <i>default object size</i> is a 1em square. [[!CSS21]]</dd>
<dt>'border-image'</dt>
<dd>The <i>default object size</i> is the size of the element's
<a href="http://www.w3.org/TR/css3-background/#border-image-area">border image area</a>.
[[CSS3BG]]</dd>
<dt>'cursor'</dt>
<dd>The <i>default object size</i> is a UA-defined size that should
be based on the size of a typical cursor on the UA's operating system.
[[!CSS21]]</dd>
<dt>replaced elements</dt>
<dd>The <i>default object size</i> is a rectangle 300px wide and 150px
tall. [[!CSS21]]</dd>
</dl>
<p class=issue>The only reason these are examples is because the proper
place for the normative definitions of default object sizes is in the
definitions for the relevant properties. These are the correct values,
though.</p>
</div>
</dd>
</dl>
<!-- ====================================================================== -->
<h3 id="object-negotiation">
CSS⇋Object Negotiation</h3>
<p>Objects in CSS are sized and rendered as follows:</p>
<ol>
<li>When an image or object is specified in a document, such as through a url()
value in a 'background-image' property or a @src attribute on an <img> element,
CSS queries the object for its <i>intrinsic dimensions</i>.</li>
<li>Using the <i>intrinsic dimensions</i> and the <i>specified size</i>,
CSS then computes a <i>concrete object size</i> that defines the size and
position of the region the object will render in (specified in the
following section).</li>
<li>CSS asks the object to render itself at the <i>concrete object size</i>.
CSS does not define how objects render when the <i>concrete object size</i>
is different from the object's <i>intrinsic dimensions</i>. The object may
adjust itself to match the <i>concrete object size</i> in some way, or even
render itself larger or smaller than the <i>concrete object size</i> to
satisfy sizing constraints of its own.</li>
<li>Unless otherwise specified by CSS, the object is then clipped to the
<i>concrete object size</i>.</li>
</ol>
<!-- ====================================================================== -->
<h3 id="default-sizing">
Concrete Object Size Resolution</h3>
<p>In the absence of more specific rules, an object's
<i>intrinsic dimensions</i> are resolved to a <i>concrete object size</i> as
follows:</p>
<ul>
<li>If the <i>specified size</i> is a definite width and height, the
<i>concrete object size</i> is given that width and height.</li>
<li>If the <i>specified size</i> has only a width or height, but not both,
then the <i>concrete object size</i> is given that specified width or height.
The other dimension is calculated as follows:
<ol>
<li>If the object has an <i>intrinsic aspect ratio</i>, the missing
dimension of the <i>concrete object size</i> is calculated using the
<i>intrinsic aspect-ratio</i> and the present dimension.</li>
<li>Otherwise, if the missing dimension is present in the object's
<i>intrinsic dimensions</i>, the missing dimension is taken from the
object's <i>intrinsic dimensions</i>.</li>
<li>Otherwise, the missing dimension of the <i>concrete object size</i>
is taken from the <i>default object size</i>.</li>
</ol>
</li>
<li>If the <i>specified size</i> has neither a definite width nor height, and
has no additional contraints, the dimensions of the <i>concrete object size</i>
are calculated as follows:
<ol>
<li>If the object has only an <i>intrinsic aspect ratio</i>, the
<i>concrete object size</i> must have that aspect ratio, and additionally
be as large as possible without either its height or width exceeding
the height or width of the <i>default object size</i>. Otherwise,
the width and height of the <i>concrete object size</i> is the same
as the object's <i>intrinsic width</i> and <i>intrinsic height</i>,
if they exist.</li>
<li>If the <i>concrete object size</i> is still missing a width or height,
and the object has an <i>intrinsic aspect ratio</i>, the missing dimension
is calculated from the present dimension and the <i>intrinsic aspect ratio</i>.
Otherwise, the missing dimensions is taken from the <i>default object size</i>.</li>
</ol>
</li>
</ul>
<p>If the <i>specified size</i> has additional constraints, the
<i>concrete object size</i> must be sized to satisfy those constraints.
For example, the 'min-width', 'min-height', 'max-width', and 'max-height'
properties specify slightly more complex handling for sizing replaced
elements, and ''background-repeat: round'' can further adjust
the size calculated by 'background-size' so that the image fits a whole
number of times into the background positioning area.</p>
<!-- ====================================================================== -->
<h3 id="object-fit">
Sizing Objects: the 'object-fit' property</h3>
<table class="propdef">
<tr>
<th>Name:
<td><dfn>object-fit</dfn>
<tr>
<th>Value:
<td>fill | contain | cover | none | scale-down
<tr>
<th>Initial:
<td>fill
<tr>
<th>Applies to:
<td>replaced elements
<tr>
<th>Inherited:
<td>no
<tr>
<th>Percentages:
<td>N/A
<tr>
<th>Media:
<td>visual
<tr>
<th>Computed value:
<td>specified value
</table>
<p>The 'object-fit' property specifies how the contents of a replaced element
should be scaled relative to the box established by its used height and width.
It also enables scaling a replaced element's contents up to a specified maximum
size or down to a specified minimum size while preserving its aspect ratio.