FFFF csswg-drafts/css-images/Overview.html at c6bad5230a78d579e62ef7bda3f74bb337c22850 · w3c/csswg-drafts · GitHub
Skip to content

Latest commit

 

History

History
3076 lines (2467 loc) · 224 KB

File metadata and controls

3076 lines (2467 loc) · 224 KB
<!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>
</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=http://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 heading" id=subtitle><span class=content>Editor’s Draft,
<span class=dt-updated><span class=value-title title=20140430>30 April 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>Editor’s Draft:<dd><a href=http://dev.w3.org/csswg/css-images-4/>http://dev.w3.org/csswg/css-images-4/</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>Fe 28B edback:</dt>
<dd><a href="mailto:www-style@w3.org?subject=%5Bcss-images%5D%20feedback">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>)<dt>Test Suite:<dd>None Yet<dt>Editors:
<dd 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>)<dd 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>)<dt>Issue Tracking:<dd><a href=http://www.w3.org/Style/CSS/Tracker/products/27>http://www.w3.org/Style/CSS/Tracker/products/27</a></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 heading" id=abstract><span class=content>Abstract</span></h2>
<p class=p-summary data-fill-with=abstract>This module contains the features of CSS level 4 relating to the <a class="production css-code" data-link-type=type href=#typedef-image title="<image>">&lt;image&gt;</a> type and replaced elements. It includes and extends the functionality of CSS Image Values and Replaced Content Module Level 3. The main extensions compared to level 3 are several additions to the <a class="production css-code" data-link-type=type href=#typedef-image title="<image>">&lt;image&gt;</a> type, additions to the <a class="production css-code" data-link-type=type href=#typedef-gradient title="<gradient>">&lt;gradient&gt;</a> type, extentions to the <a class=css data-link-type=maybe href=#funcdef-image title=image()>image()</a> function, definitions for interpolating several <a class="production css-code" data-link-type=type href=#typedef-image title="<image>">&lt;image&gt;</a> types, and several properties controlling the interaction of replaced elements and CSS’s layout models.
<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.</p>
<h2 class="no-num no-toc no-ref heading settled heading" 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 heading" id=contents><span class=content>Table of Contents</span></h2>
<div data-fill-with=table-of-contents><ul class=toc>
<li><a href=#intro><span class=secno>1</span> Introduction</a>
<ul class=toc>
<li><a href=#placement><span class=secno>1.1</span> Module Interactions</a>
<li><a href=#values><span class=secno>1.2</span> Values</a></ul>
<li><a href=#planned-features><span class=secno>2</span> Planned Features</a>
<li><a href=#image-values><span class=secno>3</span> Image Values: the <span class=production data-link-type=type title="<image>">&lt;image&gt;</span> type</a>
<ul class=toc>
<li><a href=#url-notation><span class=secno>3.1</span> Image References and Image Slices: the <span class=production data-link-type=type title="<url>">&lt;url&gt;</span> type and <span class=css data-link-type=maybe title=url()>url()</span> notation</a>
<li><a href=#image-notation><span class=secno>3.2</span> Image Fallbacks and Annotations: the <span class=css data-link-type=maybe title=image()>image()</span> notation</a>
<ul class=toc>
<li><a href=#image-fragments><span class=secno>3.2.1</span> Image Fragments</a>
<li><a href=#image-fallbacks><span class=secno>3.2.2</span> Image Fallbacks</a>
<li><a href=#color-images><span class=secno>3.2.3</span> Solid-color Images</a>
<li><a href=#bidi-images><span class=secno>3.2.4</span> Bidi-sensitive Images</a></ul>
<li><a href=#image-set-notation><span class=secno>3.3</span> Resolution Negotiation: the <span class=css data-link-type=maybe title=image-set()>image-set()</span> notation</a>
<li><a href=#element-notation><span class=secno>3.4</span> Using Elements as Images: the <span class=css data-link-type=maybe title=element()>element()</span> notation</a>
<ul class=toc>
<li><a href=#paint-sources><span class=secno>3.4.1</span> Paint Sources</a>
<li><a href=#elementsources><span class=secno>3.4.2</span> Using Out-Of-Document Sources: the <code>ElementSources</code> interface</a>
<li><a href=#element-cycles><span class=secno>3.4.3</span> Cycle Detection</a></ul>
<li><a href=#cross-fade-function><span class=secno>3.5</span> Combining images: the <span class=css data-link-type=maybe title=cross-fade()>cross-fade()</span> notation</a></ul>
<li><a href=#gradients><span class=secno>4</span> Gradients</a>
<ul class=toc>
<li><a href=#linear-gradients><span class=secno>4.1</span> Linear Gradients: the <span class=css data-link-type=maybe title=linear-gradient()>linear-gradient()</span> notation</a>
<li><a href=#radial-gradients><span class=secno>4.2</span> Radial Gradients: the <span class=css data-link-type=maybe title=radial-gradient()>radial-gradient()</span> notation</a>
<li><a href=#conic-gradients><span class=secno>4.3</span> Conic Gradients: the <span class=css data-link-type=maybe title=conic-gradient()>conic-gradient()</span> notation</a>
<li><a href=#repeating-gradients><span class=secno>4.4</span> 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</a>
<li><a href=#color-stop-syntax><span class=secno>4.5</span> Gradient Color-Stops</a></ul>
<li><a href=#sizing><span class=secno>5</span> Sizing Images and Objects in CSS</a>
<ul class=toc>
<li><a href=#sizing-terms><span class=secno>5.1</span> Object-Sizing Terminology</a>
<li><a href=#object-negotiation><span class=secno>5.2</span> CSS⇋Object Negotiation</a>
<li><a href=#concrete-size-resolution><span class=secno>5.3</span> Concrete Object Size Resolution</a>
<ul class=toc>
<li><a href=#default-sizing><span class=secno>5.3.1</span> Default Sizing Algorithm</a>
<li><a href=#cover-contain><span class=secno>5.3.2</span> Cover and Contain Constraint Sizing</a></ul>
<li><a href=#object-sizing-examples><span class=secno>5.4</span> Examples of CSS Object Sizing</a>
<li><a href=#the-object-fit><span class=secno>5.5</span> Sizing Objects: the <span class=property data-link-type=propdesc title=object-fit>object-fit</span> property</a>
<li><a href=#the-object-position><span class=secno>5.6</span> Positioning Objects: the <span class=property data-link-type=propdesc title=object-position>object-position</span> property</a></ul>
<li><a href=#image-processing><span class=secno>6</span> Image Processing</a>
<ul class=toc>
<li><a href=#the-image-resolution><span class=secno>6.1</span> Overriding Image Resolutions: the <span class=property data-link-type=propdesc title=image-resolution>image-resolution</span> property</a>
<li><a href=#the-image-orientation><span class=secno>6.2</span> Orienting an Image on the Page: the <span class=property data-link-type=propdesc title=image-orientation>image-orientation</span> property</a>
<li><a href=#the-image-rendering><span class=secno>6.3</span> Determing How To Scale an Image: the <span class=property data-link-type=propdesc title=image-rendering>image-rendering</span> property</a></ul>
<li><a href=#interpolation><span class=secno>7</span> Interpolation</a>
<ul class=toc>
<li><a href=#interpolating-images><span class=secno>7.1</span> Interpolating <span class=production data-link-type=type title="<image>">&lt;image&gt;</span></a>
<li><a href=#interpolating-image-combinations><span class=secno>7.2</span> Interpolating cross-fade()</a>
<li><a href=#interpolating-gradients><span class=secno>7.3</span> Interpolating <span class=production data-link-type=type title="<gradient>">&lt;gradient&gt;</span></a></ul>
<li><a href=#serialization><span class=secno>8</span> Serialization</a>
<li><a href=#changes><span class=secno>9</span> Changes since Images 3</a>
<li><a href=#conformance><span class=secno></span> Conformance</a>
<ul class=toc>
<li><a href=#conventions><span class=secno></span> Document conventions</a>
<li><a href=#conformance-classes><span class=secno></span> Conformance classes</a>
<li><a href=#partial><span class=secno></span> Partial implementations</a>
<li><a href=#experimental><span class=secno></span> Experimental implementations</a>
<li><a href=#testing><span class=secno></span> Non-experimental implementations</a></ul>
<li><a href=#references><span class=secno></span> References</a>
<ul class=toc>
<li><a href=#normative><span class=secno></span> Normative References</a>
<li><a href=#informative><span class=secno></span> Informative References</a></ul>
<li><a href=#index><span class=secno></span> Index</a>
<li><a href=#property-index><span class=secno></span> Property index</a>
<li><a href=#issues-index><span class=secno></span>Issues Index</a></ul></div>
<h2 class="heading settled heading" data-level=1 id=intro><span class=secno>1 </span><span class=content>
Introduction</span><a class=self-link href=#intro></a></h2>
<p> <em>This section is not normative.</em>
<p> In CSS Levels 1 and 2,
image values, such as those used in the <a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css-backgrounds-3/#background-image title=background-image>background-image</a> 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-image-type>a reference to an element</a>,
or as <a href=#gradients>a gradient</a>.
<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 class="heading settled heading" data-level=1.1 id=placement><span class=secno>1.1 </span><span class=content>
Module Interactions</span><a class=self-link href=#placement></a></h3>
<p> This module defines and extends the <a class="production css-code" data-link-type=type href=#typedef-image title="<image>">&lt;image&gt;</a> value type defined in <a data-biblio-type=normative data-link-type=biblio href=#css3val title=css3val>[CSS3VAL]</a>.
Furthermore it replaces the <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/css-values-3/#url-value title="<url>">&lt;url&gt;</a> type
in the <a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css-backgrounds-3/#background-image title=background-image>background-image</a> and <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> definitions in CSS1 and CSS2
and adds <a class="production css-code" data-link-type=type href=#typedef-image title="<image>">&lt;image&gt;</a> as an alternative to <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/css-values-3/#url-value title="<url>">&lt;url&gt;</a> in the <a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css-content-3/#content title=content>content</a> property’s value.
It is presumed that CSS specifications beyond CSS2.1 will use the <a class="production css-code" data-link-type=type href=#typedef-image title="<image>">&lt;image&gt;</a> notation
in place of <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/css-values-3/#url-value title="<url>">&lt;url&gt;</a> where 2D images are expected. (See e.g. <a data-biblio-type=informative data-link-type=biblio href=#css3bg title=css3bg>[CSS3BG]</a>.)
<p> Of the properties defined in this module,
only <a class=property data-link-type=propdesc href=#propdef-image-resolution title=image-resolution>image-resolution</a>
applies to <code>::first-line</code> and <code>::first-letter</code>.
<h3 class="heading settled heading" data-level=1.2 id=values><span class=secno>1.2 </span><span class=content>
Values</span><a class=self-link href=#values></a></h3>
<p> This specification follows the <a href=http://www.w3.org/TR/CSS21/about.html#property-defs>CSS property definition conventions</a> from <a data-biblio-type=normative data-link-type=biblio href=#css21 title=css21>[CSS21]</a>.
Value types not defined in this specification
are defined in CSS Level 2 Revision 1 <a data-biblio-type=normative data-link-type=biblio href=#css21 title=css21>[CSS21]</a>.
Other CSS modules may expand the definitions of these value types:
for example <a data-biblio-type=informative data-link-type=biblio href=#css3color title=css3color>[CSS3COLOR]</a>,
when combined with this module,
expands the definition of the <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/css-color-3/#valuea-def-color title="<color>">&lt;color&gt;</a> value type as used in this specification.
<p> In addition to the property-specific values listed in their definitions,
all properties defined in this specification also accept the <a href=http://www.w3.org/TR/css3-values/>global keywords</a> as their property value.
For readability they has not been repeated explicitly.
<h2 class="heading settled heading" data-level=2 id=planned-features><span class=secno>2 </span><span class=content>
Planned Features</span><a class=self-link href=#planned-features></a></h2>
<ol>
<li>Resolution tagging in image()
<li>Logical keywords for specifying linear gradient direction.
<li>More interpolation modes for gradients: <a href=http://lists.w3.org/Archives/Public/www-style/2012Jan/0635.html>http://lists.w3.org/Archives/Public/www-style/2012Jan/0635.html</a>
<li>Ability to reference an SVG paint server via url (maybe as element(<a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/css-values-3/#string-value title="<string>">&lt;string&gt;</a>)?)
</ol>
<h2 class="heading settled heading" data-level=3 id=image-values><span class=secno>3 </span><span class=content>
Image Values: the <a class="production css-code" data-link-type=type href=#typedef-image title="<image>">&lt;image&gt;</a> type</span><a class=self-link href=#image-values></a></h2>
<p> The <a class="production css-code" data-link-type=type href=#typedef-image title="<image>">&lt;image&gt;</a> value type denotes a 2D image. It can be a
<a href=#url-notation>url reference</a>,
<a href=#image-notation>image notation</a>,
or <a href=#gradients>gradient notation</a>.
Its syntax is:
<pre class=prod><dfn class=css-code data-dfn-type=type data-export="" id=typedef-image>&lt;image&gt;<a class=self-link href=#typedef-image></a></dfn> = <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/css-values-3/#url-value title="<url>">&lt;url&gt;</a> | <a class="production css-code" data-link-type=function href=#funcdef-image title=image()>&lt;image()&gt;</a> | <a class="production css-code" data-link-type=function href=#funcdef-image-set title=image-set()>&lt;image-set()&gt;</a> | <a class="production css-code" data-link-type=function href=#funcdef-element title=element()>&lt;element()&gt;</a> | <a class="production css-code" data-link-type=function href=#funcdef-cross-fade title=cross-fade()>&lt;cross-fade()&gt;</a> | <a class="production css-code" data-link-type=type href=#typedef-gradient title="<gradient>">&lt;gradient&gt;</a></pre>
<p> An <a class="production css-code" data-link-type=type href=#typedef-image title="<image>">&lt;image&gt;</a> can be used in many CSS properties,
including the <a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css-backgrounds-3/#background-image title=background-image>background-image</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>, <a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css-ui-3/#cursor0 title=cursor>cursor</a> properties <a data-biblio-type=normative data-link-type=biblio href=#css21 title=css21>[CSS21]</a>
(where it replaces the <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/css-values-3/#url-value title="<url>">&lt;url&gt;</a> component in the property’s value).
<p> In some cases, an image is invalid,
such as a <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/css-values-3/#url-value title="<url>">&lt;url&gt;</a> pointing to a resource that is not a valid image format.
28B
An <dfn data-dfn-type=dfn data-export="" id=invalid-image>invalid image<a class=self-link href=#invalid-image></a></dfn> is rendered as a solid-color <span class=css data-link-type=maybe title=transparent>transparent</span> image with no intrinsic dimensions.
7E03 However, <a data-link-type=dfn href=#invalid-image title="invalid images">invalid images</a> have special behavior in some contexts,
such as the <a class=css data-link-type=maybe href=#funcdef-image title=image()>image()</a> notation.
<h3 class="heading settled heading" data-level=3.1 id=url-notation><span class=secno>3.1 </span><span class=content>
Image References and Image Slices: the <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/css-values-3/#url-value title="<url>">&lt;url&gt;</a> type and <span class=css data-link-type=maybe title=url()>url()</span> notation</span><a class=self-link href=#url-notation></a></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>&gt;url()'' notation</a>, defined in <a data-biblio-type=normative data-link-type=biblio href=#css21 title=css21>[CSS21]</a>.
<div class=example>
<p> In the example below, a background image is specified with <span class=css data-link-type=maybe title=url()>url()</span>syntax:
<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 <a data-link-type=dfn href=#invalid-image title="invalid image">invalid image</a>.
<h3 class="heading settled heading" data-level=3.2 id=image-notation><span class=secno>3.2 </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> function allows an author to:
<p> <ul>
<li>
<p> use <a href=http://www.w3.org/TR/media-frags/>media fragments</a> to clip out a portion of an image
<li>
<p> specify fallback images in case the preferred image can’t be decoded or is a type that the browser doesn’t recognize
<li>
<p> use a solid color as an image
<li>
<p> automatically respect the image orientation specified in the image’s metadata
</ul>
<p> The <a class=css data-link-type=maybe href=#funcdef-image title=image()>image()</a> notation is defined as:
<pre class=prod> <dfn class=css-code data-dfn-type=function data-export="" id=funcdef-image>image()<a class=self-link href=#funcdef-image></a></dfn> = image( <a class="production css-code" data-link-type=type href=#typedef-image-tags title="<image-tags>">&lt;image-tags&gt;</a>? [ <a class="production css-code" data-link-type=type href=#typedef-image-src title="<image-src>">&lt;image-src&gt;</a> , ]* [ <a class="production css-code" data-link-type=type href=#typedef-image-src title="<image-src>">&lt;image-src&gt;</a> | <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/css-color-3/#valuea-def-color title="<color>">&lt;color&gt;</a> ] )
<dfn class=css-code 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 | rtl ]
<dfn class=css-code 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 css-code" data-link-type=type href=http://dev.w3.org/csswg/css-values-3/#url-value title="<url>">&lt;url&gt;</a> | <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/css-values-3/#string-value title="<string>">&lt;string&gt;</a> ]
</pre>
<p> Each <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/css-values-3/#string-value title="<string>">&lt;string&gt;</a> or <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/css-values-3/#url-value title="<url>">&lt;url&gt;</a> inside <a class=css data-link-type=maybe href=#funcdef-image title=image()>image()</a> represents an image,
just as if the <a href=#url-notation>&gt;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 <a data-biblio-type=normative data-link-type=biblio href=#css3val title=css3val>[CSS3VAL]</a>)
when a specified <a class=css data-link-type=maybe href=#funcdef-image title=image()>image()</a> value is computed.
<p> If the image has an orientation specified in its metadata,
such as EXIF,
the UA must rotate or flip the image to correctly orient it
as the metadata specifies.
<h4 class="heading settled heading" data-level=3.2.1 id=image-fragments><span class=secno>3.2.1 </span><span class=content>
Image Fragments</span><a class=self-link href=#image-fragments></a></h4>
<p> When a URL specified in <a class=css data-link-type=maybe href=#funcdef-image title=image()>image()</a> 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=images/sprites.svg>
<img alt="[9 circles, with 0 to 8 eighths filled in]" height=20 src=images/sprites.svg width=180>
</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.
</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 <a class=css data-link-type=maybe href=#funcdef-image title=image()>image()</a> notation
<em>must</em> support the <code>xywh=#,#,#,#</code> form of media fragment identifiers
for images specified via <a class=css data-link-type=maybe href=#funcdef-image title=image()>image()</a>. <a data-biblio-type=normative data-link-type=biblio href=#media-frags title=media-frags>[MEDIA-FRAGS]</a>
<div class=example>
Note that image fragments can also be used with the <span class=css data-link-type=maybe title=url()>url()</span> 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> Since the <a class=css data-link-type=maybe href=#funcdef-image title=image()>image()</a> 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:
<pre> background-image: url('swirl.png'); /* old UAs */
background-image: image('sprites.png#xywh=10,30,60,20'); /* new UAs */
</pre> </div>
<h4 class="heading settled heading" data-level=3.2.2 id=image-fallbacks><span class=secno>3.2.2 </span><span class=content>
Image Fallbacks</span><a class=self-link href=#image-fallbacks></a></h4>
<p> Multiple <a class="production css-code" data-link-type=type href=#typedef-image-src title="<image-src>">&lt;image-src&gt;</a>s can be given separated by commas,
in which case the function represents the first image that’s not an <a data-link-type=dfn href=#invalid-image title="invalid image">invalid image</a>.
< 8DBD div>
The final argument can specify a <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/css-color-3/#valuea-def-color title="<color>">&lt;color&gt;</a> to serve as an ultimate fallback;
this can be used, e.g. for <a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css-backgrounds-3/#background-image title=background-image>background-image</a>,
to ensure adequate contrast if none of the preceding <a class="production css-code" data-link-type=type href=#typedef-image-src title="<image-src>">&lt;image-src&gt;</a>s can be used.
If the final argument is a <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/css-color-3/#valuea-def-color title="<color>">&lt;color&gt;</a>,
it represents a solid-color image of the given color with no <a data-link-type=dfn href=#intrinsic-dimensions title="intrinsic dimensions">intrinsic dimensions</a>.
If all of the provided <a class="production css-code" data-link-type=type href=#typedef-image-src title="<image-src>">&lt;image-src&gt;</a>s are <a data-link-type=dfn href=#invalid-image title="invalid images">invalid images</a>
and a fallback color was not provided as the last argument,
the entire <a class=css data-link-type=maybe href=#funcdef-image title=image()>image()</a> function must be treated as an <a data-link-type=dfn href=#invalid-image title="invalid image">invalid image</a>.
<div class=example>
<p> The rule below would tell the UA to load "wavy.svg" if it can;
failing that to load "wavy.png";
and 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.
<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:
<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 <a class=css data-link-type=maybe href=#funcdef-image title=image()>image()</a> function addresses this:
<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.
</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 <a data-link-type=dfn href=#invalid-image title="invalid image">invalid image</a>.
<span class=note>This error-handling is limited to image(),
and not in the definition of URL,
for legacy compat reasons.</span>
<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:
<pre>background-image: image("cat_meme.gif#frame=5", "lolcat.png");</pre> </div>
<h4 class="heading settled heading" data-level=3.2.3 id=color-images><span class=secno>3.2.3 </span><span class=content>
Solid-color Images</span><a class=self-link href=#color-images></a></h4>
<div class=example>
<p> At times, one may need a solid-color image for a property or function that does not accept the <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/css-color-3/#valuea-def-color title="<color>">&lt;color&gt;</a> type directly.
The <a class=css data-link-type=maybe href=#funcdef-image title=image()>image()</a> 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>
<h4 class="heading settled heading" data-level=3.2.4 id=bidi-images><span class=secno>3.2.4 </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 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.
<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:
<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:
<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.
</div>
<h3 class="heading settled heading" data-level=3.3 id=image-set-notation><span class=secno>3.3 </span><span class=content>
Resolution Negotiation: the <a class=css data-link-type=maybe href=#funcdef-image-set title=image-set()>image-set()</a> notation</span><a class=self-link href=#image-set-notation></a></h3>
<p> Delivering the most appropriate image resolution for a user’s device can be a difficult task.
Ideally, images should be in the same resolution as the device they’re being viewed in,
which can vary between users.
However, other factors can factor into the decision of which image to send;
for example, if the user is on a slow mobile connection,
they may prefer to receive lower-res images
rather than waiting for a large proper-res image to load.
The <a class=css data-link-type=maybe href=#funcdef-image-set title=image-set()>image-set()</a> function allows an author to ignore most of these issues,
simply providing multiple resolutions of an image
and letting the UA decide which is most appropriate in a given situation.
<p class=issue id=issue-980ee62a><a class=self-link href=#issue-980ee62a></a>
This solution assumes that resolution is a proxy for filesize,
and therefore doesn’t appropriately handle multi-resolution sets of vector images,
or mixing vector images with raster ones (e.g. for icons).
For example, use a vector for high-res,
pixel-optimized bitmap for low-res,
and same vector again for low-bandwidth (because it’s much smaller, even though it’s higher resolution).
<p> The syntax for <a class=css data-link-type=maybe href=#funcdef-image-set title=image-set()>image-set()</a> is:
<pre class=prod><dfn class=css-code data-dfn-type=function data-export="" id=funcdef-image-set>image-set()<a class=self-link href=#funcdef-image-set></a></dfn> = image-set( [ <a class="production css-code" data-link-type=type href=#typedef-image-set-decl title="<image-set-decl>">&lt;image-set-decl&gt;</a>, ]* [ <a class="production css-code" data-link-type=type href=#typedef-image-set-decl title="<image-set-decl>">&lt;image-set-decl&gt;</a> | <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/css-color-3/#valuea-def-color title="<color>">&lt;color&gt;</a>] )
<dfn class=css-code data-dfn-type=type data-export="" id=typedef-image-set-decl>&lt;image-set-decl&gt;<a class=self-link href=#typedef-image-set-decl></a></dfn> = [ <a class="production css-code" data-link-type=type href=#typedef-image title="<image>">&lt;image&gt;</a> | <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/css-values-3/#string-value title="<string>">&lt;string&gt;</a> ] <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/css-values-3/#resolution-value title="<resolution>">&lt;resolution&gt;</a></pre>
<p> The <a class=css data-link-type=maybe href=#funcdef-image-set title=image-set()>image-set()</a> function can not be nested inside of itself,
either directly
or indirectly
(as an argument to another <a class="production css-code" data-link-type=type href=#typedef-image title="<image>">&lt;image&gt;</a> type).
<p class=issue id=issue-81202629><a class=self-link href=#issue-81202629></a>
WebKit’s experimental implementation has an <span class=css data-link-type=maybe title=x>x</span> unit
which is identical to <a class=css data-link-type=maybe href=http://dev.w3.org/csswg/css-values-3/#dppx title=dppx>dppx</a>.
Should we add it?
<p> Each <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/css-values-3/#string-value title="<string>">&lt;string&gt;</a> or <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/css-values-3/#url-value title="<url>">&lt;url&gt;</a> inside <a class=css data-link-type=maybe href=#funcdef-image-set title=image-set()>image-set()</a> represents an image,
just like in <a class=css data-link-type=maybe href=#funcdef-image title=image()>image()</a>.
<p> Every <a class="production css-code" data-link-type=type href=#typedef-image-set-decl title="<image-set-decl>">&lt;image-set-decl&gt;</a> in a given <a class=css data-link-type=maybe href=#funcdef-image-set title=image-set()>image-set()</a> must have a different <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/css-values-3/#resolution-value title="<resolution>">&lt;resolution&gt;</a>,
or else the function is invalid.
<p> The value that a given <a class=css data-link-type=maybe href=#funcdef-image-set title=image-set()>image-set()</a> represents is determined by
the UA first ordering the set of <a class="production css-code" data-link-type=type href=#typedef-image-set-decl title="<image-set-decl>">&lt;image-set-decl&gt;</a>s
in a UA-determined order
(which should be based on the <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/css-values-3/#resolution-value title="<resolution>">&lt;resolution&gt;</a> of each <a class="production css-code" data-link-type=type href=#typedef-image-set-decl title="<image-set-decl>">&lt;image-set-decl&gt;</a>,
but may include other factors that the UA deems relevant,
such as connection speed).
The function then represents the first such image that is not an <a data-link-type=dfn href=#invalid-image title="invalid image">invalid image</a>.
<p> If a fallback color was provided,
the UA may decide at any point that the remaining <a class="production css-code" data-link-type=type href=#typedef-image-set-decl title="<image-set-decl>">&lt;image-set-decl&gt;</a>s are unsuitable,
and choose to use the fallback color instead,
in which case the function represents a solid-color image of the given color with no <a data-link-type=dfn href=#intrinsic-dimensions title="intrinsic dimensions">intrinsic dimensions</a>.
<p> If <em>all</em> of the <a class="production css-code" data-link-type=type href=#typedef-image-set-decl title="<image-set-decl>">&lt;image-set-decl&gt;</a>s represent <a data-link-type=dfn href=#invalid-image title="invalid images">invalid images</a>,
then if a fallback color was provided,
the function represents a solid-color image of the given color with no <a data-link-type=dfn href=#intrinsic-dimensions title="intrinsic dimensions">intrinsic dimensions</a>;
otherwise, the function represents an <a data-link-type=dfn href=#invalid-image title="invalid image">invalid image</a>.
<p class=issue id=issue-d54a6b64><a class=self-link href=#issue-d54a6b64></a>
HTML currently doesnt' do fallback if the first-chosen image doesn’t load.
We should harmonize with HTML,
either by convincing them to do fallback,
or by removing our own fallback.
<p> If an <a class="production css-code" data-link-type=type href=#typedef-image-set-decl title="<image-set-decl>">&lt;image-set-decl&gt;</a> is chosen and successfully loaded,
the associated <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/css-values-3/#resolution-value title="<resolution>">&lt;resolution&gt;</a> is the image’s <a data-link-type=dfn href=#intrinsic-resolution title="intrinsic resolution">intrinsic resolution</a>.
<p class=issue id=issue-6b5b488e><a class=self-link href=#issue-6b5b488e></a>
It’s been suggested that we don’t need a full <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/css-values-3/#resolution-value title="<resolution>">&lt;resolution&gt;</a> here,
and should instead just use the <span class=css data-link-type=maybe title=x>x</span> unit by itself.
This seems silly to me,
since the <span class=css data-link-type=maybe title=x>x</span> unit is just an easier synonym for <a class=css data-link-type=maybe href=http://dev.w3.org/csswg/css-values-3/#dppx title=dppx>dppx</a>,
but thoughts?
Beyond theoretical purity considerations,
it seems that <a class=css data-link-type=maybe href=http://dev.w3.org/csswg/css-values-3/#dpi title=dpi>dpi</a> can be useful for use-cases involving printing,
where dpi is actually used to talk about images
and having an integer correlation between dots and pixels
is either unnecessary or strictly non-sensical
(as the screening resolution can depend on the colors being used).
<div class=example>
This example shows how to use <a class=css data-link-type=maybe href=#funcdef-image-set title=image-set()>image-set()</a> to provide an image in three versions:
a "normal" version,
a "high-res" version,
and an extra-high resolution version for use in high-quality printing
(as printers can have <em>extremely</em> high resolution):
<pre> background-image: image-set( "foo.png" 1x,
"foo-2x.png" 2x,
"foo-print.png" 600dpi );
</pre> </div>
<h3 class="heading settled heading" data-level=3.4 id=element-notation><span class=secno>3.4 </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, 8097 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 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> The syntax for <a class=css data-link-type=maybe href=#funcdef-element title=element()>element()</a> is:
<pre class=prod><dfn class=css-code data-dfn-type=function data-export="" id=funcdef-element>element()<a class=self-link href=#funcdef-element></a></dfn> = element( <a class="production css-code" 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-code" 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=#select title=select>[SELECT]</a>.
<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> 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:
<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://www.w3.org/TR/CSS21/visuren.html#x43 title="stacking context">stacking context</a>
<dd>
<p> 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:
<p> <ul>
<li>
<p> 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>
<p> 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> 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 data-link-type=maybe title=transparent>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 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=#css3-transforms title=css3-transforms>[CSS3-TRANSFORMS]</a>
<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> Implementations may either re-use existing bitmap data generated for the referenced element
or regenerate the display of the element to maximize quality at the image’s size
(for example, if the implementation detects that the referenced element is an SVG fragment);
in the latter case, the layout of the referenced element in the image must not be changed by the regeneration process.
That is, the image must look identical to the referenced element,
modulo rasterization quality.
<div class=example>
<p> As a somewhat silly example, a <code>&lt;p&gt;</code> element can be reused as a background elsewhere in the document:
<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>
</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>
<p> 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:
<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 href=#invalid-image title="invalid image">invalid image</a>.
<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:
<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 data-link-type=maybe title=display:none>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.
<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:
<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=css 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.
</div>
<h4 class="heading settled heading" data-level=3.4.1 id=paint-sources><span class=secno>3.4.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 width, height, and appearance,
separate from the process of 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> 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> 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:
<dl>
<dt>objectBoundingBox
<dd>
<p> The coordinate system has its origin at the top left corner of the rectangle defined by the <a data-link-type=dfn href=#concrete-object-size 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 href=#concrete-object-size 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 href=#concrete-object-size title="concrete object size">concrete object size</a>.
<dt>userSpaceOnUse
<dd>
<p> The coordinate system has its origin at the top left corner of the rectangle defined by the <a data-link-type=dfn href=#concrete-object-size 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 href=#concrete-object-size 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 <a class=css data-link-type=maybe href=http://dev.w3.org/csswg/css-values-3/#px title=px>px</a> 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.
<h4 class="heading settled heading" data-level=3.4.2 id=elementsources><span class=secno>3.4.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> 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.
<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> Whenever <a class=css data-link-type=maybe href=#funcdef-element title=element()>element()</a> uses an <a class="production css-code" 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>
<p> 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>
<p> 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 href=#invalid-image title="invalid image">invalid image</a>.
<li>
<p> 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-code" 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-code" 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 data-link-type=maybe title="element(external fancy)">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> Note that the <a data-link-type=idl href=#dom-css-elementsources 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 data-link-type=maybe title=#fancy>#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.
</div>
<h4 class="heading settled heading" data-level=3.4.3 id=element-cycles><span class=secno>3.4.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> The dependency graph consists of edges such that:
<p> <ul>
<li>
<p> every element depends on its children
<li>
<p> 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>
<p> 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 href=#invalid-image title="invalid images">invalid images</a>.
<h3 class="heading settled heading" data-level=3.5 id=cross-fade-function><span class=secno>3.5 </span><span class=content>
Combining images: the <a class=css data-link-type=maybe href=#funcdef-cross-fade title=cross-fade()>cross-fade()</a> notation</span><a class=self-link href=#cross-fade-function></a></h3>
<p> When transitioning between images,
CSS requires a way to explicitly refer to the intermediate image
that is a combination of the start and end images.
This is accomplished with the <a class=css data-link-type=maybe href=#funcdef-cross-fade title=cross-fade()>cross-fade()</a> function,
which indicates the two images to be combined
and how far along in the transition the combination is.
<p class=note> Note: Authors can also use the <a class=css data-link-type=maybe href=#funcdef-cross-fade title=cross-fade()>cross-fade()</a> function for many simple image manipulations,
such as tinting an image with a solid color
or highlighting a particular area of the page by combining an image with a radial gradient.
<p> The syntax for <a class=css data-link-type=maybe href=#funcdef-cross-fade title=cross-fade()>cross-fade()</a> is defined as:
<pre class=prod><dfn class=css-code data-dfn-type=function data-export="" id=funcdef-cross-fade>cross-fade()<a class=self-link href=#funcdef-cross-fade></a></dfn> = cross-fade( [ <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/css-values-3/#percentage-value title="<percentage>">&lt;percentage&gt;</a>? &amp;&amp; <a class="production css-code" data-link-type=type href=#typedef-image title="<image>">&lt;image&gt;</a> ] [, <a class="production css-code" data-link-type=type href=#typedef-image title="<image>">&lt;image&gt;</a> | <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/css-color-3/#valuea-def-color title="<color>">&lt;color&gt;</a> ]? )</pre>
<p> The function represents an image generated by
combining two images.
<p> The <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/css-values-3/#percentage-value title="<percentage>">&lt;percentage&gt;</a> represents how much of the first image is retained
when it is blended with the second image.
The <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/css-values-3/#percentage-value title="<percentage>">&lt;percentage&gt;</a> must be between <span class=css data-link-type=maybe title=0%>0%</span> and <span class=css data-link-type=maybe title=100%>100%</span> inclusive;
any other value is invalid.
If omitted,
it defaults to the value <span class=css data-link-type=maybe title=50%>50%</span>.
<p> If the last argument is a <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/css-color-3/#valuea-def-color title="<color>">&lt;color&gt;</a>,
it represents a solid-color image with the same intrinsic dimensions as the first image.
If omitted,
it defaults to the color <span class=css data-link-type=maybe title=transparent>transparent</span>.
<p> More precisely,
given <span class=css data-link-type=maybe title="cross-fade(p a, b)">cross-fade(<var>p</var> <var>A</var>, <var>B</var>)</span>,
where <var>A</var> and <var>B</var> are images
and <var>p</var> is a percentage between 0% and 100%,
the function represents an image
with width equal to <code>width<sub>A</sub> × <var>p</var> + width<sub>B</sub> × (1-<var>p</var>)</code>
and height equal to <code>height<sub>A</sub> × <var>p</var> + height<sub>B</sub> × (1-<var>p</var>)</code>.
The contents of the image must be constructed by
first scaling <var>A</var> and <var>B</var> to the size of the generated image,