-
Notifications
You must be signed in to change notification settings - Fork 709
/
Copy pathOverview.bs
1086 lines (870 loc) · 45.8 KB
/
Overview.bs
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
<h1>CSS Image Values and Replaced Content Module Level 4</h1>
<pre class='metadata'>
Status: ED
Work Status: Exploring
Shortname: css-images
Level: 4
Group: csswg
ED: http://dev.w3.org/csswg/css-images-4/
TR: http://www.w3.org/TR/css4-images/
Editor: Tab Atkins Jr., Google, http://xanthir.com/contact/
Editor: Elika J. Etemad / fantasai, Invited Expert, http://fantasai.inkedblade.net/contact
Abstract: This is a delta spec over Images 3; when next published, it will be a real spec with everything filled in, but for now removing duplication is more important than having a complete spec.
!Issue Tracking: <a href="http://www.w3.org/Style/CSS/Tracker/products/27">http://www.w3.org/Style/CSS/Tracker/products/27</a>
Previous Version: http://www.w3.org/TR/2012/WD-css4-images-20120911/
Ignored Terms: <offset>, background positioning area, border image area, <meetorslice>, <ending-shape>, Map, <image>, invalid image, invalid images, concrete object size, linear-gradient(), radial-gradient(), intrinsic dimensions, default object size, CSS
Link Defaults: css21 (property) display, css21 (dfn) stacking context
</pre>
Images Values: the <<image>> type {#image-values}
=================================================
Image File Formats {#image-file-formats}
----------------------------------------
At minimum, the UA must support the following image file formats
when referenced from an <<image>> value,
for all the properties in which using <<image>> is valid:
<ul>
<li>PNG, as specified in [[!PNG]]
<li>SVG, as specified in [[!SVG]],
using the <a href="http://www.w3.org/TR/svg-integration/#secure-static-mode">secure static mode</a> (See [[!SVG-INTEGRATION]])
<li>If the UA supports animated <<image>>s,
SVG, as specified in [[!SVG]],
using the <a href="http://www.w3.org/TR/svg-integration/#secure-animated-mode">secure animated mode</a> (See [[!SVG-INTEGRATION]])
</ul>
The UA may support other file formats as well.
Image Fallbacks and Annotations: the ''image()'' notation {#image-notation}
---------------------------------------------------------------------------
The ''image()'' notation is defined as:
<pre class='prod'>
<dfn>image()</dfn> = image( <<image-tags>>? [ <<image-src>>? , <<color>>? ]! )
<dfn><image-tags></dfn> = [ ltr | rtl ]
<dfn><image-src></dfn> = [ <<url>> | <<string>> ]
</pre>
### Bidi-sensitive Images ### {#bidi-images}
Before listing any <code><image-src>s</code>,
the author may specify a directionality for the image,
similar to adding a <code>dir</code> attribute to an element in HTML.
If a directional image is used on or in an element with opposite <a href="http://www.w3.org/TR/CSS21/visuren.html#propdef-direction">direction</a>,
the image must be flipped in the inline direction
(as if it was transformed by, e.g., <code>scaleX(-1)</code>, if the inline direction is the X axis).
Note: Absent this declaration,
images default to no directionality at all,
and thus don't care about the directionality of the surrounding element.
<div class='example'>
A list may use an arrow for a bullet that points into the content.
If the list can contain both LTR and RTL text,
though, the bullet may be on the left or the right,
and an image designed to point into the text on one side will point out of the text on the other side.
This can be fixed with code like:
<pre>
<ul style="list-style-image: image(ltr 'arrow.png');">
<li dir='ltr'>My bullet is on the left!</li>
<li dir='rtl'>MY BULLET IS ON THE RIGHT!</li>
</ul>
</pre>
This should render something like:
<pre>
⇒ My bullet is on the left!
!THGIR EHT NO SI TELLUB YM ⇐
</pre>
In LTR list items, the image will be used as-is.
In the RTL list items, however,
it will be flipped in the inline direction,
so it still points into the content.
</div>
<!--
████████ ██ ████████ ██ ██ ████████ ██ ██ ████████ ███ ███
██ ██ ██ ███ ███ ██ ███ ██ ██ ██ ██
██ ██ ██ ████ ████ ██ ████ ██ ██ ██ ██
██████ ██ ██████ ██ ███ ██ ██████ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ███ ██ ██ ██
████████ ████████ ████████ ██ ██ ████████ ██ ██ ██ ███ ███
-->
<h3 id='element-notation'>
Using Elements as Images: the ''element()'' notation</h3>
The ''element()'' function allows an author to use an element in the document as an image.
As the referenced element changes appearance,
the image changes as well.
This can be used, for example,
to create live previews of the next/previous slide in a slideshow,
or to reference a canvas element for a fancy generated gradient or even an animated background.
Note: The ''element()'' function only reproduces the <em>appearance</em> of the referenced element,
not the actual content and its structure.
Authors should only use this for decorative purposes,
and must not use ''element()'' to reproduce an element with significant content across the page.
Instead, just insert multiple copies of the element into the document.
The syntax for ''element()'' is:
<pre class=prod><dfn>element()</dfn> = element( <<id-selector>> )</pre>
where <<id-selector>> is an ID selector [[!SELECT]].
<p class='issue'>
Do we need to be able to refer to elements in external documents
(such as SVG paint servers)?
Or is it enough to just use url() for this?
<p class='issue'>
This name conflicts with a somewhat similar function in GCPM.
This needs to be resolved somehow.
<p class='issue'>
Want the ability to do "reflections" of an element,
either as a background-image on the element or in a pseudo-element.
This needs to be specially-handled to avoid triggering the cycle-detection.
<p class='issue'>
When we have overflow:paged,
how can we address a single page in the view?
The ''element()'' function references the element matched by its argument.
The ID is first looked up in the <a idl>elementSources</a> map,
as described in that section.
If it's not found,
it's then matched against the document.
If multiple elements are matched,
the function references the first such element.
The image represented by the ''element()'' function can vary based on whether the element is visible in the document:
<dl>
<dt>
an <a lt="element-not-rendered">element that is rendered</a>,
is not a descendant of a replaced element,
and generates a <a spec=css21>stacking context</a>
<dd>
The function represents an image with its intrinsic size equal to the <dfn export>decorated bounding box</dfn> of the referenced element:
<ul>
<li>
for an element rendered using a CSS rendering model,
the <a>decorated bounding box</a> is the smallest axis-aligned rectangle
that contains the <a href="http://www.w3.org/TR/2011/CR-css3-background-20110215/#border-image-area">border image areas</a> of all the fragments of the principal box
<li>
for an element rendered using the SVG rendering model,
<a href="http://www.w3.org/TR/SVGTiny12/intro.html#TermDecoratedBoundingBox">the decorated bounding box is defined by SVG</a>
</ul>
Note: Because images clip anything outside their bounds by default,
this means that decorations that extend outside the <a>decorated bounding box</a>,
like box shadows,
may be clipped.
The image is constructed by rendering the referenced element and its descendants
(at the same size that they would be in the document)
over an infinite ''transparent'' canvas,
positioned so that the edges of the <a>decorated bounding box</a> are flush with the edges of the image.
<p class='issue'>
Requiring some degree of stacking context on the element appears to be required for an efficient implementation.
Do we need a full stacking context, or just a pseudo-stacking context?
Should it need to be a stacking context normally,
or can we just render it as a stacking context when rendering it to element()?
If the referenced element has a transform applied to it or an ancestor,
the transform must be ignored when rendering the element as an image. [[!CSS3-TRANSFORMS]]
If the referenced element is broken across pages,
the element is displayed as if the page content areas were joined flush in the pagination direction,
with pages' edges corresponding to the initial containing block's start edge aligned.
<span class='note'>Elements broken across lines or columns are just rendered with their <a>decorated bounding box</a>.</span>
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.
<div class='example'>
As a somewhat silly example, a <code><p></code> element can be reused as a background elsewhere in the document:
<pre>
<style>
#src { color: white; background: lime; width: 300px; height: 40px; position: relative; }
#dst { color: black; background: element(#src); padding: 20px; margin: 20px 0; }
</style>
<p id='src'>I'm an ordinary element!</p>
<p id='dst'>I'm using the previous element as my background!</p>
</pre>
<img src="images/element-function.png" alt="">
</div>
<dt>an <a lt='element-not-rendered'>element that is not rendered</a>, but which provides a <a>paint source</a>
<dd>
The function represents an image with the intrinsic size and appearance of the <a>paint source</a>.
The host language defines the size and appearance of paint sources.
<div class='example'>
For example, the ''element()'' function can reference an SVG <code><pattern></code> element in an HTML document:
<pre>
<!DOCTYPE html>
<svg>
<defs>
<pattern id='pattern1'>
<path d='...'>
</pattern>
</defs>
</svg>
<p style="background: element(#pattern1)">
I'm using the pattern as a background!
If the pattern is changed or animated,
my background will be updated too!
</p>
</pre>
HTML also defines that a handful of elements,
such as <code><canvas></code>, <code><img></code>, and <code><video></code>,
provide a paint source.
This means that CSS can, for example,
reference a canvas that's being drawn into,
but not displayed in the page:
<pre>
<!DOCTYPE html>
<script>
var canvas = document.querySelector('#animated-bullet');
canvas.width = 20; canvas.height = 20;
drawAnimation(canvas);
</script>
<canvas id='animated-bullet' style='display:none'></canvas>
<ul style="list-style-image: element(#animated-bullet);">
<li>I'm using the canvas as a bullet!</li>
<li>So am I!</li>
<li>As the canvas is changed over time with Javascript,
we'll all update our bullet image with it!</li>
</ul>
</pre>
</div>
<dt>anything else
<dd>
The function represents an <a>invalid image</a>.
<div class='example'>
For example, all of the following ''element()'' uses will result in a transparent background:
<pre>
<!DOCTYPE html>
<p id='one' style="display:none; position: relative;">one</p>
<iframe src="http://example.com">
<p id='two' style="position: relative;">I'm fallback content!</p>
</iframe>
<ul>
<li style="background: element(#one);">
A display:none element isn't rendered, and a P element
doesn't provide a paint source.
</li>
<li style="background: element(#two);">
The descendants of a replaced element like an IFRAME
can't be used in element() either.
</li>
<li style="background: element(#three);">
There's no element with an id of "three", so this also
gets rendered as a transparent image.
</li>
</ul>
</pre>
</div>
</dl>
An element is <dfn export id='element-not-rendered' lt='element-not-rendered'>not rendered</dfn> if it does not have an associated box.
This can happen, for example,
if the element or an ancestor is ''display:none''.
Host languages may define additional ways in which an element can be considered not rendered;
for example, in SVG,
any descendant of a <code><defs></code> element is considered to be not rendered.
<div class='example'>
The ''element()'' function can be put to many uses.
For example, it can be used to show a preview of the previous or next slide in a slideshow:
<pre>
<!DOCTYPE html>
<script>
function navigateSlides() {
var currentSlide = ...;
document.querySelector('#prev-slide').id = '';
document.querySelector('#next-slide').id = '';
currentSlide.previousElementSibling.id = 'prev-slide';
currentSlide.nextElementSibling.id = 'next-slide';
}
</script>
<style>
.slide {
/* Need to be a stacking context to be element()-able. */
position: relative;
}
#prev-preview, #next-preview {
position: fixed;
...
}
#prev-preview { background: element(#prev-slide); }
#next-preview { background: element(#next-slide); }
</style>
<a id='prev-preview'>Previous Slide</a>
<a id='next-preview'>Next Slide</a>
<section class='slide'>...</section>
<section class='slide current-slide'>...</section>
...
</pre>
In this example, the <code>navigateSlides</code> function updates the ids of the next and previous slides,
which are then displayed in small floating boxes alongside the slides.
Since you can't interact with the slides through the ''element()'' function (it's just an image),
you could even use <code>click</code> handlers on the preview boxes to help navigate through the page.
</div>
<h4 id='paint-sources'>
Paint Sources</h4>
Host languages may define that some elements provide a <dfn export>paint source</dfn>.
Paint sources have an intrinsic appearance and can obtain a <a>concrete object size</a>
without having to do layout or rendering,
and so may be used as images even when they're <a lt='element-not-rendered'>not rendered</a>.
In HTML, the <code><img></code>, <code><video></code>, and <code><canvas></code> elements provide paint sources
(defined in each element's section in <a href='http://www.whatwg.org/specs/web-apps/current-work/multipage/'>HTML5</a>).
In SVG, any element that provides a <a href='http://www.w3.org/TR/SVG/pservers.html'>paint server</a> provides a paint source.
<span class='note'>Note: In SVG1.1,
the <code><linearGradient></code>,
<code><radialGradient></code>,
and <code><pattern></code> elements
provide paint sources.</span>
They are drawn as described in the spec,
with the coordinate systems defined as follows:
<dl>
<dt>objectBoundingBox
<dd>
The coordinate system has its origin at the top left corner of the rectangle defined by the <a>concrete object size</a> that it's being drawn into,
and the same width and height as the <a>concrete object size</a>.
A single <a href="http://www.w3.org/TR/SVG/coords.html#Units">user coordinate</a> is the width and height of the <a>concrete object size</a>.
<dt>userSpaceOnUse
<dd>
The coordinate system has its origin at the top left corner of the rectangle defined by the <a>concrete object size</a> that it's being drawn into,
and the same width and height as the <a>concrete object size</a>.
<a href="http://www.w3.org/TR/SVG/coords.html#Units">User coordinates</a> are sized equivalently to the CSS ''px'' unit.
</dl>
Note: It is expected that a future version of this module will define ways to refer to paint sources in external documents,
or ones that are created solely by script and never inserted into a document at all.
<h4 id='elementsources'>
Using Out-Of-Document Sources: the <code>ElementSources</code> interface</h4>
The ''element()'' function normally selects elements within a document,
but elements that provide a <a>paint source</a> don't necessarily need to be in-document.
For example, an HTML <code><canvas></code> element can be created, maintained, and drawn into entirely in script,
with no need for it to be inserted into the document directly.
All that's needed is a way to refer to the element,
as an ID selector cannot select elements outside of the document.
The <a idl>elementSources</a> Map object provides this.
<pre class='idl'>
partial interface CSS {
[SameObject] readonly attribute Map elementSources;
};
</pre>
Any entries in the <a idl>elementSources</a> map with a string key
and a value that is an object providing a <a>paint source</a>
are made available to the ''element()'' function.
Whenever ''element()'' uses an <<id-selector>>,
the ID's value (without the leading <code>#</code> character)
is first looked up in the <a idl>elementSources</a> map:
<ul>
<li>
If it's found,
and the object associated with it provides a <a>paint source</a>,
the ''element()'' function represents that paint source.
<li>
If it's found,
but the object associated with it <em>doesn't</em> provide a <a>paint source</a>,
the ''element()'' function represent an <a>invalid image</a>.
<li>
If the ID isn't found in the map at all,
it's then looked for in the document as normal.
</ul>
<p class='issue'>
This reuse of the ID selector matches Moz behavior.
I'm trying to avoid slapping a <<custom-ident>> right in the beginning of the grammar,
as that eats too much syntax-space.
Another possibility, though, is to start the value with a language-defined keyword
<em>followed by</em> a <<custom-ident>>,
like ''element(external fancy)'' or something.
Naming suggestions welcome.
<div class='example'>
For example, fancy animating backgrounds can be done with an external canvas:
<pre>
<script>
var bg = document.createElement('canvas');
bg.height = 200;
bg.width = 1000;
drawFancyBackground(bg);
CSS.elementSources.set('fancy', bg);
</script>
<style>
h1 {
background-image: element(#fancy);
}
</style>
</pre>
As the "fancy" canvas is drawn into and animated,
the backgrounds of all the H1 elements will automatically update in tandem.
Note that the <a idl>elementSources</a> map is consulted <em>before</em> the document
to match the ID selector,
so even if there's an element in the document that would match ''#fancy'',
the backgrounds will still predictably come from the <a idl>elementSources</a> value instead.
</div>
<h4 id='element-cycles'>
Cycle Detection</h4>
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.
The dependency graph consists of edges such that:
<ul>
<li>
every element depends on its children
<li>
for any element A with a property using the ''element()'' function pointing to an element B,
A depends on B
<li>
if a host language defines a way for elements to refer to the rendering of other elements,
the referencing element depends on the referenced element.
For example, in SVG,
a <code><use></code> element depends on the element it referenced.
</ul>
If the graph contains a cycle,
any ''element()'' functions participating in the cycle are <a>invalid images</a>.
<!--
██████ ████████ ███ ████████ ████ ████████ ██ ██ ████████ ██████
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ███ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ██
██ ████ ████████ ██ ██ ██ ██ ██ ██████ ██ ██ ██ ██ ██████
██ ██ ██ ██ █████████ ██ ██ ██ ██ ██ ████ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ███ ██ ██ ██
██████ ██ ██ ██ ██ ████████ ████ ████████ ██ ██ ██ ██████
-->
<h2 id="gradients">
Gradients</h2>
A gradient is an image that smoothly fades from one color to another.
These are commonly used for subtle shading in background images, buttons, and many other things.
The gradient notations described in this section allow an author to specify such an image in a terse syntax,
so that the UA can generate the image automatically when rendering the page.
The syntax of a <<gradient>> is:
<pre class=prod>
<dfn><gradient></dfn> = [
<<linear-gradient()>> | <<repeating-linear-gradient()>> |
<<radial-gradient()>> | <<repeating-radial-gradient()>> |
<<conic-gradient()>> | <<repeating-conic-gradient()>> ]
</pre>
<div class=example>
As with the other <<image>> types defined in this specification,
gradients can be used in any property that accepts images.
For example:
<ul>
<li><code>background: linear-gradient(white, gray);</code>
<li><code>list-style-image: radial-gradient(circle, #006, #00a 90%, #0000af 100%, white 100%)</code>
</ul>
</div>
A gradient is drawn into a box with the dimensions of the <a>concrete object size</a>,
referred to as the <dfn export>gradient box</dfn>.
However, the gradient itself has no <a>intrinsic dimensions</a>.
<div class='example'>
For example, if you use a gradient as a background,
by default the gradient will draw into a <a>gradient box</a> the size of the element's padding box.
If 'background-size' is explicitly set to a value such as ''100px 200px'',
then the <a>gradient box</a> will be 100px wide and 200px tall.
Similarly, for a gradient used as a 'list-style-image',
the box would be a 1em square,
which is the <a>default object size</a> for that property.
</div>
Gradients are specified by defining the <dfn>starting point</dfn> and <dfn>ending point</dfn>
of a <dfn export>gradient line</dfn>
(which, depending on the type of gradient,
may be technically a line, or a ray, or a spiral),
and then specifying colors at points along this line.
The colors are smoothly blended to fill in the rest of the line,
and then each type of gradient defines how to use the color of the <a>gradient line</a> to produce the actual gradient.
<!--
██████ ███████ ██ ██ ████ ██████
██ ██ ██ ██ ███ ██ ██ ██ ██
██ ██ ██ ████ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ████ ██ ██
██ ██ ██ ██ ██ ███ ██ ██ ██
██████ ███████ ██ ██ ████ ██████
-->
<h3 id='conic-gradients'>
Conic Gradients: the ''conic-gradient()'' notation</h3>
A conic gradient starts by specifying the center of a circle,
similar to radial gradients,
except that conic gradient color-stops are placed <em>around</em> the circumference of the circle,
rather than on a line emerging from the center,
causing the color to smoothly transition as you spin around the center,
rather than as you progress outward from the center.
A conic gradient is specified by indicating a rotation angle, the center of the gradient,
and then specifying a list of color-stops.
Unlike linear and radial gradients,
whose color-stops are placed by specifying a <<length>>,
the color-stops of a conic gradient are specified with an <<angle>>.
Rays are then drawn emerging from the center and pointing in all directions,
with the color of each ray equal to the color of the gradient-line where they intersect it.
Note: These gradients are called "conic" or "conical"
because, if the color stops are chosen to be significantly lighter on one side than the other,
it produces a pattern that looks like a cone observed from above.
They are also known as "angle" gradients in some contexts,
since they are produced by varying the rotation angle of a ray.
<div class=example>
<div style="overflow: hidden">
<img style="float: right; margin-left: 1em;" src='images/conic-diagram.png' alt="[An image showing a box with a background shading gradually clockwise from white to black, starting from the top. A gradient circle is shown, and the colors at 0 and 216 degrees respectively.]">
This example visually illustrates how ''conic-gradient(at 25% 30%, white, black 60%)'' would be drawn. Note that since color stop positions always resolve to angles, the only effect of the center center is a 2D translation of the gradient, i.e. it does not affect how the gradient is drawn.
</div>
</div>
<h4 id='conic-gradient-syntax' class='no-toc'>
''conic-gradient()'' Syntax</h4>
The syntax for a conic gradient is:
<pre class='prod'>
<dfn>conic-gradient()</dfn> = conic-gradient(
[ from <<angle>> ]? [ at <<position>> ]?,
<<angular-color-stop-list>>
)
</pre>
The arguments are defined as follows:
<dl dfn-type=value dfn-for="conic-gradient(), repeating-conic-gradient()">
<dt><dfn><<angle>></dfn>
<dd>
The entire gradient is rotated by this angle.
If omitted, defaults to ''0deg''.
<dt><dfn><<position>></dfn>
<dd>
Determines the <dfn dfn>gradient center</dfn> of the gradient.
The <<position>> value type (which is also used for 'background-position')
is defined in [[!CSS3VAL]],
and is resolved using the center-point as the object area
and the <a>gradient box</a> as the positioning area.
If this argument is omitted, it defaults to ''<position>/center''.
</dl>
<p class='issue'>
Anything else that might be useful? Defining the shape of the gradient as elliptical, perhaps?
<h4 id='conic-color-stops' class='no-toc'>
Placing Color Stops</h4>
Color stops are placed on a <a>gradient line</a> that curves around the center in a circle,
with both the 0% and 100% locations at 0deg.
Just like linear gradients,
0deg points to the top of the page,
and increasing angles correspond to clockwise movement around the circle.
Note: It may be more helpful to think of the gradient line as forming a spiral,
where only the segment from 0deg to 360deg is rendered.
This avoids any confusion about "overlap" when you have angles outside of the rendered region.
A color-stop can be placed at a location before 0% or after 100%;
though these regions are never directly consulted for rendering,
color stops placed there can affect the color of color-stops within the rendered region
through interpolation or repetition (see <a href="#repeating-gradients">repeating gradients</a>).
For example, ''conic-gradient(red -50%, yellow 150%)'' produces a conic gradient
that starts with a reddish-orange color at 0deg (specifically, #f50),
and transitions to an orangish-yellow color at 360deg (specifically, #fa0).
The color of the gradient at any point is determined by first finding the unique ray
anchored at the center of the gradient that passes through the given point.
The point's color is then the color of the <a>gradient line</a> at the location where this ray intersects it.
<h4 id='conic-gradient-examples' class='no-toc'>
Conic Gradient Examples</h4>
All of the following ''conic-gradient()'' examples are presumed to be applied to a box that is 300px wide and 200px tall, unless otherwise specified.
<div class=example>
Below are various ways of specifying the same basic conic gradient:
<pre>
background: conic-gradient(#f06, gold);
background: conic-gradient(at 50% 50%, #f06, gold);
background: conic-gradient(from 0deg, #f06, gold);
background: conic-gradient(from 0deg at center, #f06, gold);
background: conic-gradient(#f06 0%, gold 100%);
background: conic-gradient(#f06 0deg, gold 1turn);
</pre>
<img src="images/conic1.png" alt="" >
</div>
<div class=example>
Below are various ways of specifying the same basic conic gradient.
This demonstrates how even though color stops with angles outside [0deg, 360deg) are not directly painted,
they can still affect the color of the painted part of the gradient.
<pre>
background: conic-gradient(white -50%, black 150%);
background: conic-gradient(white -180deg, black 540deg);
background: conic-gradient(hsl(0,0%,75%), hsl(0,0%,25%));
</pre>
<img src="images/conic2.png" alt="" >
</div>
<div class=example>
Below are two different ways of specifying the same rotated conic gradient, one with a rotation angle and one without:
<pre>
background: conic-gradient(from 45deg, white, black, white);
background: conic-gradient(hsl(0,0%,87.5%), white 45deg, black 225deg, hsl(0,0%,87.5%));
</pre>
<img src="images/conic3.png" alt="" >
Note that offsetting every color stop by the rotation angle instead would not work and produces an entirely different gradient:
<pre>
background: conic-gradient(white 45deg, black 225deg, white 405deg);
</pre>
<img src="images/conic4.png" alt="" >
</div>
<div class=example>
A conic gradient with a radial gradient overlaid on it, to draw a hue & saturation wheel:
<pre>
background: radial-gradient(gray, transparent),
conic-gradient(red, yellow, lime, aqua, blue, magenta, red);
border-radius: 50%;
width: 200px; height: 200px;
</pre>
<img src="images/conic5.png" alt="" >
</div>
<div class=example>
A conic gradient used to draw a simple pie chart.
The ''0deg'' color stop positions will be fixed up to be equal to the position of the color stop before them.
This will produce infinitesimal (invisible) transitions between the color stops with different colors,
effectively producing solid color segments.
<pre>
background: conic-gradient(yellowgreen 40%, gold 0deg 75%, #f06 0deg);
border-radius: 50%;
width: 200px; height: 200px;
</pre>
<img src="images/conic6.png" alt="" >
</div>
<!--
████████ ████████ ████████ ████████ ███ ████████ ████ ██ ██ ██████
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ███ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██
████████ ██████ ████████ ██████ ██ ██ ██ ██ ██ ██ ██ ██ ████
██ ██ ██ ██ ██ █████████ ██ ██ ██ ████ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ███ ██ ██
██ ██ ████████ ██ ████████ ██ ██ ██ ████ ██ ██ ██████
-->
<h3 id='repeating-gradients'>
Repeating Gradients: the ''repeating-linear-gradient()'', ''repeating-radial-gradient()'', and ''repeating-conic-gradient()'' notations</h3>
In addition to ''linear-gradient()'', ''radial-gradient()'', and ''conic-gradient()'',
this specification defines <dfn>repeating-linear-gradient()</dfn>,
<dfn>repeating-radial-gradient()</dfn>,
and <dfn>repeating-conic-gradient()</dfn> values.
These notations take the same values
and are interpreted the same
as their respective non-repeating siblings defined previously.
<div class=example>
Basic repeating conic gradient:
<pre>background: repeating-conic-gradient(gold, #f06 20deg);</pre>
<img src="images/repeating-conic1.png" alt="">
</div>
<div class=example>
Repeating color stops with abrupt transitions creates a starburst-type background:
<pre>
background: repeating-conic-gradient(
hsla(0,0%,100%,.2) 0deg 15deg,
hsla(0,0%,100%,0) 0deg 30deg
) #0ac;</pre>
<img src="images/repeating-conic2.png" alt="">
</div>
<div class=example>
Here repeating color stops with abrupt transitions are used to create a checkerboard:
<pre>
background: repeating-conic-gradient(black 0deg 25%, white 0deg 50%);
background-size: 60px 60px;
</pre>
<img src="images/repeating-conic3.png" alt="">
The same checkerboard can be created via non-repeating conic gradients:
<pre>
background: conic-gradient(black 25%, white 0deg 50%, black 0deg 75%, white 0deg);
background-size: 60px 60px;
</pre>
</div>
<!--
██████ ████████ ███████ ████████ ██████
██ ██ ██ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██
██████ ██ ██ ██ ████████ ██████
██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ██
██████ ██ ███████ ██ ██████
-->
<h3 id='color-stop-syntax'>
Gradient Color-Stops</h3>
<pre class=prod>
<dfn><color-stop-list></dfn> =
[ <<linear-color-stop>> , <<linear-color-hint>>? ]# , <<linear-color-stop>>
<dfn><linear-color-stop></dfn> = <<color>> && <<color-stop-length>>
<dfn><linear-color-hint></dfn> = <<length>> | <<percentage>>
<dfn><color-stop-length></dfn> = [ <<length>> | <<percentage>> ]{1,2}
<dfn><angular-color-stop-list></dfn> =
[ <<angular-color-stop>> , <<angular-color-hint>>? ]# , <<angular-color-stop>>
<dfn><angular-color-stop></dfn> = <<color>> && <<color-stop-angle>>?
<dfn><angular-color-hint></dfn> = <<angle>> | <<percentage>>
<dfn><color-stop-angle></dfn> = [ <<angle>> | <<percentage>> ]{1,2}
<dfn><color-stop></dfn> = <<color-stop-length>> | <<color-stop-angle>>
</pre>
<pre class='railroad'>
Plus:
Sequence:
N: <color-stop>
T: ,
Choice: 1
N: <color-hint>
Skip:
T: ,
N: <color-stop>
</pre>
<p class='issue'>
Are lengths useful in <<angular-color-stop>>, for a given gradient circle?
<p class='issue'>
This is past the complexity point where it can be easily understood with just prose.
Add a diagram illustrating the possibilities,
preferably for all three kinds of gradients
(to show off the three shapes of gradient lines).
The colors in gradients are specified using <a>color stops</a>.
A <dfn export>color stop</dfn> is a combination of a color and one or two positions.
(Depending on the type of gradient, that position can be a length, angle, or percentage.)
While every color stop conceptually has at least one position,
the position can be omitted in the syntax.
(It gets automatically filled in by the user agent; see below for details.)
Between two <a>color stops</a> there can be a <dfn local-lt="color hint">color interpolation hint</dfn>,
which specifies how the colors of the two <a>color stops</a> on either side
should be interpolated in the space between them
(by default, they interpolate linearly).
There can only be at most one <a>color interpolation hint</a> between any two given <a>color stops</a>;
using more than that makes the function invalid.
Color stops are organized into a <dfn export>color stop list</dfn>,
which is a list of one or more <a>color stops</a>.
The first and last <a>color stops</a> in the list
must have a color
(though their position can be omitted).
<a>Color stops</a> and <a>color hints</a> are placed on a <a>gradient line</a>,
which defines the colors at every point of a gradient.
The gradient function defines the shape and length of the <a>gradient line</a>,
along with its <a>starting point</a> and <a>ending point</a>.
<a>Color stops</a> and <a>color hints</a> must be specified in order.
Percentages refer to the length of the <a>gradient line</a> between the <a>starting point</a> and <a>ending point</a>,
with 0% being at the starting point
and 100% being at the ending point.
Lengths are measured from the <a>starting point</a> in the direction of the <a>ending point</a> along the <a>gradient line</a>.
Angles are measured with 0deg pointing up,
and positive angles corresponding to clockwise rotations from there.
<a>Color stops</a> and <a>color hints</a> are usually placed between the <a>starting point</a> and <a>ending point</a>,
but that's not required;
the gradient line extends infinitely in both directions,
and a <a>color stop</a> or <a>color hint</a> can be placed at any position on the <a>gradient line</a>.
A <a>color stop</a> with two locations is mostly equivalent
to specifying two <a>color stops</a> with the same color,
one for each position.
<span class='note'>Specifying two locations makes it easier to create solid-color "stripes" in a gradient,
without having to repeat the color twice.</span>
The position of a <a>color stop</a> can be omitted.
This causes the <a>color stop</a> to position itself automatically
between the two surrounding stops.
If multiple stops in a row lack a position,
they space themselves out equally.
The following steps must be applied <em>in order</em> to process the <<color-stop-list>>.
After applying these rules,
all <a>color stops</a> and <a>color hints</a> will have a definite position and color (if appropriate)
and they will be in ascending order:
<ol>
<li>
If the first <a>color stop</a> does not have a position,
set its position to 0%.
If the last <a>color stop</a> does not have a position,
set its position to 100%.
<li>
If a <a>color stop</a> or <a>color hint</a> has a position that is less than the specified position of any <a>color stop</a> or <a>color hint</a> before it in the list,
set its position to be equal to the largest specified position of any <a>color stop</a> or <a>color hint</a> before it.
<li>
If any <a>color stop</a> still does not have a position,
then, for each run of adjacent <a>color stops</a> without positions,
set their positions so that they are evenly spaced between the preceding and following <a>color stops</a> with positions.
</ol>
<p class='issue'>
This requires us to wait until <em>after</em> layout to do fix-up,
because implied-position stops (set by step 3)
may depend on stops that need layout information to place,
and which may be corrected by step 2.
Swapping steps 2 and 3 would let us interpolate <a>color stops</a> purely at computed-value time,
which is a nice plus,
at the cost of changing behavior from level 3 for some edge cases that triggered fixup.
Make sure this is handled well in the serialization rules.
At each <a>color stop</a> position,
the line is the color of the <a>color stop</a>.
Between two <a>color stops</a>,
the line's color is interpolated between the colors of the two <a>color stops</a>,
with the interpolation taking place in premultiplied RGBA space.
By default,
this interpolation is linear--
at 25%, 50%, or 75% of the distance between two <a>color stops</a>,
the color is a 25%, 50%, or 75% blend of the colors of the two stops.
However, if a <a>color hint</a> was provided between two <a>color stops</a>,
the interpolation is non-linear,
and controlled by the hint:
<ol>
<li>
Determine the location of the <a>color hint</a> as a percentage of the distance between the two <a>color stops</a>,
denoted as a number between 0 and 1,
where 0 indicates the hint is placed right on the first <a>color stop</a>,
and 1 indicates the hint is placed right on the second <a>color stop</a>.
Let this percentage be <var>H</var>.
<li>
For any given point between the two color stops,
determine the point's location as a percentage of the distance between the two <a>color stops</a>,
in the same way as the previous step.
Let this percentage be <var>P</var>.
<li>
Let <var>C</var>, the color weighting at that point,
be equal to <code>P<sup>log<sub>H</sub>(.5)</sup></code>.
<li>
The color at that point is then a linear blend between the colors of the two <a>color stops</a>,
blending <code>(1 - C)</code> of the first stop and <var>C</var> of the second stop.
</ol>
Note: If the hint is placed halfway between the two stops,
this is thus the ordinary linear interpolation.
If the hint is placed anywhere else,
it dictates the position of the "halfway point",
where the color is an equal blend between the two <a>color stops</a>,
and produces smooth, even blends between the <a>color stops</a> and the "halfway point".
Before the first <a>color stop</a>,
the line is the color of the first <a>color stop</a>.
After the last <a>color stop</a>, the line is the color of the last <a>color stop</a>.
If multiple <a>color stops</a> 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.
<div class=example>
Below are several pairs of gradients.
The latter of each pair is a manually "fixed-up" version of the former,
obtained by applying the above rules.
For each pair, both gradients will render identically.
<span class='note'>The numbers in each arrow specify which fixup steps are invoked in the transformation.</span>
<pre>