8000 csswg-drafts/css-images/Overview.html at 59e5a4325335f5ae338745e3cd30b9623760bdf7 · w3c/csswg-drafts · GitHub
Skip to content

Latest commit

 

History

History
1212 lines (978 loc) · 83.3 KB

File metadata and controls

<!DOCTYPE html><html lang=en><head>
<meta content="text/html; charset=utf-8" http-equiv=Content-Type>
<title>CSS Image Values and Replaced Content Module Level 4</title>
<link href=../default.css rel=stylesheet type=text/css>
<link href=../csslogo.ico rel="shortcut icon" type=image/x-icon>
<style>
body {
background: url("https://www.w3.org/StyleSheets/TR/logo-ED") top left no-repeat white;
background-attachment: fixed;
color: black;
font-family: sans-serif;
margin: 0 auto;
max-width: 50em;
padding: 2em 1em 2em 70px;
}
:link { color: #00C; background: transparent }
:visited { color: #609; background: transparent }
a[href]:active { color: #C00; background: transparent }
a[href]:hover { background: #ffa }
a[href] img { border-style: none }
h1, h2, h3, h4, h5, h6 { text-align: left }
h1, h2, h3 { color: #005A9C; }
h1 { font: 170% sans-serif }
h2 { font: 140% sans-serif }
h3 { font: 120% sans-serif }
h4 { font: bold 100% sans-serif }
h5 { font: italic 100% sans-serif }
h6 { font: small-caps 100% sans-serif }
.hide { display: none }
div.head { margin-bottom: 1em }
div.head h1 { margin-top: 2em; clear: both }
div.head table { margin-left: 2em; margin-top: 2em }
p.copyright { font-size: small }
p.copyright small { font-size: small }
pre { margin-left: 2em }
dt { font-weight: bold }
ul.toc, ol.toc {
list-style: none;
}
</style>
<style>svg.railroad-diagram{background-color:hsl(30,20%,95%);}svg.railroad-diagram path{stroke-width:3;stroke:black;fill:rgba(0,0,0,0);}svg.railroad-diagram text{font:bold 14px monospace;text-anchor:middle;}svg.railroad-diagram text.label{text-anchor:start;}svg.railroad-diagram text.comment{font:italic 12px monospace;}svg.railroad-diagram rect{stroke-width:3;stroke:black;fill:hsl(120,100%,90%);}</style></head>
<body class=h-entry>
<div class=head>
<p data-fill-with=logo><a class=logo href=http://www.w3.org/>
<img alt=W3C height=48 src=https://www.w3.org/Icons/w3c_home width=72>
</a>
</p>
<h1 class="p-name no-ref" id=title>CSS Image Values and Replaced Content Module Level 4</h1>
<h2 class="no-num no-toc no-ref heading settled" id=subtitle><span class=content>Editor’s Draft,
<span class=dt-updated><span class=value-title title=20141003>3 October 2014</span></span></span></h2>
<div data-fill-with=spec-metadata><dl><dt>This version:<dd><a class=u-url href=http://dev.w3.org/csswg/css-images-4/>http://dev.w3.org/csswg/css-images-4/</a><dt>Latest version:<dd><a href=http://www.w3.org/TR/css4-images/>http://www.w3.org/TR/css4-images/</a><dt>Previous Versions:<dd><a href=http://www.w3.org/TR/2012/WD-css4-images-20120911/ rel=previous>http://www.w3.org/TR/2012/WD-css4-images-20120911/</a><dt>Feedback:<dd><span><a href="mailto:www-style@w3.org?subject=[css-images] feedback">www-style@w3.org</a> with subject line “<kbd>[css-images] <var>… message topic …</var></kbd>” (<a href=http://lists.w3.org/Archives/Public/www-style/ rel=discussion>archives</a>)</span><dt>Editors:<dd><div class="p-author h-card vcard"><a class="p-name fn u-url url" href=http://xanthir.com/contact/>Tab Atkins Jr.</a> (<span class="p-org org">Google</span>)</div><dd><div class="p-author h-card vcard"><a class="p-name fn u-url url" href=http://fantasai.inkedblade.net/contact>fantasai</a> (<span class="p-org org">Mozilla</span>)</div><dt>Issue Tracking:<dd><span><a href=http://www.w3.org/Style/CSS/Tracker/products/27>http://www.w3.org/Style/CSS/Tracker/products/27</a></span></dl></div>
<div data-fill-with=warning></div>
<p class=copyright data-fill-with=copyright><a href=http://www.w3.org/Consortium/Legal/ipr-notice#Copyright>Copyright</a> © 2014 <a href=http://www.w3.org/><abbr title="World Wide Web Consortium">W3C</abbr></a><sup>®</sup> (<a href=http://www.csail.mit.edu/><abbr title="Massachusetts Institute of Technology">MIT</abbr></a>, <a href=http://www.ercim.eu/><abbr title="European Research Consortium for Informatics and Mathematics">ERCIM</abbr></a>, <a href=http://www.keio.ac.jp/>Keio</a>, <a href=http://ev.buaa.edu.cn/>Beihang</a>), All Rights Reserved. W3C <a href=http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer>liability</a>, <a href=http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks>trademark</a> and <a href=http://www.w3.org/Consortium/Legal/copyright-documents>document use</a> rules apply.
</p>
<hr title="Separator for header">
</div>
<h2 class="no-num no-toc no-ref heading settled" id=abstract><span class=content>Abstract</span></h2>
<div class=p-summary data-fill-with=abstract><p>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.</p>
<a href=http://www.w3.org/TR/CSS/>CSS</a> is a language for describing the rendering of structured documents
(such as HTML and XML)
on screen, on paper, in speech, etc.</div>
<h2 class="no-num no-toc no-ref heading settled" id=status><span class=content>Status of this document</span></h2>
<div data-fill-with=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=%5Bcss-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 “css-images” in the subject,
preferably like this:
“[css-images] <em>…summary of comment…</em>”
<p>
This document was produced by the <a href=http://www.w3.org/Style/CSS/members>CSS Working Group</a>
(part of the <a href=http://www.w3.org/Style/>Style Activity</a>).
<p>
This document was produced by a group operating under
the <a href=http://www.w3.org/Consortium/Patent-Policy-20040205/>5 February 2004 W3C Patent Policy</a>.
W3C maintains a <a href=http://www.w3.org/2004/01/pp-impl/32061/status rel=disclosure>public list of any patent disclosures</a>
made in connection with the deliverables of the group;
that page also includes instructions for disclosing a patent.
An individual who has actual knowledge of a patent which the individual believes contains <a href=http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential>Essential Claim(s)</a>
must disclose the information in accordance with <a href=http://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure>section 6 of the W3C Patent Policy</a>.</div>
<div data-fill-with=at-risk></div>
<h2 class="no-num no-toc no-ref heading settled" id=contents><span class=content>Table of Contents</span></h2>
<div data-fill-with=table-of-contents><ul class=toc><li><a href=#image-values><span class=secno>1</span> <span class=content>Images Values: the <span class=production data-link-type=type title="<image>">&lt;image&gt;</span> type</span></a><ul class=toc><li><a href=#image-notation><span class=secno>1.1</span> <span class=content>Image Fallbacks and Annotations: the <span class=css data-link-type=maybe title=image()>image()</span> notation</span></a><ul class=toc><li><a href=#bidi-images><span class=secno>1.1.1</span> <span class=content>Bidi-sensitive Images</span></a></ul><li><a href=#element-notation><span class=secno>1.2</span> <span class=content>
Using Elements as Images: the <span class=css data-link-type=maybe title=element()>element()</span> notation</span></a><ul class=toc><li><a href=#paint-sources><span class=secno>1.2.1</span> <span class=content>
Paint Sources</span></a><li><a href=#elementsources><span class=secno>1.2.2</span> <span class=content>
Using Out-Of-Document Sources: the <code>ElementSources</code> interface</span></a><li><a href=#element-cycles><span class=secno>1.2.3</span> <span class=content>
Cycle Detection</span></a></ul></ul><li><a href=#gradients><span class=secno>2</span> <span class=content>
Gradients</span></a><ul class=toc><li><a href=#conic-gradients><span class=secno>2.1</span> <span class=content>
Conic Gradients: the <span class=css data-link-type=maybe title=conic-gradient()>conic-gradient()</span> notation</span></a><li><a href=#repeating-gradients><span class=secno>2.2</span> <span class=content>
Repeating Gradients: the <span class=css data-link-type=maybe title=repeating-linear-gradient()>repeating-linear-gradient()</span>, <span class=css data-link-type=maybe title=repeating-radial-gradient()>repeating-radial-gradient()</span>, and <span class=css data-link-type=maybe title=repeating-conic-gradient()>repeating-conic-gradient()</span> notations</span></a><li><a href=#color-stop-syntax><span class=secno>2.3</span> <span class=content>
Gradient Color-Stops</span></a></ul><li><a href=#conformance><span class=secno></span> <span class=content>
Conformance</span></a><ul class=toc><li><a href=#conventions><span class=secno></span> <span class=content>
Document conventions</span></a><li><a href=#conformance-classes><span class=secno></span> <span class=content>
Conformance classes</span></a><li><a href=#partial><span class=secno></span> <span class=content>
Partial implementations</span></a><li><a href=#experimental><span class=secno></span> <span class=content>
Experimental implementations</span></a><li><a href=#testing><span class=secno></span> <span class=content>
Non-experimental implementations</span></a></ul><li><a href=#references><span class=secno></span> <span class=content>References</span></a><ul class=toc><li><a href=#normative><span class=secno></span> <span class=content>Normative References</span></a></ul><li><a href=#index><span class=secno></span> <span class=content>Index</span></a><li><a href=#issues-index><span class=secno></span> <span class=content>Issues Index</span></a></ul></div>
<h2 class="heading settled" data-level=1 id=image-values><span class=secno>1. </span><span class=content>Images Values: the <a class="production css" data-link-type=type title="<image>">&lt;image&gt;</a> type</span><a class=self-link href=#image-values></a></h2>
<h3 class="heading settled" data-level=1.1 id=image-notation><span class=secno>1.1. </span><span class=content>Image Fallbacks and Annotations: the <a class=css data-link-type=maybe href=#funcdef-image title=image()>image()</a> notation</span><a class=self-link href=#image-notation></a></h3>
<p>The <a class=css data-link-type=maybe href=#funcdef-image title=image()>image()</a> notation is defined as:</p>
<pre class=prod><dfn data-dfn-type=function data-export="" id=funcdef-image>image()<a class=self-link href=#funcdef-image></a></dfn> = image( <a class=production data-link-type=type href=#typedef-image-tags title="<image-tags>">&lt;image-tags&gt;</a><a class=prod-punc data-link-type=grammar href=http://dev.w3.org/csswg/css-values-3/#mult-opt title=?>?</a> [ <a class=production data-link-type=type href=#typedef-image-src title="<image-src>">&lt;image-src&gt;</a><a class=prod-punc data-link-type=grammar href=http://dev.w3.org/csswg/css-values-3/#mult-opt title=?>?</a> <a class=prod-punc data-link-type=grammar href=http://dev.w3.org/csswg/css-values-3/#comb-comma title=,>,</a> <a class=production data-link-type=type href=http://dev.w3.org/csswg/css-color-3/#valuea-def-color title="<color>">&lt;color&gt;</a><a class=prod-punc data-link-type=grammar href=http://dev.w3.org/csswg/css-values-3/#mult-opt title=?>?</a> ]<a class=prod-punc data-link-type=grammar href=http://dev.w3.org/csswg/css-values-3/#mult-req title=!>!</a> )
<dfn data-dfn-type=type data-export="" id=typedef-image-tags>&lt;image-tags&gt;<a class=self-link href=#typedef-image-tags></a></dfn> = [ ltr <a class=prod-punc data-link-type=grammar href=http://dev.w3.org/csswg/css-values-3/#comb-one title=|>|</a> rtl ]
<dfn data-dfn-type=type data-export="" id=typedef-image-src>&lt;image-src&gt;<a class=self-link href=#typedef-image-src></a></dfn> = [ <a class=production data-link-type=type href=http://dev.w3.org/csswg/css-values-3/#url-value title="<url>">&lt;url&gt;</a> <a class=prod-punc data-link-type=grammar href=http://dev.w3.org/csswg/css-values-3/#comb-one title=|>|</a> <a class=production data-link-type=type href=http://dev.w3.org/csswg/css-values-3/#string-value title="<string>">&lt;string&gt;</a> ]
</pre>
<h4 class="heading settled" data-level=1.1.1 id=bidi-images><span class=secno>1.1.1. </span><span class=content>Bidi-sensitive Images</span><a class=self-link href=#bidi-images></a></h4>
<p>Before listing any <code>&lt;image-src&gt;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).</p>
<p class=note>Note: Absent this declaration,
images default to no directionality at all,
and thus don’t care about the directionality of the surrounding element.</p>
<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>&lt;ul style="list-style-image: image(ltr 'arrow.png');"&gt;
&lt;li dir='ltr'&gt;My bullet is on the left!&lt;/li&gt;
&lt;li dir='rtl'&gt;MY BULLET IS ON THE RIGHT!&lt;/li&gt;
&lt;/ul&gt;
</pre>
<p>This should render something like:</p>
<pre>⇒ My bullet is on the left!
!THGIR EHT NO SI TELLUB YM ⇐
</pre>
<p>In LTR list items, the image will be used as-is.
In the RTL list items, however,
it will be flipped in the inline direction,
so it still points into the content.</p>
< 8096 /div>
</div>
<h3 class="heading settled" data-level=1.2 id=element-notation><span class=secno>1.2. </span><span class=content>
Using Elements as Images: the <a class=css data-link-type=maybe href=#funcdef-element title=element()>element()</a> notation</span><a class=self-link href=#element-notation></a></h3>
<p>The <a class=css data-link-type=maybe href=#funcdef-element title=element()>element()</a> function allows an author to use an element in the document as an image.
As the referenced element changes appearance,
the image changes as well.
This can be used, for example,
to create live previews of the next/previous slide in a slideshow,
or to reference a canvas element for a fancy generated gradient or even an animated background.</p>
<p class=note>Note: The <a class=css data-link-type=maybe href=#funcdef-element title=element()>element()</a> 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 <a class=css data-link-type=maybe href=#funcdef-element title=element()>element()</a> to reproduce an element with significant content across the page.
Instead, just insert multiple copies of the element into the document.</p>
<p>The syntax for <a class=css data-link-type=maybe href=#funcdef-element title=element()>element()</a> is:</p>
<pre class=prod><dfn data-dfn-type=function data-export="" id=funcdef-element>element()<a class=self-link href=#funcdef-element></a></dfn> = element( <a class=production data-link-type=type href=http://dev.w3.org/csswg/selectors-4/#typedef-id-selector title="<id-selector>">&lt;id-selector&gt;</a> )</pre>
<p>where <a class="production css" data-link-type=type href=http://dev.w3.org/csswg/selectors-4/#typedef-id-selector title="<id-selector>">&lt;id-selector&gt;</a> is an ID selector <a data-biblio-type=normative data-link-type=biblio href=#biblio-select title=SELECT>[SELECT]</a>.</p>
<p class=issue id=issue-90473f0b><a class=self-link href=#issue-90473f0b></a>
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 id=issue-1449f72e><a class=self-link href=#issue-1449f72e></a>
This name conflicts with a somewhat similar function in GCPM.
This needs to be resolved somehow.
<p class=issue id=issue-99f17c20><a class=self-link href=#issue-99f17c20></a>
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 id=issue-69699ad7><a class=self-link href=#issue-69699ad7></a>
When we have overflow:paged,
how can we address a single page in the view?
<p>The <a class=css data-link-type=maybe href=#funcdef-element title=element()>element()</a> function references the element matched by its argument.
The ID is first looked up in the <a data-link-type=idl href=#dom-css-elementsources title=elementSources>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.</p>
<p>The image represented by the <a class=css data-link-type=maybe href=#funcdef-element title=element()>element()</a> function can vary based on whether the element is visible in the document:</p>
<dl>
<dt>
an <a data-link-type=dfn href=#element-not-rendered title=element-not-rendered>element that is rendered</a>,
is not a descendant of a replaced element,
and generates a <a data-link-spec=css21 data-link-type=dfn href=http://dev.w3.org/csswg/css2/visuren.html#x44 title="stacking context">stacking context</a>
<dd>
The function represents an image with its intrinsic size equal to the <dfn data-dfn-type=dfn data-export="" id=decorated-bounding-box>decorated bounding box<a class=self-link href=#decorated-bounding-box></a></dfn> of the referenced element:
<ul>
<li>
for an element rendered using a CSS rendering model,
the <a data-link-type=dfn href=#decorated-bounding-box title="decorated bounding box">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>
<p class=note>Note: Because images clip anything outside their bounds by default,
this means that decorations that extend outside the <a data-link-type=dfn href=#decorated-bounding-box title="decorated bounding box">decorated bounding box</a>,
like box shadows,
may be clipped.</p>
<p>The image is constructed by rendering the referenced element and its descendants
(at the same size that they would be in the document)
over an infinite <span class=css>transparent</span> canvas,
positioned so that the edges of the <a data-link-type=dfn href=#decorated-bounding-box title="decorated bounding box">decorated bounding box</a> are flush with the edges of the image.</p>
<p class=issue id=issue-88986af5><a class=self-link href=#issue-88986af5></a>
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()?
<p>If the referenced element has a transform applied to it or an ancestor,
the transform must be ignored when rendering the element as an image. <a data-biblio-type=normative data-link-type=biblio href=#biblio-css3-transforms title=CSS3-TRANSFORMS>[CSS3-TRANSFORMS]</a></p>
<p>If the referenced element is broken across pages,
the element is displayed as if the page content areas were joined flush in the pagination direction,
with pages' edges corresponding to the initial containing block’s start edge aligned.
<span class=note>Elements broken across lines or columns are just rendered with their <a data-link-type=dfn href=#decorated-bounding-box title="decorated bounding box">decorated bounding box</a>.</span></p>
<p>Implementations may either re-use existing bitmap data generated for the referenced element
or regenerate the display of the element to maximize quality at the image’s size
(for example, if the implementation detects that the referenced element is an SVG fragment);
in the latter case, the layout of the referenced element in the image must not be changed by the regeneration process.
That is, the image must look identical to the referenced element,
modulo rasterization quality.</p>
<div class=example>
<p>As a somewhat silly example, a <code>&lt;p&gt;</code> element can be reused as a background elsewhere in the document:</p>
<pre>&lt;style&gt;
#src { color: white; background: lime; width: 300px; height: 40px; }
#dst { color: black; background: element(#src); padding: 20px; margin: 20px 0; }
&lt;/style&gt;
&lt;p id='src'&gt;I’m an ordinary element!&lt;/p&gt;
&lt;p id='dst'&gt;I’m using the previous element as my background!&lt;/p&gt;
</pre>
<p><img alt="" src=images/element-function.png></p>
</div>
<dt>an <a data-link-type=dfn href=#element-not-rendered title=element-not-rendered>element that is not rendered</a>, but which provides a <a data-link-type=dfn href=#paint-source title="paint source">paint source</a>
<dd>
The function represents an image with the intrinsic size and appearance of the <a data-link-type=dfn href=#paint-source title="paint source">paint source</a>.
The host language defines the size and appearance of paint sources.
<div class=example>
For example, the <a class=css data-link-type=maybe href=#funcdef-element title=element()>element()</a> function can reference an SVG <code>&lt;pattern&gt;</code> element in an HTML document:
<pre>&lt;!DOCTYPE html&gt;
&lt;svg&gt;
&lt;defs&gt;
&lt;pattern id='pattern1'&gt;
&lt;path d='...'&gt;
&lt;/pattern&gt;
&lt;/defs&gt;
&lt;/svg&gt;
&lt;p style="background: element(#pattern1)"&gt;
I’m using the pattern as a background!
If the pattern is changed or animated,
my background will be updated too!
&lt;/p&gt;
</pre>
<p>HTML also defines that a handful of elements,
such as <code>&lt;canvas&gt;</code>, <code>&lt;img&gt;</code>, and <code>&lt;video&gt;</code>,
provide a paint source.
This means that CSS can, for example,
reference a canvas that’s being drawn into,
but not displayed in the page:</p>
<pre>&lt;!DOCTYPE html&gt;
&lt;script&gt;
var canvas = document.querySelector('#animated-bullet');
canvas.width = 20; canvas.height = 20;
drawAnimation(canvas);
&lt;/script&gt;
&lt;canvas id='animated-bullet' style='display:none'&gt;&lt;/canvas&gt;
&lt;ul style="list-style-image: element(#animated-bullet);"&gt;
&lt;li&gt;I’m using the canvas as a bullet!&lt;/li&gt;
&lt;li&gt;So am I!&lt;/li&gt;
&lt;li&gt;As the canvas is changed over time with Javascript,
we’ll all update our bullet image with it!&lt;/li&gt;
&lt;/ul&gt;
</pre>
</div>
<dt>anything else
<dd>
<p>The function represents an <a data-link-type=dfn title="invalid image">invalid image</a>.</p>
<div class=example>
<p>For example, all of the following <a class=css data-link-type=maybe href=#funcdef-element title=element()>element()</a> uses will result in a transparent background:</p>
<pre>&lt;!DOCTYPE html&gt;
&lt;p id='one' style="display:none;"&gt;one&lt;/p&gt;
&lt;iframe src="http://example.com"&gt;
&lt;p id='two'&gt;I’m fallback content!&lt;/p&gt;
&lt;/iframe&gt;
&lt;ul&gt;
&lt;li style="background: element(#one);"&gt;
A display:none element isn’t rendered, and a P element
doesn’t provide a paint source.
&lt;/li&gt;
&lt;li style="background: element(#two);"&gt;
The descendants of a replaced element like an IFRAME
can’t be used in element() either.
&lt;/li&gt;
&lt;li style="background: element(#three);"&gt;
There’s no element with an id of "three", so this also
gets rendered as a transparent image.
&lt;/li&gt;
&lt;/ul&gt;
</pre>
</div>
</dl>
<p>An element is <dfn data-dfn-type=dfn data-export="" id=element-not-rendered title=element-not-rendered>not rendered<a class=self-link href=#element-not-rendered></a></dfn> if it does not have an associated box.
This can happen, for example,
if the element or an ancestor is <span class=css>display:none</span>.
Host languages may define additional ways in which an element can be considered not rendered;
for example, in SVG,
any descendant of a <code>&lt;defs&gt;</code> element is considered to be not rendered.</p>
<div class=example>
<p>The <a class=css data-link-type=maybe href=#funcdef-element title=element()>element()</a> function can be put to many uses.
For example, it can be used to show a preview of the previous or next slide in a slideshow:</p>
<pre>&lt;!DOCTYPE html&gt;
&lt;script&gt;
function navigateSlides() {
var currentSlide = ...;
document.querySelector('#prev-slide').id = '';
document.querySelector('#next-slide').id = '';
currentSlide.previousElementSibling.id = 'prev-slide';
currentSlide.nextElementSibling.id = 'next-slide';
}
&lt;/script&gt;
&lt;style&gt;
#prev-preview, #next-preview {
position: fixed;
...
}
#prev-preview { background: element(#prev-slide); }
#next-preview { background: element(#next-slide); }
&lt;/style&gt;
&lt;a id='prev-preview'&gt;Previous Slide&lt;/a&gt;
&lt;a id='next-preview'&gt;Next Slide&lt;/a&gt;
&lt;section class='slide'&gt;...&lt;/section&gt;
&lt;section class='slide current-slide'&gt;...&lt;/section&gt;
...
</pre>
<p>In this example, the <code>navigateSlides</code> function updates the ids of the next and previous slides,
which are then displayed in small floating boxes alongside the slides.
Since you can’t interact with the slides through the <a class=c 8229 ss data-link-type=maybe href=#funcdef-element title=element()>element()</a> function (it’s just an image),
you could even use <code>click</code> handlers on the preview boxes to help navigate through the page.</p>
</div>
<h4 class="heading settled" data-level=1.2.1 id=paint-sources><span class=secno>1.2.1. </span><span class=content>
Paint Sources</span><a class=self-link href=#paint-sources></a></h4>
<p>Host languages may define that some elements provide a <dfn data-dfn-type=dfn data-export="" id=paint-source>paint source<a class=self-link href=#paint-source></a></dfn>.
Paint sources have an intrinsic appearance and can obtain a <a data-link-type=dfn title="concrete object size">concrete object size</a>
without having to do layout or rendering,
and so may be used as images even when they’re <a data-link-type=dfn href=#element-not-rendered title=element-not-rendered>not rendered</a>.</p>
<p>In HTML, the <code>&lt;img&gt;</code>, <code>&lt;video&gt;</code>, and <code>&lt;canvas&gt;</code> elements provide paint sources
(defined in each element’s section in <a href=http://www.whatwg.org/specs/web-apps/current-work/multipage/>HTML5</a>).</p>
<p>In SVG, any element that provides a <a href=http://www.w3.org/TR/SVG/pservers.html>paint server</a> provides a paint source.
<span class=note>Note: In SVG1.1,
the <code>&lt;linearGradient&gt;</code>,
<code>&lt;radialGradient&gt;</code>,
and <code>&lt;pattern&gt;</code> elements
provide paint sources.</span>
They are drawn as described in the spec,
with the coordinate systems defined as follows:</p>
<dl>
<dt>objectBoundingBox
<dd>
The coordinate system has its origin at the top left corner of the rectangle defined by the <a data-link-type=dfn title="concrete object size">concrete object size</a> that it’s being drawn into,
and the same width and height as the <a data-link-type=dfn title="concrete object size">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 data-link-type=dfn title="concrete object size">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 data-link-type=dfn title="concrete object size">concrete object size</a> that it’s being drawn into,
and the same width and height as the <a data-link-type=dfn title="concrete object size">concrete object size</a>.
<a href=http://www.w3.org/TR/SVG/coords.html#Units>User coordinates</a> are sized equivalently to the CSS <span class=css>px</span> unit.
</dl>
<p class=note>Note: It is expected that a future version of this module will define ways to refer to paint sources in external documents,
or ones that are created solely by script and never inserted into a document at all.</p>
<h4 class="heading settled" data-level=1.2.2 id=elementsources><span class=secno>1.2.2. </span><span class=content>
Using Out-Of-Document Sources: the <code>ElementSources</code> interface</span><a class=self-link href=#elementsources></a></h4>
<p>The <a class=css data-link-type=maybe href=#funcdef-element title=element()>element()</a> function normally selects elements within a document,
but elements that provide a <a data-link-type=dfn href=#paint-source title="paint source">paint source</a> don’t necessarily need to be in-document.
For example, an HTML <code>&lt;canvas&gt;</code> element can be created, maintained, and drawn into entirely in script,
with no need for it to be inserted into the document directly.</p>
<p>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 data-link-type=idl href=#dom-css-elementsources title=elementSources>elementSources</a> Map object provides this.</p>
<pre class=idl>partial interface <dfn class=idl-code data-dfn-type=interface data-export="" data-global-name="" id=dom-css>CSS<a class=self-link href=#dom-css></a></dfn> {
[SameObject] readonly attribute <a data-link-type=idl title=Map>Map</a> <dfn class=idl-code data-dfn-for=CSS data-dfn-type=attribute data-export="" data-global-name="CSS<interface>/elementsources<attribute>" data-readonly="" data-type="Map " id=dom-css-elementsources>elementSources<a class=self-link href=#dom-css-elementsources></a></dfn>;
};
</pre>
<p>Any entries in the <a data-link-type=idl href=#dom-css-elementsources title=elementSources>elementSources</a> map with a string key
and a value that is an object providing a <a data-link-type=dfn href=#paint-source title="paint source">paint source</a>
are made available to the <a class=css data-link-type=maybe href=#funcdef-element title=element()>element()</a> function.</p>
<p>Whenever <a class=css data-link-type=maybe href=#funcdef-element title=element()>element()</a> uses an <a class="production css" data-link-type=type href=http://dev.w3.org/csswg/selectors-4/#typedef-id-selector title="<id-selector>">&lt;id-selector&gt;</a>,
the ID’s value (without the leading <code>#</code> character)
is first looked up in the <a data-link-type=idl href=#dom-css-elementsources title=elementSources>elementSources</a> map:</p>
<ul>
<li>
If it’s found,
and the object associated with it provides a <a data-link-type=dfn href=#paint-source title="paint source">paint source</a>,
the <a class=css data-link-type=maybe href=#funcdef-element title=element()>element()</a> function represents that paint source.
<li>
If it’s found,
but the object associated with it <em>doesn’t</em> provide a <a data-link-type=dfn href=#paint-source title="paint source">paint source</a>,
the <a class=css data-link-type=maybe href=#funcdef-element title=element()>element()</a> function represent an <a data-link-type=dfn title="invalid image">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 id=issue-e72c9f56><a class=self-link href=#issue-e72c9f56></a>
This reuse of the ID selector matches Moz behavior.
I’m trying to avoid slapping a <a class="production css" data-link-type=type href=http://dev.w3.org/csswg/css-values-3/#identifier-value title="<custom-ident>">&lt;custom-ident&gt;</a> 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 <a class="production css" data-link-type=type href=http://dev.w3.org/csswg/css-values-3/#identifier-value title="<custom-ident>">&lt;custom-ident&gt;</a>,
like <span class=css>element(external fancy)</span> or something.
Naming suggestions welcome.
<div class=example>
For example, fancy animating backgrounds can be done with an external canvas:
<pre>&lt;script&gt;
var bg = document.createElement('canvas');
bg.height = 200;
bg.width = 1000;
drawFancyBackground(bg);
CSS.elementSources.set('fancy', bg);
&lt;/script&gt;
&lt;style&gt;
h1 {
background-image: element(#fancy);
}
&lt;/style&gt;
</pre>
<p>As the "fancy" canvas is drawn into and animated,
the backgrounds of all the H1 elements will automatically update in tandem.</p>
<p>Note that the <a data-link-type=idl href=#dom-css-el 8097 ementsources title=elementSources>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 <span class=css>#fancy</span>,
the backgrounds will still predictably come from the <a data-link-type=idl href=#dom-css-elementsources title=elementSources>elementSources</a> value instead.</p>
</div>
<h4 class="heading settled" data-level=1.2.3 id=element-cycles><span class=secno>1.2.3. </span><span class=content>
Cycle Detection</span><a class=self-link href=#element-cycles></a></h4>
<p>The <a class=css data-link-type=maybe href=#funcdef-element title=element()>element()</a> function can produce nonsensical circular relationships,
such as an element using itself as its own background.
These relationships can be easily and reliably detected and resolved, however,
by keeping track of a dependency graph and using common cycle-detection algorithms.</p>
<p>The dependency graph consists of edges such that:</p>
<ul>
<li>
every element depends on its children
<li>
for any element A with a property using the <a class=css data-link-type=maybe href=#funcdef-element title=element()>element()</a> 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>&lt;use&gt;</code> element depends on the element it referenced.
</ul>
<p>If the graph contains a cycle,
any <a class=css data-link-type=maybe href=#funcdef-element title=element()>element()</a> functions participating in the cycle are <a data-link-type=dfn title="invalid images">invalid images</a>.</p>
<h2 class="heading settled" data-level=2 id=gradients><span class=secno>2. </span><span class=content>
Gradients</span><a class=self-link href=#gradients></a></h2>
<p>A gradient is an image that smoothly fades from one color to another.
These are commonly used for subtle shading in background images, buttons, and many other things.
The gradient notations described in this section allow an author to specify such an image in a terse syntax,
so that the UA can generate the image automatically when rendering the page.
The syntax of a <a class="production css" data-link-type=type href=#typedef-gradient title="<gradient>">&lt;gradient&gt;</a> is:</p>
<pre class=prod><dfn data-dfn-type=type data-export="" id=typedef-gradient>&lt;gradient&gt;<a class=self-link href=#typedef-gradient></a></dfn> = [
<a class=production data-link-type=function title=linear-gradient()>&lt;linear-gradient()&gt;</a> <a class=prod-punc data-link-type=grammar href=http://dev.w3.org/csswg/css-values-3/#comb-one title=|>|</a> <a class=production data-link-type=function href=#funcdef-repeating-linear-gradient title=repeating-linear-gradient()>&lt;repeating-linear-gradient()&gt;</a> <a class=prod-punc data-link-type=grammar href=http://dev.w3.org/csswg/css-values-3/#comb-one title=|>|</a>
<a class=production data-link-type=function title=radial-gradient()>&lt;radial-gradient()&gt;</a> <a class=prod-punc data-link-type=grammar href=http://dev.w3.org/csswg/css-values-3/#comb-one title=|>|</a> <a class=production data-link-type=function href=#funcdef-repeating-radial-gradient title=repeating-radial-gradient()>&lt;repeating-radial-gradient()&gt;</a> <a class=prod-punc data-link-type=grammar href=http://dev.w3.org/csswg/css-values-3/#comb-one title=|>|</a>
<a class=production data-link-type=function href=#funcdef-conic-gradient title=conic-gradient()>&lt;conic-gradient()&gt;</a> <a class=prod-punc data-link-type=grammar href=http://dev.w3.org/csswg/css-values-3/#comb-one title=|>|</a> <a class=production data-link-type=function href=#funcdef-repeating-conic-gradient title=repeating-conic-gradient()>&lt;repeating-conic-gradient()&gt;</a> ]
</pre>
<div class=example>
<p>As with the other <a class="production css" data-link-type=type title="<image>">&lt;image&gt;</a> 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>A gradient is drawn into a box with the dimensions of the <a data-link-type=dfn title="concrete object size">concrete object size</a>,
referred to as the <dfn data-dfn-type=dfn data-export="" id=gradient-box>gradient box<a class=self-link href=#gradient-box></a></dfn>.
However, the gradient itself has no <a data-link-type=dfn title="intrinsic dimensions">intrinsic dimensions</a>.</p>
<div class=example>
For example, if you use a gradient as a background,
by default the gradient will draw into a <a data-link-type=dfn href=#gradient-box title="gradient box">gradient box</a> the size of the element’s padding box.
If <a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css-backgrounds-3/#background-size title=background-size>background-size</a> is explicitly set to a value such as <span class=css>100px 200px</span>,
then the <a data-link-type=dfn href=#gradient-box title="gradient box">gradient box</a> will be 100px wide and 200px tall.
Similarly, for a gradient used as a <a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css-lists-3/#propdef-list-style-image title=list-style-image>list-style-image</a>,
the box would be a 1em square,
which is the <a data-link-type=dfn title="default object size">default object size</a> for that property.
</div>
<p>Gradients are specified by defining the <dfn data-dfn-type=dfn data-noexport="" id=starting-point>starting point<a class=self-link href=#starting-point></a></dfn> and <dfn data-dfn-type=dfn data-noexport="" id=ending-point>ending point<a class=self-link href=#ending-point></a></dfn>
of a <dfn data-dfn-type=dfn data-export="" id=gradient-line>gradient line<a class=self-link href=#gradient-line></a></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 data-link-type=dfn href=#gradient-line title="gradient line">gradient line</a> to produce the actual gradient.</p>
<h3 class="heading settled" data-level=2.1 id=conic-gradients><span class=secno>2.1. </span><span class=content>
Conic Gradients: the <a class=css data-link-type=maybe href=#funcdef-conic-gradient title=conic-gradient()>conic-gradient()</a> notation</span><a class=self-link href=#conic-gradients></a></h3>
<p>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.</p>
<p>A conic gradient is specified by indicating 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 <a class="production css" data-link-type=type href=http://dev.w3.org/csswg/css-values-3/#length-value title="<length>">&lt;length&gt;</a>,
the color-stops of a conic gradient are specified with an <a class="production css" data-link-type=type href=http://dev.w3.org/csswg/css-values-3/#angle-value title="<angle>">&lt;angle&gt;</a>.
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.</p>
<p class=note>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.</p>
<h4 class="no-toc heading settled" data-level=2.1.1 id=conic-gradient-syntax><span class=secno>2.1.1. </span><span class=content>
<a class=css data-link-type=maybe href=#funcdef-conic-gradient title=conic-gradient()>conic-gradient()</a> Syntax</span><a class=self-link href=#conic-gradient-syntax></a></h4>
<p>The syntax for a conic gradient is:</p>
<pre class=prod><dfn data-dfn-type=function data-export="" id=funcdef-conic-gradient>conic-gradient()<a class=self-link href=#funcdef-conic-gradient></a></dfn> = conic-gradient(
[ at <a class=production data-link-type=type href=http://dev.w3.org/csswg/css-backgrounds-3/#position title="<position>">&lt;position&gt;</a> <a class=prod-punc data-link-type=grammar href=http://dev.w3.org/csswg/css-values-3/#comb-comma title=,>,</a> ]<a class=prod-punc data-link-type=grammar href=http://dev.w3.org/csswg/css-values-3/#mult-opt title=?>?</a>
<a class=production data-link-type=type href=#typedef-angular-color-stop-list title="<angular-color-stop-list>">&lt;angular-color-stop-list&gt;</a>
)
</pre>
<p>The <a class="production css" data-link-type=type href=http://dev.w3.org/csswg/css-backgrounds-3/#position title="<position>">&lt;position&gt;</a> argument is defined in [!CSS3VAL],
and is resolved using the center-point as the object area
and the gradient box as the positioning area.
If this argument is omitted,
it defaults to 'at center'.</p>
<p class=issue id=issue-42102e31><a class=self-link href=#issue-42102e31></a>
Anything else that might be useful? Defining the shape of the gradient as elliptical, perhaps?
<h4 class="no-toc heading settled" data-level=2.1.2 id=conic-color-stops><span class=secno>2.1.2. </span><span class=content>
Placing Color Stops</span><a class=self-link href=#conic-color-stops></a></h4>
<p>Color stops are placed on a <a data-link-type=dfn href=#gradient-line title="gradient line">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.</p>
<p class=note>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.</p>
<p>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, <span class=css>conic-gradient(red -50%, yellow 150%)</span> 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).</p>
<p>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 data-link-type=dfn href=#gradient-line title="gradient line">gradient line</a> at the location where this ray intersects it.</p>
<h4 class="no-toc heading settled" data-level=2.1.3 id=conic-gradient-examples><span class=secno>2.1.3. </span><span class=content>
Conic Gradient Examples</span><a class=self-link href=#conic-gradient-examples></a></h4>
<p class=issue id=issue-57d440f3><a class=self-link href=#issue-57d440f3></a>
Produce examples.
Better yet, strike this section, and intermix some examples into the sections above.
Do this for the other two types of gradients as well.
<h3 class="heading settled" data-level=2.2 id=repeating-gradients><span class=secno>2.2. </span><span class=content>
Repeating Gradients: the <a class=css data-link-type=maybe href=#funcdef-repeating-linear-gradient title=repeating-linear-gradient()>repeating-linear-gradient()</a>, <a class=css data-link-type=maybe href=#funcdef-repeating-radial-gradient title=repeating-radial-gradient()>repeating-radial-gradient()</a>, and <a class=css data-link-type=maybe href=#funcdef-repeating-conic-gradient title=repeating-conic-gradient()>repeating-conic-gradient()</a> notations</span><a class=self-link href=#repeating-gradients></a></h3>
<p>In addition to <span class=css>linear-gradient()</span>, <span class=css>radial-gradient()</span>, and <a class=css data-link-type=maybe href=#funcdef-conic-gradient title=conic-gradient()>conic-gradient()</a>,
this specification defines <dfn class=css data-dfn-type=function data-export="" id=funcdef-repeating-linear-gradient>repeating-linear-gradient()<a class=self-link href=#funcdef-repeating-linear-gradient></a></dfn>,
<dfn class=css data-dfn-type=function data-export="" id=funcdef-repeating-radial-gradient>repeating-radial-gradient()<a class=self-link href=#funcdef-repeating-radial-gradient></a></dfn>,
and <dfn class=css data-dfn-type=function data-export="" id=funcdef-repeating-conic-gradient>repeating-conic-gradient()<a class=self-link href=#funcdef-repeating-conic-gradient></a></dfn> values.
These notations take the same values
and are interpreted the same
as their respective non-repeating siblings defined previously.</p>
<div class=example>
<pre>repeating-conic-gradient(at 20%, white 0deg, white 20deg, red 20deg, red 40deg)</pre>
<p class=issue id=issue-091fbe43><a class=self-link href=#issue-091fbe43></a>Insert rendering here.
</div>
<h3 class="heading settled" data-level=2.3 id=color-stop-syntax><span class=secno>2.3. </span><span class=content>
Gradient Color-Stops</span><a class=self-link href=#color-stop-syntax></a></h3>
<pre class=prod><dfn data-dfn-type=type data-export="" id=typedef-color-stop-list>&lt;color-stop-list&gt;<a class=self-link href=#typedef-color-stop-list></a></dfn> =
[ <a class=production data-link-type=type href=#typedef-linear-color-stop title="<linear-color-stop>">&lt;linear-color-stop&gt;</a> <a class=prod-punc data-link-type=grammar href=http://dev.w3.org/csswg/css-values-3/#comb-comma title=,>,</a> <a class=production data-link-type=type href=#typedef-linear-color-hint title="<linear-color-hint>">&lt;linear-color-hint&gt;</a><a class=prod-punc data-link-type=grammar href=http://dev.w3.org/csswg/css-values-3/#mult-opt title=?>?</a> ]<a class=prod-punc data-link-type=grammar href=http://dev.w3.org/csswg/css-values-3/#mult-comma title=#>#</a> <a class=prod-punc data-link-type=grammar href=http://dev.w3.org/csswg/css-values-3/#comb-comma title=,>,</a> <a class=production data-link-type=type href=#typedef-linear-color-stop title="<linear-color-stop>">&lt;linear-color-stop&gt;</a>
<dfn data-dfn-type=type data-export="" id=typedef-linear-color-stop>&lt;linear-color-stop&gt;<a class=self-link href=#typedef-linear-color-stop></a></dfn> = <a class=production data-link-type=type href=http://dev.w3.org/csswg/css-color-3/#valuea-def-color title="<color>">&lt;color&gt;</a> &amp;&amp; <a class=production data-link-type=type href=#typedef-color-stop-length title="<color-stop-length>">&lt;color-stop-length&gt;</a>
<dfn data-dfn-type=type data-export="" id=typedef-linear-color-hint>&lt;linear-color-hint&gt;<a class=self-link href=#typedef-linear-color-hint></a></dfn> = <a class=production data-link-type=type href=http://dev.w3.org/csswg/css-values-3/#length-value title="<length>">&lt;length&gt;</a> <a class=prod-punc data-link-type=grammar href=http://dev.w3.org/csswg/css-values-3/#comb-one title=|>|</a> <a class=production data-link-type=type href=http://dev.w3.org/csswg/css-values-3/#percentage-value title="<percentage>">&lt;percentage&gt;</a>
<dfn data-dfn-type=type data-export="" id=typedef-color-stop-length>&lt;color-stop-length&gt;<a class=self-link href=#typedef-color-stop-length></a></dfn> = [ <a class=production data-link-type=type href=http://dev.w3.org/csswg/css-values-3/#length-value title="<length>">&lt;length&gt;</a> <a class=prod-punc data-link-type=grammar href=http://dev.w3.org/csswg/css-values-3/#comb-one title=|>|</a> <a class=production data-link-type=type href=http://dev.w3.org/csswg/css-values-3/#percentage-value title="<percentage>">&lt;percentage&gt;</a> ]{1<a class=prod-punc data-link-type=grammar href=http://dev.w3.org/csswg/css-values-3/#comb-comma title=,>,</a>2}
<dfn data-dfn-type=type data-export="" id=typedef-angular-color-stop-list>&lt;angular-color-stop-list&gt;<a class=self-link href=#typedef-angular-color-stop-list></a></dfn> =
[ <a class=production data-link-type=type href=#typedef-angular-color-stop title="<angular-color-stop>">&lt;angular-color-stop&gt;</a> <a class=prod-punc data-link-type=grammar href=http://dev.w3.org/csswg/css-values-3/#comb-comma title=,>,</a> <a class=production data-link-type=type href=#typedef-angular-color-hint title="<angular-color-hint>">&lt;angular-color-hint&gt;</a><a class=prod-punc data-link-type=grammar href=http://dev.w3.org/csswg/css-values-3/#mult-opt title=?>?</a> ]<a class=prod-punc data-link-type=grammar href=http://dev.w3.org/csswg/css-values-3/#mult-comma title=#>#</a> <a class=prod-punc data-link-type=grammar href=http://dev.w3.org/csswg/css-values-3/#comb-comma title=,>,</a> <a class=production data-link-type=type href=#typedef-angular-color-stop title="<angular-color-stop>">&lt;angular-color-stop&gt;</a>
<dfn data-dfn-type=type data-export="" id=typedef-angular-color-stop>&lt;angular-color-stop&gt;<a class=self-link href=#typedef-angular-color-stop></a></dfn> = <a class=production data-link-type=type href=http://dev.w3.org/csswg/css-color-3/#valuea-def-color title="<color>">&lt;color&gt;</a> &amp;&amp; <a class=production data-link-type=type href=#typedef-color-stop-angle title="<color-stop-angle>">&lt;color-stop-angle&gt;</a><a class=prod-punc data-link-type=grammar href=http://dev.w3.org/csswg/css-values-3/#mult-opt title=?>?</a>
<dfn data-dfn-type=type data-export="" id=typedef-angular-color-hint>&lt;angular-color-hint&gt;<a class=self-link href=#typedef-angular-color-hint></a></dfn> = <a class=production data-link-type=type href=http://dev.w3.org/csswg/css-values-3/#angle-value title="<angle>">&lt;angle&gt;</a> <a class=prod-punc data-link-type=grammar href=http://dev.w3.org/csswg/css-values-3/#comb-one title=|>|</a> <a class=production data-link-type=type href=http://dev.w3.org/csswg/css-values-3/#percentage-value title="<percentage>">&lt;percentage&gt;</a>
<dfn data-dfn-type=type data-export="" id=typedef-color-stop-angle>&lt;color-stop-angle&gt;<a class=self-link href=#typedef-color-stop-angle></a></dfn> = [ <a class=production data-link-type=type href=http://dev.w3.org/csswg/css-values-3/#angle-value title="<angle>">&lt;angle&gt;</a> <a class=prod-punc data-link-type=grammar href=http://dev.w3.org/csswg/css-values-3/#comb-one title=|>|</a> <a class=production data-link-type=type href=http://dev.w3.org/csswg/css-values-3/#percentage-value title="<percentage>">&lt;percentage&gt;</a> ]{1<a class=prod-punc data-link-type=grammar href=http://dev.w3.org/csswg/css-values-3/#comb-comma title=,>,</a>2}
<dfn data-dfn-type=type data-export="" id=typedef-color-stop>&lt;color-stop&gt;<a class=self-link href=#typedef-color-stop></a></dfn> = <a class=production data-link-type=type href=#typedef-color-stop-length title="<color-stop-length>">&lt;color-stop-length&gt;</a> <a class=prod-punc data-link-type=grammar href=http://dev.w3.org/csswg/css-values-3/#comb-one title=|>|</a> <a class=production data-link-type=type href=#typedef-color-stop-angle title="<color-stop-angle>">&lt;color-stop-angle&gt;</a>
</pre>
<div class=railroad><svg class=railroad-diagram height=121 viewBox="0 0 597 121" width=597>
<g transform="translate(.5 .5)">
<path d="M 20 50 v 20 m 10 -20 v 20 m -10 -10 h 20.5">
</path><path d="M40 60h10">
</path><g>
<path d="M50 60h0.0">
</path><path d="M410.0 60h0.0">
</path><path d="M50.0 60h10">
</path><g>
<path d="M60.0 60h0.0">
</path><path d="M400.0 60h0.0">
</path><path d="M60.0 60h10">
</path><g>
<path d="M70.0 60h0.0">
</path><path d="M186.0 60h0.0">
</path><rect height=22 width=116 x=70.0 y=49>
</rect><text x=128.0 y=64>
&lt;color-stop&gt;</text></g><path d="M186.0 60h10">
</path><path d="M196.0 60h10">
</path><g>
<path d="M206.0 60h0.0">
</path><path d="M234.0 60h0.0">
</path><rect height=22 rx=10 ry=10 width=28 x=206.0 y=49>
</rect><text x=220.0 y=64>
,</text></g><path d="M234.0 60h10">
</path><g>
<path d="M244.0 60h0.0">
</path><path d="M400.0 60h0.0">
</path><path d="M244.0 60a10 10 0 0 0 10 -10v0a10 10 0 0 1 10 -10">
</path><g>
<path d="M264.0 40h0.0">
</path><path d="M380.0 40h0.0">
</path><rect height=22 width=116 x=264.0 y=29>
</rect><text x=322.0 y=44>
&lt;color-hint&gt;</text></g><path d="M380.0 40a10 10 0 0 1 10 10v0a10 10 0 0 0 10 10">
</path><path d="M244.0 60h20">
</path><g>
<path d="M264.0 60h116">
</path></g><path d="M380.0 60h20">
</path></g></g><path d="M400.0 60h10">
</path><path d="M60.0 60a10 10 0 0 0 -10 10v10a10 10 0 0 0 10 10">
</path><g>
<path d="M60.0 90h156.0">
</path><path d="M244.0 90h156.0">
</path><rect height=22 rx=10 ry=10 width=28 x=216.0 y=79>
</rect><text x=230.0 y=94>
,</text></g><path d="M400.0 90a10 10 0 0 0 10 -10v-10a10 10 0 0 0 -10 -10">
</path></g><path d="M410 60h10">
</path><path d="M420 60h10">
</path><g>
<path d="M430 60h0.0">
</path><path d="M546.0 60h0.0">
</path><rect height=22 width=116 x=430.0 y=49>
</rect><text x=488.0 y=64>
&lt;color-stop&gt;</text></g><path d="M546 60h10">
</path><path d="M 556 60 h 20 m -10 -10 v 20 m 10 -20 v 20">
</path></g></svg></div>
<p class=issue id=issue-cfc5db5e><a class=self-link href=#issue-cfc5db5e></a>
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).
<p>The colors in gradients are specified using <a data-link-type=dfn href=#color-stop title="color stops">color stops</a>.
A <dfn data-dfn-type=dfn data-export="" id=color-stop>color stop<a class=self-link href=#color-stop></a></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.)</p>
<p>Between two <a data-link-type=dfn href=#color-stop title="color stops">color stops</a> there can be a <dfn data-dfn-type=dfn data-local-title="color hint" data-noexport="" id=color-interpolation-hint>color interpolation hint<a class=self-link href=#color-interpolation-hint></a></dfn>,
which specifies how the colors of the two <a data-link-type=dfn href=#color-stop title="color stops">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 data-link-type=dfn href=#color-interpolation-hint title="color interpolation hint">color interpolation hint</a> between any two given <a data-link-type=dfn href=#color-stop title="color stops">color stops</a>;
using more than that makes the function invalid.</p>
<p>Color stops are organized into a <dfn data-dfn-type=dfn data-export="" id=color-stop-list>color stop list<a class=self-link href=#color-stop-list></a></dfn>,
which is a list of one or more <a data-link-type=dfn href=#color-stop title="color stops">color stops</a>.
The first and last <a data-link-type=dfn href=#color-stop title="color stops">color stops</a> in the list
must have a color
(though their position can be omitted).</p>
<p><a data-link-type=dfn href=#color-stop title="Color stops">Color stops</a> and <a data-link-type=dfn href=#color-interpolation-hint title="color hints">color hints</a> are placed on a <a data-link-type=dfn href=#gradient-line title="gradient line">gradient line</a>,
which defines the colors at every point of a gradient.
The gradient function defines the shape and length of the <a data-link-type=dfn href=#gradient-line title="gradient line">gradient line</a>,
along with its <a data-link-type=dfn href=#starting-point title="starting point">starting point</a> and <a data-link-type=dfn href=#ending-point title="ending point">ending point</a>.</p>
<p><a data-link-type=dfn href=#color-stop title="Color stops">Color stops</a> and <a data-link-type=dfn href=#color-interpolation-hint title="color hints">color hints</a> must be specified in order.
Percentages refer to the length of the <a data-link-type=dfn href=#gradient-line title="gradient line">gradient line</a> between the <a data-link-type=dfn href=#starting-point title="starting point">starting point</a> and <a data-link-type=dfn href=#ending-point title="ending point">ending point</a>,
with 0% being at the starting point
and 100% being at the ending point.
Lengths are measured from the <a data-link-type=dfn href=#starting-point title="starting point">starting point</a> in the direction of the <a data-link-type=dfn href=#ending-point title="ending point">ending point</a> along the <a data-link-type=dfn href=#gradient-line title="gradient line">gradient line</a>.
Angles are measured with 0deg pointing up,
and positive angles corresponding to clockwise rotations from there.</p>
<p><a data-link-type=dfn href=#color-stop title="Color stops">Color stops</a> and <a data-link-type=dfn href=#color-interpolation-hint title="color hints">color hints</a> are usually placed between the <a data-link-type=dfn href=#starting-point title="starting point">starting point</a> and <a data-link-type=dfn href=#ending-point title="ending point">ending point</a>,
but that’s not required;
the gradient line extends infinitely in both directions,
and a <a data-link-type=dfn href=#color-stop title="color stop">color stop</a> or <a data-link-type=dfn href=#color-interpolation-hint title="color hint">color hint</a> can be placed at any position on the <a data-link-type=dfn href=#gradient-line title="gradient line">gradient line</a>.</p>
<p>A <a data-link-type=dfn href=#color-stop title="color stop">color stop</a> with two locations is mostly equivalent
to specifying two <a data-link-type=dfn href=#color-stop title="color stops">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></p>
<p>The position of a <a data-link-type=dfn href=#color-stop title="color stop">color stop</a> can be omitted.
This causes the <a data-link-type=dfn href=#color-stop title="color stop">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.</p>
<p>The following steps must be applied <em>in order</em> to process the <a class="production css" data-link-type=type href=#typedef-color-stop-list title="<color-stop-list>">&lt;color-stop-list&gt;</a>.
After applying these rules,
all <a data-link-type=dfn href=#color-stop title="color stops">color stops</a> and <a data-link-type=dfn href=#color-interpolation-hint title="color hints">color hints</a> will have a definite position and color (if appropriate)
and they will be in ascending order:</p>
<ol>
<li>
If the first <a data-link-type=dfn href=#color-stop title="color stop">color stop</a> does not have a position,
set its position to 0%.
If the last <a data-link-type=dfn href=#color-stop title="color stop">color stop</a> does not have a position,
set its position to 100%.
<li>
If a <a data-link-type=dfn href=#color-stop title="color stop">color stop</a> or <a data-link-type=dfn href=#color-interpolation-hint title="color hint">color hint</a> has a position that is less than the specified position of any <a data-link-type=dfn href=#color-stop title="color stop">color stop</a> or <a data-link-type=dfn href=#color-interpolation-hint title="color hint">color hint</a> before it in the list,
set its position to be equal to the largest specified position of any <a data-link-type=dfn href=#color-stop title="color stop">color stop</a> or <a data-link-type=dfn href=#color-interpolation-hint title="color hint">color hint</a> before it.
<li>
If any <a data-link-type=dfn href=#color-stop title="color stop">color stop</a> still does not have a position,
then, for each run of adjacent <a data-link-type=dfn href=#color-stop title="color stops">color stops</a> without positions,
set their positions so that they are evenly spaced between the preceding and following <a data-link-type=dfn href=#color-stop title="color stops">color stops</a> with positions.
</ol>
<p class=issue id=issue-ffe26cbe><a class=self-link href=#issue-ffe26cbe></a>
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 data-link-type=dfn href=#color-stop title="color stops">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.
<p>At each <a data-link-type=dfn href=#color-stop title="color stop">color stop</a> position,
the line is the color of the <a data-link-type=dfn href=#color-stop title="color stop">color stop</a>.
Between two <a data-link-type=dfn href=#color-stop title="color stops">color stops</a>,
the line’s color is interpolated between the colors of the two <a data-link-type=dfn href=#color-stop title="color stops">color stops</a>,
with the interpolation taking place in premultiplied RGBA space.</p>
<p>By default,
this interpolation is linear—<wbr>at 25%, 50%, or 75% of the distance between two <a data-link-type=dfn href=#color-stop title="color stops">color stops</a>,
the color is a 25%, 50%, or 75% blend of the colors of the two stops.</p>
<p>However, if a <a data-link-type=dfn href=#color-interpolation-hint title="color hint">color hint</a> was provided between two <a data-link-type=dfn href=#color-stop title="color stops">color stops</a>,
the interpolation is non-linear,
and controlled by the hint:</p>
<ol>
<li>
Determine the location of the <a data-link-type=dfn href=#color-interpolation-hint title="color hint">color hint</a> as a percentage of the distance between the two <a data-link-type=dfn href=#color-stop title="color stops">color stops</a>,
denoted as a number between 0 and 1,
where 0 indicates the hint is placed right on the first <a data-link-type=dfn href=#color-stop title="color stop">color stop</a>,
and 1 indicates the hint is placed right on the second <a data-link-type=dfn href=#color-stop title="color stop">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 data-link-type=dfn href=#color-stop title="color stops">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 data-link-type=dfn href=#color-stop title="color stops">color stops</a>,
blending <code>(1 - C)</code> of the first stop and <var>C</var> of the second stop.
</ol>
<p class=note>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 data-link-type=dfn href=#color-stop title="color stops">color stops</a>,
and produces smooth, even blends between the <a data-link-type=dfn href=#color-stop title="color stops">color stops</a> and the "halfway point".</p>
<p>Before the first <a data-link-type=dfn href=#color-stop title="color stop">color stop</a>,
the line is the color of the first <a data-link-type=dfn href=#color-stop title="color stop">color stop</a>.
After the last <a data-link-type=dfn href=#color-stop title="color stop">color stop</a>, the line is the color of the last <a data-link-type=dfn href=#color-stop title="color stop">color stop</a>.</p>
<p>If multiple <a data-link-type=dfn href=#color-stop title="color stops">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.</p>
<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>1. linear-gradient(red, white 20%, blue)
=1=&gt;
linear-gradient(red 0%, white 20%, blue 100%)
2. linear-gradient(red 40%, white, black, blue)
=13=&gt;
linear-gradient(red 40%, white 60%, black 80%, blue 100%)
3. linear-gradient(red -50%, white, blue)
=13=&gt;
linear-gradient(red -50%, white 25%, blue 100%)
4. linear-gradient(red -50px, white, blue)
=13=&gt;
linear-gradient(red -50px, white calc(-25px + 50%), blue 100%)
5. linear-gradient(red 20px, white 0px, blue 40px)
=2=&gt;
linear-gradient(red 20px, white 20px, blue 40px)
6. linear-gradient(red, white -50%, black 150%, blue)
=12=&gt;
linear-gradient(red 0%, white 0%, black 150%, blue 150%)
7. linear-gradient(red 80px, white 0px, black, blue 100px)
=23=&gt;
linear-gradient(red 80px, white 80px, black 90px, blue 100px)
8. linear-gradient(red, 25%, white)
=14=&gt;
linear-gradient(red 0%, rgb(100%,50%,50%) 25%, white 100%)
</pre>
</div>
<div class=example>
The following example illustrates the difference between
a gradient transitioning in pre-multiplied sRGBA
and one transitioning (incorrectly) in non-premultiplied.
In both of these example,
the gradient is drawn over a white background.
Both gradients could be written with the following value:
<pre>linear-gradient(90deg, red, transparent, blue)</pre>
<p>In premultiplied space,
transitions to or from "transparent" always look nice:</p>
<object data=images/gradient2.svg height=100 width=200>(Image requires SVG)</object>
<p>On the other hand,
if a gradient were to incorrectly transition in non-premultiplied space,
the colors near "transparent" would noticeably darken to a grayish color,
because "transparent" is actually a shorthand for <span class=css>rgba(0,0,0,0)</span>, or transparent black:</p>
<object data=images/gradient3.svg height=100 width=200>(Image requires SVG)</object>
</div>
<p class=note>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 <a data-link-type=dfn href=#color-stop title="color stop">color stop</a> to unintentionally try to move before an earlier one.
For example, the rule <a class=css data-link-type=propdesc href=http://dev.w3.org/csswg/css-backgrounds-3/#background-image title=background-image>background-image: linear-gradient(yellow 100px, blue 50%)</a>
wouldn’t require any fix-up as long as the background area is at least 200px tall.
If it was 150px tall, however,
the blue <a data-link-type=dfn href=#color-stop title="color stop’s">color stop’s</a> position would be equivalent to "75px",
which precedes the yellow <a data-link-type=dfn href=#color-stop title="color stop">color stop</a>,
and would be corrected to a position of 100px.</p>