8000 csswg-drafts/css-images-3/Overview.src.html at f36dbca4ed549e8147e12d5a44640e98e5aece23 · w3c/csswg-drafts · GitHub
Skip to content

Latest commit

 

History

History
1820 lines (1389 loc) · 95.6 KB

File metadata and controls

1820 lines (1389 loc) · 95.6 KB
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head profile="http://www.w3.org/2006/03/hcard">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>CSS Image Values and Replaced Content Module Level 3</title>
<link rel="stylesheet" type="text/css" href="../default.css">
<link rel="stylesheet" type="text/css" href="http://www.w3.org/StyleSheets/TR/W3C-[STATUS].css">
</head>
<div class="head">
<!--logo-->
<h1>CSS Image Values and Replaced Content Module Level 3</h1>
<h2 class="no-num no-toc">[LONGSTATUS] [DATE]</h2>
<dl>
<dt>This Version:</dt>
<dd><a href="http://dev.w3.org/csswg/css3-images/">http://dev.w3.org/csswg/css3-images/</a>
<!-- <dd><a href="[VERSION]">http://www.w3.org/TR/[YEAR]/WD-css3-images-[CDATE]/</a>-->
<dt>Latest Version:</dt>
<dd><a href="http://www.w3.org/TR/css3-images/">http://www.w3.org/TR/css3-images/</a></dd>
<dt>Editor's Draft:</dt>
<dd><a href="http://dev.w3.org/csswg/css3-images/">http://dev.w3.org/csswg/css3-images/</a>
<dt>Previous Version:</dt>
<dd><a href="http://www.w3.org/TR/2012/WD-css3-images-20120112/">http://www.w3.org/TR/2012/WD-css3-images-20120112/</a>
<dt>Disposition of Last Call Comments:
<dd><a href="http://dev.w3.org/csswg/css3-images/issues-lc-2012">http://dev.w3.org/csswg/css3-images/issues-lc-2012</a>
<dt>Issue Tracking:</dt>
<dd><a href="http://www.w3.org/Style/CSS/Tracker/products/27">http://www.w3.org/Style/CSS/Tracker/products/27</a>
<dt>Feedback:</dt>
<dd><a href="http://lists.w3.org/Archives/Public/www-style/">www-style@w3.org</a> with subject line &ldquo;<kbd>[[SHORTNAME]] <var>&hellip; message topic &hellip;</var></kbd>&rdquo;
<dt>Editors:</dt>
<dd class='vcard'>
<a class='url fn' href="http://fantasai.inkedblade.net/contact">Elika J. Etemad</a> (<span class='org'>Mozilla</span>)</dd>
<dd class='vcard'>
<a class='url fn' href="http://www.xanthir.com/contact/">Tab Atkins Jr.</a> (<span class='org'>Google</span>)</dd>
</dl>
<!--copyright-->
<hr title="Separator for header">
</div>
<h2 class="no-num no-toc" id="abstract">Abstract</h2>
<p>CSS is a language for describing the rendering of structured documents (such as HTML and XML) on screen, on paper, in speech, etc. This module contains the features of CSS level&nbsp;3 relating to the &lt;image> type and replaced elements. It includes and extends the functionality of CSS level&nbsp;2 [[!CSS21]], which builds on CSS level&nbsp;1 [[CSS1]]. The main extensions compared to level&nbsp;2 are the generalization of the &lt;url> type to the &lt;image> type, several additions to the ''&lt;image>'' type, a generic sizing algorithm for images and other replaced content in CSS, and several properties controlling the interaction of replaced elements and CSS's layout models.</p>
<h2 class="no-num no-toc" id="status">Status of this document</h2>
<!--status-->
<p>&#8203;&#8203;&#8203;&#8203;&#8203;This specification is a <strong>Last Call Working Draft</strong>. All
persons are encouraged to review this document and <strong>send comments
to the <a href="http://lists.w3.org/Archives/Public/www-style/">www-style</a>
mailing list</strong> as described above. The <strong>deadline for
comments</strong> is <strong>7 February 2012</strong>.
<p>The following features are at risk: &hellip;
<ol>
<li>The <a href="#image-notation">image()</a> notation</li>
<li>The 'object-fit', 'object-position', 'image-orientation', and 'image-resolution' properties</li>
</ol>
<h2 class="no-num no-toc" id="contents">Table of contents</h2>
<!--toc-->
<h2 id="intro">
Introduction</h2>
<p><em>This section is not normative.</em>
<p>In CSS Levels 1 and 2, image values, such as those used in the
'background-image' property, could only be given by a single URL
value. This module introduces additional ways of representing 2D
images, for example as <a href="#image-notation">a list of URIs denoting fallbacks</a>,
<!-- as <a href="#element-reference">a reference to an element</a>, -->
or as <a href="#gradients">a gradient</a>.</p>
<p>This module also defines several properties for <a href="#image-processing">manipulating
raster images</a> and for <a href="#object-fit">sizing</a> or
<a href="#object-position">positioning</a> replaced elements
such as images within the box determined by the CSS layout algorithms.
It also defines in a generic way CSS's <a href="#sizing">sizing algorithm</a>
for images and other replaced elements.
<h3 id="placement">
Module Interactions</h3>
<p>This module defines and extends the ''&lt;image>'' value type
defined in [[!CSS3VAL]]. Furthermore it replaces the ''&lt;url>''
type in the 'background-image' and 'list-style-image' definitions
in CSS1 and CSS2 and adds ''&lt;image>'' as an alternative to
''&lt;url>'' in the 'content' property's value. It is presumed that
CSS specifications beyond CSS2.1 will use the ''&lt;image>'' notation
in place of ''&lt;url>'' where 2D images are expected. (See e.g.
[[CSS3BG]].)
<p>Of the properties defined in this module, only 'image-resolution'
applies to <code>::first-line</code> and <code>::first-letter</code>.
<h3 id="values">
Values</h3>
This specification follows the <a href="https://www.w3.org/TR/CSS21/about.html#property-defs">CSS property definition conventions</a> from [[!CSS2]].
Value types not defined in this specification are defined in CSS Values & Units [[!CSS-VALUES-3]].
Other CSS modules may expand the definitions of these value types.
In addition to the property-specific values listed in their definitions,
all properties defined in this specification
also accept the <a>CSS-wide keywords</a> keywords as their property value.
For readability they have not been repeated explicitly.
<h2 id='resolution-units'>
Resolution Units: the &lt;resolution> type</h2>
<p>This specification defines the following units as part of the <dfn id='resolution-type'>&lt;resolution></dfn>
value type:</p>
<dl>
<dt><dfn>''dpi''</dfn></dt>
<dd>dots per inch</dd>
<dt><dfn>''dpcm''</dfn></dt>
<dd>dots per centimeter</dd>
<dt><dfn>''dppx''</dfn></dt>
<dd>dots per ''px'' unit</dd>
</dl>
<p>The ''&lt;resolution>'' unit represents the size of a single "dot" in a
graphical representation by indicating how many of these dots fit in a
CSS 'in', 'cm', or 'px'.
For uses, see e.g. the ''resolution'' media query in [[MEDIAQ]]
or the 'image-resolution' property defined below.
<p class="note">Note that due to the 1:96 fixed ratio of CSS ''in'' to
CSS ''px'', ''1dppx'' is equivalent to ''96dpi''. This corresponds to
the default resolution of images displayed in CSS: see 'image-resolution'.
<div class="example">
<p>The following @media rule uses Media Queries [[MEDIAQ]] to assign
some special style rules to devices that use two or more device pixels
per CSS ''px'' unit:
<pre>@media (min-resolution: 2dppx) { ... }</pre>
</div>
<!-- ====================================================================== -->
<h2 id="image-values">
Image Values: the &lt;image> type</h2>
<p>The ''&lt;image>'' value type denotes a 2D image. It can be a
<a href="#url-notation">url reference</a>,
<a href="#image-notation">image notation</a>,
<!-- <a href="#element-reference">element reference</a>, -->
or <a href="#gradients">gradient notation</a>.
Its syntax is:</p>
<pre class="prod"><dfn id='image-type'>&lt;image></dfn> = <i>&lt;url></i> | <i>&lt;image-list></i> | <i>&lt;element-reference></i> | <i>&lt;gradient></i></pre>
<p>An ''&lt;image>'' can be used in many CSS properties, including the
'background-image', 'list-style-image', 'cursor' properties [[!CSS21]] (where it replaces the ''&lt;url>'' component in the property's value).</p>
<p>In some cases, an image is invalid, such as a ''&lt;url>'' pointing to a resource that is not a valid image format. An <dfn>invalid image</dfn> is rendered as a solid-color ''transparent'' image with no intrinsic dimensions. However, <i>invalid images</i> have special behavior in some contexts, such as the ''image()'' notation.</p>
<!-- ====================================================================== -->
<h3 id="url-notation">
Image References and Image Slices: the ''&lt;url>'' type and ''url()'' notation</h3>
<p>The simplest way to indicate an image is to reference an image file by URL. This can be done with the <a href="http://www.w3.org/TR/CSS21/syndata.html#uri">''url()'' notation</a>, defined in [[!CSS21]].
<div class="example">
<p>In the example below, a background image is specified with ''url()''
syntax:</p>
<pre>background-image: url(wavy.png);</pre>
</div>
<p>If the UA cannot download, parse, or otherwise successfully display the contents at the URL as an image, it must be treated as an <i>invalid image</i>.</p>
<!-- ====================================================================== -->
<h3 id="image-notation">
Image Fallbacks and Annotations: the ''image()'' notation</h3>
<p>The ''image()'' function allows an author to:</p>
<ul>
<li>use <a href="http://www.w3.org/TR/media-frags/">media fragments</a> to clip out a portion of an image</li>
<li>specify fallback images in case the preferred image can't be decoded or is a type that the browser doesn't recognize</li>
<li>use a solid color as an image</li>
<li>annotate an image with a directionality</li>
</ul>
<p>The ''image()'' notation is defined as:
<pre class='prod'><dfn id='image-list-type'>&lt;image-list></dfn> = image( [ &lt;image-decl> , ]* [ &lt;image-decl> | &lt;color> ] )
<dfn id='image-decl-type'>&lt;image-decl></dfn> = [ &lt;url> | &lt;string> | &lt;element-reference> ]</pre>
<p>Each ''&lt;string>'& 133E #039; or ''&lt;url>'' inside ''image()'' represents an image, just as if the <a href="#url-notation">''url()'' notation</a> had been used. As usual for URLs in CSS, relative URLs are resolved to an absolute URL (as described in Values &amp; Units [[!CSS3VAL]]) when a specified ''image()'' value is computed.</p>
<h4 id="image-fragments">
Image Fragments</h4>
<p>When a URL specified in ''image()'' represents a portion of a resource
(e.g. by the use of <a href="http://www.w3.org/TR/media-frags/#naming-space">media fragment identifiers</a>)
that portion is clipped out of its context and used as a standalone image.
<div class="example">
<p>For example, given the following image* and CSS:</p>
<a href="sprites.svg">
<img src="sprites.svg" height="20" width="180" alt="[9 circles, with 0 to 8 eighths filled in]">
</a>
<pre>background-image: image('sprites.svg#xywh=40,0,20,20')</pre>
<p>...the background of the element will be the portion of the image that starts at (40px,0px)
and is 20px wide and tall, which is just the circle with a quarter filled in.</p>
<p><small>* SVG-in-&lt;img> support required. Click the picture to view the SVG directly.</small></p>
</div>
<p>So that authors can take advantage of CSS's forwards-compatible parsing
rules to provide a fallback for image slices, implementations that support
the ''image()'' notation <em>must</em> support the <code>xywh=#,#,#,#</code>
form of media fragment identifiers for images specified via ''image()''. [[!MEDIA-FRAGS]]</p>
<div class='example'>
<p>Note that image fragments can also be used with the ''url()'' notation. However, a legacy UA that doesn't understand the media fragments notation will ignore the fragment and simply display the entirety of the image.</p>
<p>Since the ''image()'' notation requires UAs to support media fragments, authors can take advantage of CSS's forward-compatible parsing rules to provide a fallback when using an image fragment URL:</p>
<pre>
<!-- -->background-image: url('swirl.png'); /* old UAs */
<!-- -->background-image: image('sprites.png#xywh=10,30,60,20'); /* new UAs */</pre>
</div>
<h4 id="image-fallbacks">
Image Fallbacks</h4>
<p>Multiple ''&lt;image-decl>s'' can be given separated by commas, in which case the function represents the first image that's not an <i>invalid image</i>. The final argument can specify a ''&lt;color>'' to serve as an ultimate fallback; this can be used, e.g. for 'background-image', to ensure adequate contrast if none of the preceding ''&lt;image-decl>s'' can be used. If the final argument is a ''&lt;color>'', it represents a solid-color image of the given color with no <i>intrinsic dimensions</i>. If all of the provided ''&lt;image-decl>s'' are <i>invalid images</i> and a fallback color was not provided as the last argument, the entire ''image()'' function must be treated as an <i>invalid image</i>.
<div class="example">
<p>The rule below would tell the UA to load ''wavy.svg'' if it can; failing that to load ''wavy.png''; failing that to display ''wavy.gif''. For example, the browser might not understand how to render SVG images, and the PNG may be temporarily 404 (returning an HTML 404 page, which the browser can't decode as an image) due to a server move, so the GIF is used until one of the previous problems corrects itself.</p>
<pre>background-image: image("wavy.svg", 'wavy.png' , "wavy.gif");</pre>
</div>
<div class='example'>
<p>The fallback color can be used to ensure that text is still readable even when the image fails to load. For example, the following code works fine if the image is rectangular and has no transparency:</p>
<pre>
body { color: black; background: white; }
p.special { color: white; background: url("dark.png") black; }</pre>
<p>When the image doesn't load, the background color is still there to ensure that the white text is readable. However, if the image has some transparency, the black will be visible behind it, which is probably not desired. The ''image()'' function addresses this:</p>
<pre>
body { color: black; background: white; }
p.special { color: white; background: image("dark.png", black); }</pre>
<p>Now, the black won't show at all if the image loads, but if for whatever reason the image fails, it'll pop in and prevent the white text from being set against a white background.</p>
</div>
<p>If a URL uses a fragment identifier syntax that the implementation does not understand, or does not consider valid for that type of image, the URL must be treated as representing an <i>invalid image</i>. <span class='note'>This error-handling is limited to image(), and not in the definition of URL, for legacy compat reasons.</span></p>
<div class='example'>
<p>For example, if a future specification defined a way to refer to a specific frame of an animated GIF with a fragment identifier, an author could write the following to get newer browsers to use the GIF's frame, and older browsers to instead download the fallback image:</p>
<pre>background-image: image('cat_meme.gif#frame=5', 'lolcat.png');</pre>
</div>
<!-- XXX SVG fragment example with spriting / fallbacks (once SVG can provide this) -->
<h4 id="color-images">
Solid-color Images</h4>
<div class='example'>
<p>At times, one may need a solid-color image for a property or function that does not accept the ''&lt;color>'' type directly. The ''image()'' function can be used for this: by specifying <em>only</em> a color without any URLs, the function immediately falls back to representing a solid-color image of the chosen color.
<pre>background-image: image(rgba(0,0,255,.5)), url("bg-image.png");</pre>
<p>In the above, the background is the image "bg-image.png", overlaid with partially-transparent blue.
</div>
<!-- Removed per WG decision, commenting it out so I can more easily punt it to Images 4
<h4 id='bidi-images'>
Bidi-sensitive Images</h4>
<p>Along with each ''&lt;image-decl>'', the author may specify a directionality, similar to adding a <code>dir</code> attribute to an element in HTML. The ''image()'' function takes on the directionality of the used ''&lt;image-decl>'', if any. If a directional image is used on or in an element with opposite <a href="http://www.w3.org/TR/CSS21/visuren.html#propdef-direction">direction</a>, the image must be flipped in the inline direction (as if it was transformed by, e.g., <code>scaleX(-1)</code>, if the inline direction is the X axis).</p>
<div class='example'>
<p>A list may use an arrow for a bullet that points into the content. If the list can contain both LTR and RTL text, though, the bullet may be on the left or the right, and an image designed to point into the text on one side will point out of the text on the other side. This can be fixed with code like:</p>
<pre>
&lt;ul style="list-style-image: image("arrow.png" ltr);">
&lt;li dir='ltr'>My bullet is on the left!&lt;/li>
&lt;li dir='rtl'>MY BULLET IS ON THE RIGHT!&lt;/li>
&lt;/ul></pre>
<p>This should render something like:</p>
<pre>
&#8658; My bullet is on the left!
!THGIR EHT NO SI TELLUB YM &#8656;</pre>
<p>In LTR list items, the image will be used as-is. In the RTL list items, however, it will be flipped in the inline direction, so it still points into the content.</p>
</div>
-->
<!-- ====================================================================== -->
<!-- removed per WG decision
<h3 id='element-notation'>
Using Elements as Images: the ''element()'' notation</h3>
<p>The ''element()'' function allows an author to use an element in the document as an image. As the referenced element changes appearance, the image changes as well. This can be used, for example, to create live previews of the next/previous slide in a slideshow, or to reference a canvas element for a fancy generated gradient or even an animated background.</p>
<p class='note'>Note that the ''element()'' function only reproduces the <em>appearance</em> of the referenced element, not the actual content and its structure. Authors should only use this for decorative purposes, and must not use ''element()'' to reproduce an element with significant content across the page. Instead, just insert multiple copies of the element into the document.</p>
<p>The syntax for ''element()'' is:</p>
<pre class=prod><dfn id='element-reference-type'>&lt;element-reference></dfn> = element( &lt;id-selector> )</pre>
<p>where ''&lt;id-selector>'' is an ID selector [[!SELECT]].</p>
<p>The ''element()'' function references the element matched by its argument. If multiple elements are matched, the function references the first such element.</p>
<p>The image represented by the ''element()'' function can vary based on whether the element is visible in the document:</p>
<dl>
<dt>an <i title="element-not-rendered">element that is rendered</i> and is not a descendant of a replaced element</dt>
<dd>
<p>The function represents an image with its intrinsic size equal to the <dfn>decorated bounding box</dfn> of the referenced element:
<ul>
<li>for an element rendered using a CSS rendering model, the <i>decorated bounding box</i> is the smallest axis-aligned rectangle that contains the <a href="http://www.w3.org/TR/2011/CR-css3-background-20110215/#border-image-area">border image areas</a> of all the fragments of the principal box</li>
<li>for an element rendered using the SVG rendering model, <a href="http://www.w3.org/TR/SVGTiny12/intro.html#TermDecoratedBoundingBox">the decorated bounding box is defined by SVG</a></li>
</ul>
<p class=note>Note: Because images clip anything outside their bounds by default, this means that decorations that extend outside the <i>decorated bounding box</i>, like box shadows, may be clipped.</p>
<p>The image is constructed by rendering the referenced element and its descendants (at the same size that they would be in the document) over an infinite ''transparent'' canvas, positioned so that the edges of the <i>decorated bounding box</i> are flush with the edges of the image.</p>
<p>If the referenced element has a transform applied to it or an ancestor, the transform must be ignored when rendering the element as an image. [[!CSS-TRANSFORMS]]</p>
<p>If the referenced element is broken across pages, the element is displayed as if the page content areas were joined flush in the pagination direction, with pages' edges corresponding to the initial containing block's start edge aligned. <span class='note'>Elements broken across lines or columns are just rendered with their <i>decorated bounding box</i>.</span></p>
<p>Implementations may either re-use existing bitmap data generated for the referenced element or regenerate the display of the element to maximize quality at the image's size (for example, if the implementation detects that the referenced element is an SVG fragment); in the latter case, the layout of the referenced element in the image must not be changed by the regeneration process. That is, the image must look identical to the referenced element, modulo rasterization quality.</p>
<div class='example'>
<p>As a somewhat silly example, a <code>&lt;p></code> element can be reused as a background elsewhere in the document:</p>
<pre>
&lt;style>
#src { color: white; background: lime; width: 300px; height: 40px; }
#dst { color: black; background: element(#src); padding: 20px; margin: 20px 0; }
&lt;/style>
&lt;p id='src'>I'm an ordinary element!&lt;/p>
&lt;p id='dst'>I'm using the previous element as my background!&lt;/p></pre>
<img src="element-function.png" alt="">
</div>
</dd>
<dt>an <i title='element-not-rendered'>element that is not rendered</i>, but which <i title='paint-source'>provides a paint source</i></dt>
<dd>
<p>The function represents an image with the intrinsic size and appearance of the <i title=paint-source>paint source</i>. The host language defines the size and appearance of paint sources.</p>
<div class='example'>
<p>For example, the ''element()'' function can reference an SVG <code>&lt;pattern></code> element in an HTML document:</p>
<pre>
&lt;!DOCTYPE html>
&lt;svg>
&lt;defs>
&lt;pattern id='pattern1'>
&lt;path d='...'>
&lt;/pattern>
&lt;/defs>
&lt;/svg>
&lt;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!
&lt;/p></pre>
<p>HTML also defines that a handful of elements, such as <code>&lt;canvas></code>, <code>&lt;img></code>, and <code>&lt;video></code>, provide a paint source. This means that CSS can, for example, reference a canvas that's being drawn into, but not displayed in the page:</p>
<pre>
&lt;!DOCTYPE html>
&lt;script>
var canvas = document.querySelector('#animated-bullet');
canvas.width = 20; canvas.height = 20;
drawAnimation(canvas);
&lt;/script>
&lt;canvas id='animated-bullet' style='display:none'>&lt;/canvas>
&lt;ul style="list-style-image: element(#animated-bullet);">
&lt;li>I'm using the canvas as a bullet!&lt;/li>
&lt;li>So am I!&lt;/li>
&lt;li>As the canvas is changed over time with Javascript,
we'll all update our bullet image with it!&lt;/li>
&lt;/ul></pre>
</div>
</dd>
<dt>anything else</dt>
<dd>
<p>The function represents an <i>invalid image</i>.</p>
<div class='example'>
<p>For example, all of the following ''element()'' uses will result in a transparent background:</p>
<pre>
&lt;!DOCTYPE html>
&lt;p id='one' style="display:none;">one&lt;/p>
&lt;iframe src="http://example.com">
&lt;p id='two'>I'm fallback content!&lt;/p>
&lt;/iframe>
&lt;ul>
&lt;li style="background: element(#one);">
A display:none element isn't rendered, and a P element
doesn't provide a paint source.
&lt;/li>
&lt;li style="background: element(#two);">
The descendants of a replaced element like an IFRAME
can't be used in element() either.
&lt;/li>
&lt;li style="background: element(#three);">
There's no element with an id of "three", so this also
gets rendered as a transparent image.
&lt;/li>
&lt;/ul></pre>
</div>
</dd>
</dl>
<p>An element is <dfn id='element-not-rendered' title='element-not-rendered'>not rendered</dfn> if it does not have an associated box. This can happen, for example, if the element or an ancestor is ''display:none''. Host languages may define additional ways in which an element can be considered not rendered; for example, in SVG, any descendant of a <code>&lt;defs></code> element is considered to be not rendered.</p>
<div class='example'>
<p>The ''element()'' function can be put to many uses. For example, it can be used to show a preview of the previous or next slide in a slideshow:</p>
<pre>
&lt;!DOCTYPE html>
&lt;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';
}
&lt;/script>
&lt;style>
#prev-preview, #next-preview {
position: fixed;
...
}
#prev-preview { background: element(#prev-slide); }
#next-preview { background: element(#next-slide); }
&lt;/style>
&lt;a id='prev-preview'>Previous Slide&lt;/a>
&lt;a id='next-preview'>Next Slide&lt;/a>
&lt;section class='slide'>...&lt;/section>
&lt;section class='slide current-slide'>...&lt;/section>
...</pre>
<p>In this example, the <code>navigateSlides</code> function updates the ids of the next and previous slides, which are then displayed in small floating boxes alongside the slides. Since you can't interact with the slides through the ''element()'' function (it's just an image), you could even use <code>click</code> handlers on the preview boxes to help navigate through the page.
</div>
<h4 id='paint-sources'>
Paint Sources</h4>
<p>Host languages may define that some elements provide a <dfn title="paint-source">paint source</dfn>. Paint sources have an intrinsic width, height, and appearance, separate from the process of rendering, and so may be used as images even when they're <i title='element-not-rendered'>not rendered</i>.</p>
<p>In HTML, the <code>&lt;img></code>, <code>&lt;video></code>, and <code>&lt;canvas></code> elements provide paint sources (defined in each element's section in <a href='http://www.whatwg.org/specs/web-apps/current-work/multipage/'>HTML5</a>).</p>
<p>In SVG, any element that provides a <a href='http://www.w3.org/TR/SVG/pservers.html'>paint server</a> provides a paint source. <span class='note'>Note: In SVG1.1, the <code>&lt;linearGradient></code>, <code>&lt;radialGradient></code>, and <code>&lt;pattern></code> elements provide paint sources.</span> They are drawn as described in the spec, with the coordinate systems defined as follows:</p>
<dl>
<dt>objectBoundingBox</dt>
<dd>The coordinate system has its origin at the top left corner of the rectangle defined by the <i>concrete object size</i> that it's being drawn into, and the same width and height as the <i>concrete object size</i>. A single <a href="http://www.w3.org/TR/SVG/coords.html#Units">user coordinate</a> is the width and height of the <i>concrete object size</i>.</dd>
<dt>userSpaceOnUse</dt>
<dd>The coordinate system has its origin at the top left corner of the rectangle defined by the <i>concrete object size</i> that it's being drawn into, and the same width and height as the <i>concrete object size</i>. <a href="http://www.w3.org/TR/SVG/coords.html#Units">User coordinates</a> are sized equivalently to the CSS ''px'' unit.</dd>
</dl>
<p class='note'>It is expected that a future version of this module will define ways to refer to paint sources in external documents, or ones that are created solely by script and never inserted into a document at all.</p>
<h4 id='element-cycles'>
Cycle Detection</h4>
<p>The ''element()'' function can produce nonsensical circular relationships,
such as an element using itself as its own background. These relationships
can be easily and reliably detected and resolved, however, by keeping
track of a dependency graph and using common cycle-detection algorithms.</p>
<p>The dependency graph consists of edges such that:</p>
<ul>
<li>every element depends on its children</li>
<li>for any element A with a property using the ''element()'' function pointing to an element B, A depends on B</li>
<li>if a host language defines a way for elements to refer to the rendering of other elements, the referencing element depends on the referenced element. For example, in SVG, a &lt;use> element depends on the element it referenced.</li>
</ul>
<p>If the graph contains a cycle, any ''element()'' functions participating in the cycle must represent a fully transparent image with no intrinsic dimensions.</p>
-->
<h2 id="gradients">
Gradients</h2>
<p>A gradient is an image that smoothly fades from one color to another. These
are commonly used for subtle shading in background images, buttons, and many
other things. The gradient notations described in this section allow an author to
specify such an image in a terse syntax, so that the UA can generate the image
automatically when rendering the page.
The syntax of a <i>&lt;gradient></i> is:</p>
<pre class=prod><dfn id='gradient-type'>&lt;gradient></dfn> = [
<i>&lt;linear-gradient></i> | <i>&lt;radial-gradient></i> |
<i>&lt;repeating-linear-gradient></i> | <i>&lt;repeating-radial-gradient></i> ]</pre>
<div class=example>
<p>As with the other <i>&lt;image></i> types defined in this specification,
gradients can be used in any property that accepts images. For example:</p>
<ul>
<li><code>background: linear-gradient(white, gray);</code></li>
<li><code>list-style-image: radial-gradient(circle, #006, #00a 90%, #0000af 100%, white 100%)</code></li>
</ul>
</div>
<p>A gradient is drawn into a box with the dimensions of the <i>concrete
object size</i>, referred to as the <dfn>gradient box</dfn>. However, the gradient itself has no <i>intrinsic dimensions</i>.</p>
<div class='example'>
<p>For example, if you use a gradient as a background, by default the gradient will draw into a <i>gradient box</i> the size of the element's padding box. If 'background-size' is explicitly set to a value such as ''100px 200px'', then the <i>gradient box</i> 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 <i>default object size</i> for that property.</p>
</div>
<!-- ====================================================================== -->
<h3 id='linear-gradients'>
Linear Gradients: the ''linear-gradient()'' notation</h3>
<p>A linear gradient is created by specifying a gradient line and then several
colors placed along that line. The image is constructed by creating an
infinite canvas and painting it with lines perpendicular to the gradient line,
with the color of the painted line being the color of the gradient line
where the two intersect. This produces a smooth fade from each color to
the next, progressing in the specified direction.</p>
<!-- ====================================================================== -->
<h4 class='no-toc' id='linear-gradient-syntax'>
linear-gradient() syntax</h4>
<p>The linear gradient syntax is:</p>
<pre class=prod><code>
<dfn id='linear-gradient-type'>&lt;linear-gradient></dfn> = linear-gradient(
[ [ &lt;angle> | to &lt;side-or-corner> ] ,]?
&lt;color-stop>[, &lt;color-stop>]+
)
<dfn id='side-or-corner'>&lt;side-or-corner></dfn> = [left | right] || [top | bottom]</code></pre>
<p>The first argument to the function specifies the <dfn>gradient line</dfn>,
which gives the gradient a direction and determines how color-stops are
positioned. It may be omitted; if so, it defaults to ''to bottom''.</p>
<p>The <i title="gradient line">gradient line's</i> direction may be specified in two ways:</p>
<dl>
<dt>using angles</dt>
<dd>For the purpose of this argument, ''0deg'' points upward, and positive angles represent clockwise rotation, so ''90deg'' point toward the right.</dd>
<dt>using keywords</dt>
<dd>
<p>If the argument is ''to top'', ''to right'', ''to bottom'', or ''to left'', the angle of the <i>gradient line</i> is ''0deg'', ''90deg'', ''180deg'', or ''270deg'', respectively.</p>
<p>If the argument instead specifies a corner of the box such as ''to top left'', the gradient line must be angled such that it points into the same quadrant as the specified corner, and a line drawn perpendicular to the <i>gradient line</i> through the center of the <i>gradient box</i> intersects the two neighboring corners.</p>
</dd>
</dl>
<p>Starting from the center of the <i>gradient box</i>, extend a line at the specified angle in both directions. The ending point is the point on the <i>gradient line</i> where a line drawn perpendicular to the <i>gradient line</i> would intersect the corner of the <i>gradient box</i> in the specified direction. The starting point is determined identically, but in the opposite direction.</p>
<p class='note'>It is expected that the next level of this module will provide the ability to define the gradient's direction relative to the current text direction and writing-mode.</p>
<div class=example>
<div style="overflow: hidden">
<img style="float: right; margin-left: 1em;" src='gradient-diagram.png' alt="[An image showing a box with a background shading gradually from white in the bottom-left corner to black in the top-right corner. There is a line, illustrating the gradient line, angled at 45 degrees and passing through the center of the box. The starting point and ending point of the gradient line are indicated by the intersection of the gradient line with two additional lines that pass through the bottom-left and top-right corners of the box.]">
<p>This example illustrates visually how to calculate the
<i>gradient line</i> from the rules above. This shows the starting
and ending point of the <i>gradient line</i>, along with the actual
gradient, produced by an element with
''background: linear-gradient(45deg, white, black);''.</p>
<p>Notice how, though the starting point and ending point are outside
of the box, they're positioned precisely right so that the gradient
is pure white <em>exactly</em> at the corner, and pure black
<em>exactly</em> at the opposite corner. That's intentional, and
will always be true for linear gradients.</p>
</div>
</div>
<p>The gradient's color stops are typically placed between the starting point
and ending point on the <i>gradient line</i>, but this isn't required - the
<i>gradient line</i> extends infinitely in both directions. The starting point
and ending point are merely arbitrary location markers - the starting point
defines where 0%, 0px, etc are located when specifying color-stops, and
the ending point defines where 100% is located. Color-stops are allowed
to have positions before 0% or after 100%.</p>
<p>The color of the gradient at any point is determined by finding the unique line passing through that point that is perpendicular to the <i>gradient line</i>. The point's color is the color of the <i>gradient line</i> at the point where this line intersects it.</p>
<!-- ====================================================================== -->
<h4 class='no-toc' id='linear-gradient-examples'>
Linear Gradient Examples</h4>
<p>All of the following ''linear-gradient()'' examples are presumed to be
backgrounds applied to a box that is 200px wide and 100px tall.</p>
<div class=example>
<p>Below are various ways of specifying a basic vertical gradient:</p>
<pre><code>linear-gradient(yellow, blue);
linear-gradient(to bottom, yellow, blue);
linear-gradient(180deg, yellow, blue);
linear-gradient(to top, blue, yellow);
linear-gradient(to bottom, yellow 0%, blue 100%);</code></pre>
<p><img src="linear1.png" alt="" ></p>
</div>
<div class=example>
<p>This demonstrates the use of an angle in the gradient. Note that, though the angle is not exactly the same as the angle between the corners, the <i>gradient line</i> is still sized so as to make the gradient yellow exactly at the upper-left corner, and blue exactly at the lower-right corner.</p>
<pre><code>linear-gradient(135deg, yellow, blue);
linear-gradient(-45deg, blue, yellow);</code></pre>
<p><img src="linear3.png" alt="" ></p>
</div>
<div class=example>
<p>This demonstrates a 3-color gradient, and how to specify the location of a stop explicitly:</p>
<pre><code>linear-gradient(yellow, blue 20%, #0f0);</code></pre>
<p><img src="linear4.png" alt="" ></p>
</div>
<div class=example>
<p>This demonstrates* a corner-to-corner gradient specified with keywords. Note how the gradient is red and blue exactly in the bottom-left and top-right corners, respectively, exactly like the second example. Additionally, the angle of the gradient is automatically computed so that the color at 50% (in this case, white) stretches across the top-left and bottom-right corners.</p>
<pre><code>linear-gradient(to top right, red, white, blue)</code></pre>
<p><object data="gradient1.svg" width="200"
height="100">(Image requires SVG)</object></p>
<p><small>* SVG-in-HTML support required to view the image.</small></p>
</div>
<!-- ====================================================================== -->
<h3 id='radial-gradients'>
Radial Gradients: the ''radial-gradient()'' notation</h3>
<p>In a radial gradient, rather than colors smoothly fading from one side
of the <i>gradient box</i> to the other as with linear gradients, they instead emerge from
a single point and smoothly spread outward in a circular or elliptical shape.</p>
<p>A radial gradient is specified by indicating the center of the gradient (where the 0% ellipse will be) and the size and shape of the <dfn>ending shape</dfn> (the 100% ellipse). Color stops are given as a list, just as for ''linear-gradient()''. Starting from the <i>center</i> and progressing towards (and potentially beyond) the <i>ending shape</i> uniformly-scaled concentric ellipses are drawn and colored according to the specified color stops.</p>
<!-- ====================================================================== -->
<h4 class='no-toc' id='radial-gradient-syntax'>
radial-gradient() Syntax</h4>
<p>The radial gradient syntax is:
<pre>
<dfn id='radial-gradient-type'>&lt;radial-gradient></dfn> = radial-gradient(
[ [ &lt;shape> || &lt;size> ] [ at &lt;position> ]? , |
at &lt;position>,
]?
&lt;color-stop> [ , &lt;color-stop> ]+
)</pre>
<div class=example>
<p>Here is an example of a circular radial gradient 5em wide and
positioned with its center in the top left corner:
<pre>radial-gradient(5em circle at top left, yellow, blue)</pre>
</div>
<p>The arguments are defined as follows:
<dl>
<dt id='radial-position'><dfn id='position'>&lt;position></dfn></dt>
<dd>Determines the center of the gradient. The <a href="http://www.w3.org/TR/css3-values/#position">&lt;position></a> 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 <i>gradient box</i> as the positioning area. If this argument is omitted, it defaults to ''center''.
<dt id='radial-shape'><dfn id='shape'>&lt;shape></dfn></dt>
<dd>Can be either ''circle'' or ''ellipse''; determines whether the
gradient's <i>ending shape</i> is a circle or an ellipse, respectively.
If <i>&lt;shape></i> is omitted, the <i>ending shape</i> defaults
to a circle if the <i>&lt;size></i> is a single &lt;length>,
and to an ellipse otherwise.
<dt id='radial-size'><dfn id='size'>&lt;size></dfn>
<dd>
<p>Determines the size of the gradient's <i>ending shape</i>. If
omitted it defaults to ''farthest-corner''. It can be given explicitly or
by keyword. For the purpose of the keyword definitions, consider the
<i>gradient box</i> edges as extending infinitely in both directions, rather than
being finite line segments.
<p>If the ending-shape is an ellipse, its axises are aligned with the horizontal and vertical axises.</p>
<p>Both ''circle'' and ''ellipse'' gradients accept the following keywords
as their <i>&lt;size></i>:
<dl>
<dt><dfn id='radial-closest-side'>''closest-side''</dfn></dt>
<dd>The <i>ending shape</i> is sized so that that it exactly meets the
side of the <i>gradient box</i> closest to the gradient's center. If the shape is an
ellipse, it exactly meets the closest side in each dimension.</dd>
<dt><dfn id='radial-farthest-side'>''farthest-side''</dfn></dt>
<dd>Same as ''closest-side'', except the <i>ending shape</i> is sized
based on the farthest side(s).</dd>
<dt><dfn id='radial-closest-corner'>''closest-corner''</dfn></dt>
<dd>The <i>ending shape</i> is sized so that that it passes through the
corner of the <i>gradient box</i> closest to the gradient's center. If the shape is an
ellipse, the <i>ending shape</i> is given the same aspect-ratio
it would have if ''closest-side'' were specified.
<dt><dfn id='radial-farthest-corner'>''farthest-corner''</dfn></dt>
<dd>Same as ''closest-corner'', except the <i>ending shape</i> is
sized based on the farthest corner. If the shape is an ellipse,
the <i>ending shape</i> is given the same aspect ratio it would
have if ''farthest-side'' were specified.
</dl>
<p>If <i>&lt;shape></i> is specified as ''circle'' or is omitted, the
<i>&lt;size></i> may be given explicitly as:
<dl>
<dt><dfn id='radial-size-circle'>&lt;length></dfn></dt>
<dd>
<p>Gives the radius of the circle explicitly. Negative values are
invalid.</p>
<p class='note'>Note that percentages are <em>not</em> allowed here; they can only be used to specify the size of an elliptical gradient, not a circular one. This restriction exists because there is are multiple reasonable answers as to which dimension the percentage should be relative to. A future level of this module may provide the ability to size circles with percentages, perhaps with more explicit controls over which dimension is used.</p>
</dd>
</dl>
<p>If <i>&lt;shape></i> is specified as ''ellipse'' or is omitted,
<i>&lt;size></i> may instead be given explicitly as:
<dl>
<dt><dfn id='radial-size-ellipse'>[&lt;length> | &lt;percentage>]{2}</dfn></dt>
<dd>Gives the size of the ellipse explicitly. The first value represents
the horizontal radius, the second the vertical radius. Percentages
values are relative to the corresponding dimension of the <i>gradient box</i>.
Negative values are invalid.
</dl>
</dd>
</dl>
<div class='note'>
<p>Expanded with the above definitions, the grammar becomes:
<pre>
&lt;radial-gradient> = radial-gradient(
[ [ circle || &lt;length> ] [ at &lt;position> ]? , |
[ ellipse || [ &lt;length> | &lt;percentage> ]{2} ] [ at &lt;position> ]? , |
[ [ circle | ellipse ] || &lt;extent-keyword> ] [ at &lt;position> ]? , |
at &lt;position> ,
]?
&lt;color-stop> [ , &lt;color-stop> ]+
)
&lt;extent-keyword> = closest-corner | closest-side | farthest-corner | farthest-side</pre>
</div>
<h4 class="no-toc" id="radial-color-stops">
Placing Color Stops</h4>
<p>Color-stops are placed on a <dfn>gradient ray</dfn>, similar to the <i>gradient line</i> of linear gradients. The <i>gradient ray</i> is anchored at the center of the gradient and extends toward the right. The 0% location is at the start of the <i>gradient ray</i>, and the 100% location is on the point where the <i>gradient ray</i> intersects the <i>ending shape</i>. A color-stop can be placed at a negative location; though the negative region of the <i>gradient ray</i> is never directly consulted for rendering, color stops placed there can affect the color of non-negative locations on the <i>gradient ray</i> through interpolation or repetition (see <a href='#repeating-gradients'>repeating gradients</a>). For example, ''radial-gradient(red -50px, yellow 100px)'' produces an elliptical gradient that starts with a reddish-orange color in the center (specifically, #f50) and transitions to yellow. Locations greater than 100% simply specify a location a correspondingly greater distance from the center of the gradient.</p>
<p>The color of the gradient at any point is determined by first finding the unique ellipse passing through that point with the same center, orientation, and ratio between major and minor axises as the ending-shape. The point's color is then the color of the <i>gradient ray</i> at the location where this ellipse intersects it.</p>
<h4 class="no-toc" id="degenerate-radials">
Degenerate Radial Gradients</h4>
<p>Some combinations of position, size, and shape will produce a circle
or ellipse with a radius of 0. This will occur, for example, if the
center is on a <i>gradient box</i> edge and ''closest-side'' or ''closest-corner'' is
specified or if the size and shape are given explicitly and either of
the radiuses is zero. In these degenerate cases, the gradient must be
be rendered as follows:</p>
<dl>
<dt>If the <i>ending shape</i> is a circle with zero radius:</dt>
<dd>Render as if the <i>ending shape</i> was a circle whose radius was an arbitrary very small number greater than zero. <span class='note'>This will make the gradient continue to look like a circle.</span></dd>
<dt>If the <i>ending shape</i> has zero width (regardless of the height):</dt>
<dd>Render as if the <i>ending shape</i> was an ellipse whose height was an arbitrary very large number and whose width was an arbitrary very small number greater than zero. <span class='note'>This will make the gradient look similar to a horizontal linear gradient that is mirrored across the center of the ellipse. It also means that all color-stop positions specified with a percentage resolve to ''0px''.</span></dd>
<dt>Otherwise, if the <i>ending shape</i> has zero height:</dt>
<dd>Render as if the <i>ending shape</i> was an ellipse whose width was an arbitrary very large number and whose height was an arbitrary very small number greater than zero. <span class='note'>This will make the gradient look like a solid-color image equal to the color of the last color-stop, or equal to the average color of the gradient if it's repeating.</span></dd>
</dl>
<!-- ====================================================================== -->
<h4 class='no-toc' id='radial-gradient-examples'>
Radial Gradient Examples</h4>
<p>All of the following examples are applied to a box that is 200px wide
and 100px tall.</p>
<div class=example>
<p>These examples demonstrate different ways to write the basic syntax for radial gradients:</p>
<pre><code>radial-gradient(yellow, green);
radial-gradient(ellipse at center, yellow 0%, green 100%);
radial-gradient(farthest-corner at 50% 50%, yellow, green);</code></pre>
<p><img src="radial1.png" alt="" ></p>
<pre><code>radial-gradient(circle, yellow, green);</code></pre>
<p><img src="radial2.png" alt="" ></p>
<pre><code>radial-gradient(red, yellow, green);</code></pre>
<p><img src="radial3.png" alt="" ></p>
</div>
<div class=example>
<p>This image shows a gradient originating from somewhere other than the center of the box:</p>
<pre><code>radial-gradient(farthest-side at left bottom, red, yellow 50px, green);</code></pre>
<p><img src="radial4.png" alt="" ></p>
</div>
<div class=example>
<p>Here we illustrate a 'closest-side' gradient.</p>
<pre><code>radial-gradient(closest-side at 20px 30px, red, yellow, green);
radial-gradient(20px 30px at 20px 30px, red, yellow, green);</code></pre>
<p><img src="radial6.png" alt="" ></p>
<pre><code>radial-gradient(closest-side circle at 20px 30px, red, yellow, green);
radial-gradient(20px 20px at 20px 30px, red, yellow, green);</code></pre>
<p><img src="radial7.png" alt="" ></p>
</div>
<!-- ====================================================================== -->
<h3 id='repeating-gradients'>
Repeating Gradients: the ''repeating-linear-gradient()'' and ''repeating-radial-gradient()'' notations</h3>
<p>In addition to <i>&lt;linear-gradient></i> and <i>&lt;radial-gradient></i>,
this specification defines <dfn id='repeating-linear-gradient-type'>&lt;repeating-linear-gradient></dfn> and
<dfn id='repeating-radial-gradient-type'>&lt;repeating-radial-gradient></dfn> values. These two notations take the
same values and are interpreted the same as their respective non-repeating
siblings defined previously.</p>
<p>When rendered, however, the color-stops are repeated infinitely in both
directions, with their positions shifted by multiples of the difference
between the last specified color-stop's position and the first specified
color-stop's position. For example, ''repeating-linear-gradient(red 10px, blue 50px)''
is equivalent to ''linear-gradient(..., red -30px, blue 10px, red 10px, blue 50px, red 50px, blue 90px, ...)''.
Note that the last color-stop and first color-stop will always coincide at
the boundaries of each group, which will produce sharp transitions if the
gradient does not start and end with the same color.</p>
<div class=example>
<p>Repeating gradient syntax is basically identical to that of non-repeating gradients:</p>
<pre><code>repeating-linear-gradient(red, blue 20px, red 40px)</code></pre>
<p><img src="repeating1.png" alt=""></p>
<pre><code>repeating-radial-gradient(red, blue 20px, red 40p 2334 x)</code></pre>
<p><img src="repeating2.png" alt=""></p>
<pre><code>repeating-radial-gradient(circle closest-side at 20px 30px, red, yellow, green 100%, yellow 150%, red 200%)</code></pre>
<p><img src="repeating3.png" alt=""></p>
</div>
<p>If the distance between the first and last color-stops is non-zero, but is small enough that the implementation knows that the physical resolution of the output device is insufficient to faithfully render the gradient, the implementation must <i title="gradient-average-color">find the average color of the gradient</i> and render the gradient as a solid-color image equal to the average color.</p>
<p>If the distance between the first and last color-stops is zero (or rounds to zero due to implementation limitations), the implementation must <i title="gradient-average-color">find the average color of a gradient</i> with the same number and color of color-stops, but with the first and last color-stop an arbitrary non-zero distance apart, and the remaining color-stops equally spaced between them. Then it must render the gradient as a solid-color image equal to that average color.</p>
<p>If the height of a repeating radial gradient is zero, or is close enough to zero that the implementation knows that the physical resolution of the output device is insufficient to faithfully render the gradient, the implementation must <i title="gradient-average-color">find the average color of the gradient</i> and render the gradient as a solid-color image equal to the average color.</p>
<p>To <dfn title="gradient-average-color">find the average color of a gradient</dfn>, run these steps:</p>
<ol>
<li>Define <var>list</var> as an initially-empty list of premultiplied RGBA colors, and <var>total-length</var> as the distance between first and last color stops.</li>
<li>For each adjacent pair of color-stops, define <var>weight</var> as half the distance between the two color-stops, divided by <var>total-length</var>. Add two entries to <var>list</var>, the first obtained by representing the color of the first color-stop in premultiplied sRGBA and scaling all of the components by <var>weight</var>, and the second obtained in the same way with the second color-stop.</li>
<li>Sum the entries of <var>list</var> component-wise to produce the average color, and return it.</li>
</ol>
<p class='note'>As usual, implementations may use whatever algorithm they wish, so long as it produces the same result as the above.</p>
<div class='example'>
<p>For example, the following gradient is rendered as a solid light-purple image (equal to <code>rgb(75%,50%,75%)</code>):</p>
<pre class="css">repeating-linear-gradient(red 0px, white 0px, blue 0px);</pre>
<p>The following gradient would render the same as the previous under normal circumstances (because desktop monitors can't faithfully render color-stops 1/10th of a pixel apart), but would render as a normal repeating gradient if, for example, the author applied "zoom:100;" to the element on which the gradient appears:</p>
<pre class="css">repeating-linear-gradient(red 0px, white .1px, blue .2px);</pre>
</div>
<!-- ====================================================================== -->
<h3 id='color-stop-syntax'>
Gradient Color-Stops</h3>
<pre class=prod><code><dfn id='color-stop-type'>&lt;color-stop></dfn> = &lt;color> [ &lt;percentage> | &lt;length> ]?</code></pre>
<p>Color-stops are points placed along the line defined by the <i>gradient line</i>
at the beginning of the rule. Color-stops must be specified in order.
Percentages refer to the length of the gradient line, with 0% being at the
starting point and 100% being at the ending point. Lengths are measured
from the starting point in the direction of the ending point. Color-stops
are usually placed between the starting point and ending point, but that's
not required; the gradient line extends infinitely in both directions, and
a color-stop can be placed at any position on the line.</p>
<p>At each color-stop, the line is the color of the color-stop. Between
two color-stops, the line's color is linearly interpolated between the colors
of the two color-stops, with the interpolation taking place in premultiplied
RGBA space. Before the first color-stop, the line is the color of the first
color-stop. After the last color-stop, the line is the color of the last
color-stop.</p>
<p>The following steps must be applied <em>in order</em> to process the list
of color-stops. After applying these rules, all color-stops will have a
definite position and they will be in ascending order:</p>
<ol>
<li>If the first color-stop does not have a position, set its position to 0%. If the last color-stop does not have a position, set its position to 100%.</li>
<li>If a color-stop has a position that is less than the specified position of any color-stop before it in the list, set its position to be equal to the largest specified position of any color-stop before it.</li>
<li>If any color-stop still does not have a position, then, for each run of adjacent color-stops without positions, set their positions so that they are evenly spaced between the preceding and following color-stops with positions.</li>
</ol>
<p>If multiple color-stops have the same position, they produce an infinitesimal
transition from the one specified first in the rule to the one specified
last. In effect, the color suddenly changes at that position rather than
smoothly transitioning.</p>
<div class=example>
<p>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></p>
<pre><code>
1. linear-gradient(red, white 20%, blue)
=1=>
linear-gradient(red 0%, white 20%, blue 100%)
2. linear-gradient(red 40%, white, black, blue)
=13=>
linear-gradient(red 40%, white 60%, black 80%, blue 100%)
3. linear-gradient(red -50%, white, blue)
=13=>
linear-gradient(red -50%, white 25%, blue 100%)
4. linear-gradient(red -50px, white, blue)
=13=>
linear-gradient(red -50px, white calc(-25px + 50%), blue 100%)
5. linear-gradient(red 20px, white 0px, blue 40px)
=2=>
linear-gradient(red 20px, white 20px, blue 40px)
6. linear-gradient(red, white -50%, black 150%, blue)
=12=>