8000 csswg-drafts/css-images-3/Overview.html at 7e6bd98d10dfed4f5c40e24d6c6204b215aa41df · simonwuelker/csswg-drafts · GitHub
Skip to content

Latest commit

 

History

History
executable file
·
3094 lines (2421 loc) · 132 KB

File metadata and controls

executable file
·
3094 lines (2421 loc) · 132 KB
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang=en>
<head
profile="http://dublincore.org/documents/2008/08/04/dc-html/ http://www.w3.org/2006/03/hcard">
<meta content="text/html; charset=utf-8" http-equiv=Content-Type>
<title>CSS Image Values and Replaced Content Module Level 3</title>
<link href="http://purl.org/dc/terms/" rel=schema.dc>
<link href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright"
rel=dc.rights>
<meta content="CSS Image Values and Replaced Content Module Level 3"
name=dc.title>
<meta content=text name=dc.type>
<meta content=2013-04-10 name=dc.date>
<meta content="Elika J. Etemad" name=dc.creator>
<meta content="Tab Atkins Jr." name=dc.creator>
<meta content=W3C name=dc.publisher>
<meta content="http://dev.w3.org/csswg/css3-images/" name=dc.identifier>
<link href="../default.css" rel=stylesheet type="text/css">
<link href="../csslogo.ico" rel="shortcut icon" type="image/x-icon">
<link href="http://www.w3.org/StyleSheets/TR/W3C-ED.css" rel=stylesheet
type="text/css">
<body>
<div class=head> <!--begin-logo-->
<p><a href="http://www.w3.org/"><img alt=W3C height=48
src="http://www.w3.org/Icons/w3c_home" width=72></a> <!--end-logo-->
<h1>CSS Image Values and Replaced Content Module Level 3</h1>
<h2 class="no-num no-toc" id=longstatus-date>Editor's Draft 10 April 2013</h2>
<dl>
<dt>This Version:
<dd><a
href="http://dev.w3.org/csswg/css3-images/">http://dev.w3.org/csswg/css3-images/</a>
<!-- <dd><a href="http://dev.w3.org/csswg/css3-images/">http://www.w3.org/TR/2013/WD-css3-images-20130410/</a>-->
<dt>Latest Version:
<dd><a
href="http://www.w3.org/TR/css3-images/">http://www.w3.org/TR/css3-images/</a>
<dt>Editor's Draft:
<dd><a
href="http://dev.w3.org/csswg/css3-images/">http://dev.w3.org/csswg/css3-images/</a>
<dt>Previous Version:
<dd><a
1891
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:
<dd><a
href="http://www.w3.org/Style/CSS/Tracker/products/27">http://www.w3.org/Style/CSS/Tracker/products/27</a>
<dt>Feedback:
<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>Editors:
<dd class=vcard> <a class="url fn"
href="http://fantasai.inkedblade.net/contact">Elika J. Etemad</a> (<span
class=org>Mozilla</span>)
<dd class=vcard> <a class="url fn"
href="http://www.xanthir.com/contact/">Tab Atkins Jr.</a> (<span
class=org>Google</span>)
</dl>
<!--begin-copyright-->
<p class=copyright><a
href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright"
rel=license>Copyright</a> © 2013 <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>
<!--end-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 3 relating to the &lt;image> type and
replaced elements. It includes and extends the functionality of CSS
level 2 <a href="#CSS21" rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>,
which builds on CSS level 1 <a href="#CSS1"
rel=biblioentry>[CSS1]<!--{{CSS1}}--></a>. The main extensions compared to
level 2 are the generalization of the &lt;url> type to the &lt;image>
type, several additions to the ‘<a href="#image-type"><code
class=css>&lt;image></code></a>’ 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.
<h2 class="no-num no-toc" id=status>Status of this document</h2>
<!--begin-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=%5Bcss3-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
“css3-images” in the subject, preferably like this:
“[<!---->css3-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>.</p>
<!--end-status-->
<p>​​​​​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: …
<ol>
<li>The <a href="#image-notation">image()</a> notation
<li>The ‘<a href="#object-fit"><code
class=property>object-fit</code></a>’, ‘<a
href="#object-position"><code
class=property>object-position</code></a>’, ‘<a
href="#image-orientation"><code
class=property>image-orientation</code></a>’, and ‘<a
href="#image-resolution"><code
class=property>image-resolution</code></a>’ properties
</ol>
<h2 class="no-num no-toc" id=contents>Table of contents</h2>
<!--begin-toc-->
<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="#resolution-units"><span class=secno>2. </span> Resolution
Units: the &lt;resolution> type</a>
<li><a href="#image-values"><span class=secno>3. </span> Image Values: the
&lt;image> type</a>
<ul class=toc>
<li><a href="#url-notation"><span class=secno>3.1. </span> Image
References and Image Slices: the ‘<code class=css>&lt;url></code>’
type and ‘<code class=css>url()</code>’ notation</a>
<li><a href="#image-notation"><span class=secno>3.2. </span> Image
Fallbacks and Annotations: the ‘<code class=css>image()</code>’
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>
</ul>
</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 ‘<code class=css>linear-gradient()</code>’
notation</a>
<li><a href="#radial-gradients"><span class=secno>4.2. </span> Radial
Gradients: the ‘<code class=css>radial-gradient()</code>’
notation</a>
<li><a href="#repeating-gradients"><span class=secno>4.3. </span>
Repeating Gradients: the ‘<code
class=css>repeating-linear-gradient()</code>’ and ‘<code
class=css>repeating-radial-gradient()</code>’ notations</a>
<li><a href="#color-stop-syntax"><span class=secno>4.4. </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 ‘<code class=property>object-fit</code>’ property</a>
<li><a href="#the-object-position"><span class=secno>5.6. </span>
Positioning Objects: the ‘<code
class=property>object-position</code>’ 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 ‘<code
class=property>image-resolution</code>’ property</a>
<li><a href="#the-image-orientation"><span class=secno>6.2. </span>
Orienting an Image on the Page: the ‘<code
class=property>image-orientation</code>’ property</a>
</ul>
<li><a href="#conformance"><span class=secno>7. </span> Conformance</a>
<ul class=toc>
<li><a href="#conventions"><span class=secno>7.1. </span> Document
Conventions</a>
<li><a href="#conformance-classes"><span class=secno>7.2. </span>
Conformance Classes</a>
<li><a href="#partial"><span class=secno>7.3. </span> Partial
Implementations</a>
<li><a href="#experimental"><span class=secno>7.4. </span> Experimental
Implementations</a>
<li><a href="#testing"><span class=secno>7.5. </span>Non-Experimental
Implementations</a>
<li><a href="#cr-exit-criteria"><span class=secno>7.6. </span> CR Exit
Criteria</a>
</ul>
<li class=no-num><a href="#acknowledgments">Acknowledgments</a>
<li class=no-num><a href="#references">References</a>
<ul class=toc>
<li class=no- 1891 num><a href="#normative-references">Normative
references</a>
<li class=no-num><a href="#other-references">Other references</a>
<li class=no-num><a href="#changes">Changes Since Last Call</a>
</ul>
<li class=no-num><a href="#index">Index</a>
<li class=no-num><a href="#property-index">Property index</a>
</ul>
<!--end-toc-->
<h2 id=intro><span class=secno>1. </span> 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 ‘<code
class=property>background-image</code>’ 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>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><span class=secno>1.1. </span> Module Interactions</h3>
<p>This module defines and extends the ‘<a href="#image-type"><code
class=css>&lt;image></code></a>’ value type defined in <a
href="#CSS3VAL" rel=biblioentry>[CSS3VAL]<!--{{!CSS3VAL}}--></a>.
Furthermore it replaces the ‘<code class=css>&lt;url></code>’ type in
the ‘<code class=property>background-image</code>’ and ‘<code
class=property>list-style-image</code>’ definitions in CSS1 and CSS2 and
adds ‘<a href="#image-type"><code class=css>&lt;image></code></a>’ as
an alternative to ‘<code class=css>&lt;url></code>’ in the ‘<code
class=property>content</code>’ property's value. It is presumed that CSS
specifications beyond CSS2.1 will use the ‘<a href="#image-type"><code
class=css>&lt;image></code></a>’ notation in place of ‘<code
class=css>&lt;url></code>’ where 2D images are expected. (See e.g. <a
href="#CSS3BG" rel=biblioentry>[CSS3BG]<!--{{CSS3BG}}--></a>.)
<p>Of the properties defined in this module, only ‘<a
href="#image-resolution"><code
class=property>image-resolution</code></a>’ applies to
<code>::first-line</code> and <code>::first-letter</code>.
<h3 id=values><span class=secno>1.2. </span> Values</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 href="#CSS21"
rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>. Value types not defined in
this specification are defined in CSS Level 2 Revision 1 <a
href="#CSS21" rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>. Other CSS
modules may expand the definitions of these value types: for example <a
href="#CSS3COLOR" rel=biblioentry>[CSS3COLOR]<!--{{CSS3COLOR}}--></a>,
when combined with this module, expands the definition of the &lt;color>
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/CSS21/cascade.html#value-def-inherit">inherit</a>
keyword as their property value. For readability it has not been repeated
explicitly.
<h2 id=resolution-units><span class=secno>2. </span> 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:
<dl>
<dt><dfn id=lsquodpirsquo>‘<code class=css>dpi</code>’</dfn>
<dd>dots per inch
<dt><dfn id=lsquodpcmrsquo>‘<code class=css>dpcm</code>’</dfn>
<dd>dots per centimeter
<dt><dfn id=lsquodppxrsquo>‘<code class=css>dppx</code>’</dfn>
<dd>dots per ‘<code class=css>px</code>’ unit
</dl>
<p>The ‘<a href="#resolution-type"><code
class=css>&lt;resolution></code></a>’ unit represents the size of a
single "dot" in a graphical representation by indicating how many of these
dots fit in a CSS ‘<code class=property>in</code>’, ‘<code
class=property>cm</code>’, or ‘<code class=property>px</code>’. For
uses, see e.g. the ‘<code class=css>resolution</code>’ media query in
<a href="#MEDIAQ" rel=biblioentry>[MEDIAQ]<!--{{MEDIAQ}}--></a> or the
‘<a href="#image-resolution"><code
class=property>image-resolution</code></a>’ property defined below.
<p class=note>Note that due to the 1:96 fixed ratio of CSS ‘<code
class=css>in</code>’ to CSS ‘<code class=css>px</code>’, ‘<code
class=css>1dppx</code>’ is equivalent to ‘<code
class=css>96dpi</code>’. This corresponds to the default resolution of
images displayed in CSS: see ‘<a href="#image-resolution"><code
class=property>image-resolution</code></a>’.
<div class=example>
<p>The following @media rule uses Media Queries <a href="#MEDIAQ"
rel=biblioentry>[MEDIAQ]<!--{{MEDIAQ}}--></a> to assign some special
style rules to devices that use two or more device pixels per CSS
‘<code class=css>px</code>’ unit:
<pre>@media (min-resolution: 2dppx) { ... }</pre>
</div>
<!-- ====================================================================== -->
<h2 id=image-values><span class=secno>3. </span> Image Values: the
&lt;image> type</h2>
<p>The ‘<a href="#image-type"><code class=css>&lt;image></code></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>,
<!-- <a href="#element-reference">element reference</a>, --> or <a
href="#gradients">gradient notation</a>. Its syntax is:
<pre class=prod><dfn id=image-type>&lt;image></dfn> = <i>&lt;url></i> | <a
href="#image-list-type"><i>&lt;image-list></i></a> | <a
href="#gradient-type"><i>&lt;gradient></i></a></pre>
<p>An ‘<a href="#image-type"><code class=css>&lt;image></code></a>’ can
be used in many CSS properties, including the ‘<code
class=property>background-image</code>’, ‘<code
class=property>list-style-image</code>’, ‘<code
class=property>cursor</code>’ properties <a href="#CSS21"
rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a> (where it replaces the
‘<code class=css>&lt;url></code>’ component in the property's value).
<p>In some cases, an image is invalid, such as a ‘<code
class=css>&lt;url></code>’ pointing to a resource that is not a valid
image format. An <dfn id=invalid-image>invalid image</dfn> is rendered as
a solid-color ‘<code class=css>transparent</code>’ image with no
intrinsic dimensions. However, <a href="#invalid-image"><i>invalid
images</i></a> have special behavior in some contexts, such as the
‘<code class=css>image()</code>’ notation.</p>
<!-- ====================================================================== -->
<h3 id=url-notation><span class=secno>3.1. </span> Image References and
Image Slices: the ‘<code class=css>&lt;url></code>’ type and ‘<code
class=css>url()</code>’ 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">‘<code
class=css>url()</code>’ notation</a>, defined in <a href="#CSS21"
rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>.
<div class=example>
<p>In the example below, a background image is specified with ‘<code
class=css>url()</code>’ 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
href="#invalid-image"><i>invalid image</i></a>.</p>
<!-- ====================================================================== -->
<h3 id=image-notation><span class=secno>3.2. </span> Image Fallbacks and
Annotations: the ‘<code class=css>image()</code>’ notation</h3>
<p>The ‘<code class=css>image()</code>’ function allows an author to:
<ul>
<li>use <a href="http://www.w3.org/TR/media-frags/">media fragments</a> to
clip out a portion of an image
<li>specify fallback images in case the preferred image can't be decoded
or is a type that the browser doesn't recognize
<li>use a solid color as an image
</ul>
<p>The ‘<code class=css>image()</code>’ 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> ]</pre>
<p>Each ‘<code class=css>&lt;string></code>’ or ‘<code
class=css>&lt;url></code>’ inside ‘<code class=css>image()</code>’
represents an image, just as if the <a href="#url-notation">‘<code
class=css>url()</code>’ 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 href="#CSS3VAL"
rel=biblioentry>[CSS3VAL]<!--{{!CSS3VAL}}--></a>) when a specified
‘<code class=css>image()</code>’ value is computed.
<h4 id=image-fragments><span class=secno>3.2.1. </span> Image Fragments</h4>
<p>When a URL specified in ‘<code class=css>image()</code>’ 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 alt="[9 circles, with 0 to 8 eighths filled in]"
height=20 src=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.
<p><small>* SVG-in-&lt;img> support required. Click the picture to view
the SVG directly.</small>
</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 ‘<code class=css>image()</code>’ notation <em>must</em> support
the <code>xywh=#,#,#,#</code> form of media fragment identifiers for
images specified via ‘<code class=css>image()</code>’. <a
href="#MEDIA-FRAGS"
rel=biblioentry>[MEDIA-FRAGS]<!--{{!MEDIA-FRAGS}}--></a>
<div class=example>
<p>Note that image fragments can also be used with the ‘<code
class=css>url()</code>’ 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 ‘<code class=css>image()</code>’ 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 id=image-fallbacks><span class=secno>3.2.2. </span> Image Fallbacks</h4>
<p>Multiple ‘<a href="#image-decl-type"><code
class=css>&lt;image-decl>s</code></a>’ can be given separated by commas,
in which case the function represents the first image that's not an <a
href="#invalid-image"><i>invalid image</i></a>. The final argument can
specify a ‘<code class=css>&lt;color></code>’ to serve as an ultimate
fallback; this can be used, e.g. for ‘<code
class=property>background-image</code>’, to ensure adequate contrast if
none of the preceding ‘<a href="#image-decl-type"><code
class=css>&lt;image-decl>s</code></a>’ can be used. If the final
argument is a ‘<code class=css>&lt;color></code>’, it represents a
solid-color image of the given color with no <a
href="#intrinsic-dimensions"><i>intrinsic dimensions</i></a>. If all of
the provided ‘<a href="#image-decl-type"><code
class=css>&lt;image-decl>s</code></a>’ are <a
href="#invalid-image"><i>invalid images</i></a> and a fallback color was
not provided as the last argument, the entire ‘<code
class=css>image()</code>’ function must be treated as an <a
href="#invalid-image"><i>invalid image</i></a>.
<div class=example>
<p>The rule below would tell the UA to load ‘<code
class=css>wavy.svg</code>’ if it can; failing that to load ‘<code
class=css>wavy.png</code>’; failing that to display ‘<code
class=css>wavy.gif</code>’. 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 ‘<code class=css>image()</code>’ 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 href="#invalid-image"><i>invalid
image</i></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>
<!-- XXX SVG fragment example with spriting / fallbacks (once SVG can provide this) -->
<h4 id=color-images><span class=secno>3.2.3. </span> 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 ‘<code class=css>&lt;color></code>’ type
directly. The ‘<code class=css>image()</code>’ 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>
⇒ My bullet is on the left!
!THGIR EHT NO SI TELLUB YM ⇐</pre>
<p>In LTR list items, the image will be used as-is. In the RTL list items, however, it will be flipped in the inline direction, so it still points into the content.</p>
</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><span class=secno>4. </span> 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 <a href="#gradient-type"><i>&lt;gradient></i></a> is:
<pre class=prod><dfn id=gradient-type>&lt;gradient></dfn> = [
<a
href="#linear-gradient-type"><i>&lt;linear-gradient></i></a> | <a
href="#radial-gradient-type"><i>&lt;radial-gradient></i></a> |
<a
href="#repeating-linear-gradient-type"><i>&lt;repeating-linear-gradient></i></a> | <a
href="#repeating-radial-gradient-type"><i>&lt;repeating-radial-gradient></i></a> ]</pre>
<div class=example>
<p>As with the other <a href="#image-type"><i>&lt;image></i></a> types
defined in this specification, gradients can be used in any property that
accepts images. For example:
<ul>
<li><code>background: linear-gradient(white, gray);</code>
<li><code>list-style-image: radial-gradient(circle, #006, #00a 90%,
#0000af 100%, white 100%)</code>
</ul>
</div>
<p>A gradient is drawn into a box with the dimensions of the <a
href="#concrete-object-size"><i>concrete object size</i></a>, referred to
as the <dfn id=gradient-box>gradient box</dfn>. However, the gradient
itself has no <a href="#intrinsic-dimensions"><i>intrinsic
dimensions</i></a>.
<div class=example>
<p>For example, if you use a gradient as a background, by default the
gradient will draw into a <a href="#gradient-box"><i>gradient box</i></a>
the size of the element's padding box. If ‘<code
class=property>background-size</code>’ is explicitly set to a value
such as ‘<code class=css>100px 200px</code>’, then the <a
href="#gradient-box"><i>gradient box</i></a> will be 100px wide and 200px
tall. Similarly, for a gradient used as a ‘<code
class=property>list-style-image</code>’, the box would be a 1em square,
which is the <a href="#default-object-size"><i>default object
size</i></a> for that property.
</div>
<!-- ====================================================================== -->
<h3 id=linear-gradients><span class=secno>4.1. </span> Linear Gradients:
the ‘<code class=css>linear-gradient()</code>’ 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><span class=secno>4.1.1. </span>
linear-gradient() syntax</h4>
<p>The linear gradient syntax is:
<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
id=gradient-line>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 ‘<code class=css>to bottom</code>’.
<p>The <a href="#gradient-line"><i title="gradient line">gradient
line's</i></a> direction may be specified in two ways:
<dl>
<dt>using angles
<dd>For the purpose of this argument, ‘<code class=css>0deg</code>’
points upward, and positive angles represent clockwise rotation, so
‘<code class=css>90deg</code>’ point toward the right.
<dt>using keywords
<dd>
<p>If the argument is ‘<code class=css>to top</code>’, ‘<code
class=css>to right</code>’, ‘<code class=css>to bottom</code>’, or
‘<code class=css>to left</code>’, the angle of the <a
href="#gradient-line"><i>gradient line</i></a> is ‘<code
class=css>0deg</code>’, ‘<code class=css>90deg</code>’, ‘<code
class=css>180deg</code>’, or ‘<code class=css>270deg</code>’,
respectively.
<p> If the argument instead specifies a corner of the box such as
‘<code class=css>to top left</code>’, the <a
href="#gradient-line"><i>gradient line</i></a> must be angled such that
it points into the same quadrant as the specified corner, and is
perpendicular to a line intersecting the two neighboring corners of the
<a href="#gradient-box"><i>gradient box</i></a>. <span class=note>This
causes a color-stop at 50% to intersect the two neighboring corners (see
<a href="#corner-gradient-example">example</a>).</span>
</dl>
<p>Starting from the center of the <a href="#gradient-box"><i>gradient
box</i></a>, extend a line at the specified angle in both directions. The
ending point is the point on the <a href="#gradient-line"><i>gradient
line</i></a> where a line drawn perpendicular to the <a
href="#gradient-line"><i>gradient line</i></a> would intersect the corner
of the <a href="#gradient-box"><i>gradient box</i></a> in the specified
direction. The starting point is determined identically, but in the
opposite direction.
<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.
<div class=example>
<div style="overflow: hidden"> <img
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.]"
src=gradient-diagram.png style="float: right; margin-left: 1em;">
<p>This example illustrates visually how to calculate the <a
href="#gradient-line"><i>gradient line</i></a> from the rules above.
This shows the starting and ending point of the <a
href="#gradient-line"><i>gradient line</i></a>, along with the actual
gradient, produced by an element with ‘<code class=css>background:
linear-gradient(45deg, white, black);</code>’.