Status: ED Shortname: css-images Level: 4 Group: csswg ED: http://dev.w3.org/csswg/css-images-4/ TR: http://www.w3.org/TR/css4-images/ Editor: Tab Atkins Jr., Google, http://xanthir.com/contact/ Editor: fantasai, Mozilla, http://fantasai.inkedblade.net/contact Abstract: This module contains the features of CSS level 4 relating to the <> 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 < > type, additions to the < > type, extentions to the ''image()'' function, definitions for interpolating several < > types, and several properties controlling the interaction of replaced elements and CSS's layout models. !Issue Tracking: http://www.w3.org/Style/CSS/Tracker/products/27 Previous Version: http://www.w3.org/TR/2012/WD-css4-images-20120911/ Ignored Terms: , background positioning area, border image area, , , Map Link Defaults: css21 (property) display
::first-line and ::first-letter.
<image> = <An <> | < > | < > | < > | < > | < >
background-image: url(wavy.png);
image() = image( <Each <>? [ < > , ]* [ < > | < > ] ) <image-tags> = [ ltr | rtl ] <image-src> = [ < > | < > ]
background-image: image('sprites.svg#xywh=40,0,20,20')
...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.
xywh=#,#,#,# form of media fragment identifiers
for images specified via ''image()''. [[!MEDIA-FRAGS]]
background-image: url('swirl.png'); /* old UAs */
background-image: image('sprites.png#xywh=10,30,60,20'); /* new UAs */
background-image: image("wavy.svg", "wavy.png" , "wavy.gif");
body { color: black; background: white; }
p.special { color: white; background: url("dark.png") black; }
When the image doesn't load,
the background color is still there to ensure that the white text is readable.
However, if the image has some transparency,
the black will be visible behind it,
which is probably not desired.
The ''image()'' function addresses this:
body { color: black; background: white; }
p.special { color: white; background: image("dark.png", black); }
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.
background-image: image("cat_meme.gif#frame=5", "lolcat.png");
background-image: image(rgba(0,0,255,.5)), url("bg-image.png");
In the above, the background is the image "bg-image.png",
overlaid with partially-transparent blue.
<image-src>s,
the author may specify a directionality for the image,
similar to adding a dir attribute to an element in HTML.
If a directional image is used on or in an element with opposite direction,
the image must be flipped in the inline direction
(as if it was transformed by, e.g., scaleX(-1), if the inline direction is the X axis).
Note: Absent this declaration,
images default to no directionality at all,
and thus don't care about the directionality of the surrounding element.
<ul style="list-style-image: image(ltr 'arrow.png');"> <li dir='ltr'>My bullet is on the left!</li> <li dir='rtl'>MY BULLET IS ON THE RIGHT!</li> </ul>This should render something like:
⇒ My bullet is on the left! !THGIR EHT NO SI TELLUB YM ⇐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.
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). The syntax for ''image-set()'' is:
image-set() = image-set( [ <The ''image-set()'' function can not be nested inside of itself, either directly or indirectly (as an argument to another <>, ]* [ < > | < >] ) <image-set-decl> = [ < > | < > ] < >
WebKit's experimental implementation has an ''x'' unit
which is identical to ''dppx''.
Should we add it?
Each <
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.
If an <
It's been suggested that we don't need a full <
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?
This name conflicts with a somewhat similar function in GCPM.
This needs to be resolved somehow.
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.
When we have overflow:paged,
how can we address a single page in the view?
The ''element()'' function references the element matched by its argument.
The ID is first looked up in the elementSources map,
as described in that section.
If it's not found,
it's then matched against the document.
If multiple elements are matched,
the function references the first such element.
The image represented by the ''element()'' function can vary based on whether the element is visible in the document:
Requiring some degree of stacking context on the element appears to be required for an efficient implementation.
Do we need a full stacking context, or just a pseudo-stacking context?
Should it need to be a stacking context normally,
or can we just render it as a stacking context when rendering it to element()?
If the referenced element has a transform applied to it or an ancestor,
the transform must be ignored when rendering the element as an image. [[!CSS3-TRANSFORMS]]
If the referenced element is broken across pages,
the element is displayed as if the page content areas were joined flush in the pagination direction,
with pages' edges corresponding to the initial containing block's start edge aligned.
Elements broken across lines or columns are just rendered with their decorated bounding box.
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.
This reuse of the ID selector matches Moz behavior.
I'm trying to avoid slapping a <
We should add the ability to move the focus of the gradient,
as in the original -webkit-gradient() function.
See proposal in http://lists.w3.org/Archives/Public/www-style/2011Nov/0210.html
for "from <
Anything else that might be useful? Defining the shape of the gradient as elliptical, perhaps?
Produce examples.
Better yet, strike this section, and intermix some examples into the sections above.
Do this for the other two types of gradients as well.
Insert rendering here.
This is past the complexity point where it can be easily understood with just prose.
Add a diagram illustrating the possibilities,
preferably for all three kinds of gradients
(to show off the three shapes of gradient lines).
The colors in gradients are specified using color stops.
A color stop is a combination of a color and one or two positions.
(Depending on the type of gradient, that position can be a length, angle, or percentage.)
While every color stop conceptually has at least one position,
the position can be omitted in the syntax.
(It gets automatically filled in by the user agent; see below for details.)
Some color stops don't have a color,
only a position.
A color stop like this is a color interpolation hint,
which specifies how the colors of the two color stops on either side
should be interpolated in the space between them
(by default, they interpolate linearly).
There can only be at most one color interpolation hint between any two given normal color stops;
using more than that makes the function invalid.
Color stops are organized into a color stop list,
which is a list of one or more color stops.
The first and last color stops in the list
must have a color
(though their position can be omitted).
Color stops are placed on a gradient line,
which defines the colors at every point of a gradient.
The gradient function defines the shape and length of the gradient line,
along with its starting point and ending point.
Color stops must be specified in order.
Percentages refer to the length of the gradient line between the starting point and ending point,
with 0% being at the starting point
and 100% being at the ending point.
Lengths are measured from the starting point in the direction of the ending point along the gradient line.
Angles are measured with 0deg pointing up,
and positive angles corresponding to clockwise rotations from there.
Color stops are usually placed between the starting point and ending point,
but that's not required;
the gradient line extends infinitely in both directions,
and a color stop can be placed at any position on the gradient line.
A color stop with two locations is mostly equivalent
to specifying two color stops with the same color,
one for each position.
However, if the color is omitted,
it's treated as a single color stop by step 4 in the clean-up algorithm below.
Specifying two locations makes it easier to create solid-color "stripes" in a gradient,
without having to repeat the color twice.
The position of a color stop can be omitted.
This causes the color stop to position itself automatically
between the two surrounding stops.
If multiple stops in a row lack a position,
they space themselves out equally.
Similarly, the color of a color stop can be omitted.
The causes the color to be automatically computed
to halfway between the two surrounding stops,
so that the "midpoint" of a transition can be easily adjusted.
If multiple stops in a row lack a color,
they space themselves out equally in "color space",
giving more control over the smoothness of the transition.
The following steps must be applied in order to process the list of color stops.
After applying these rules,
all color stops will have a definite position and color
and they will be in ascending order:
This requires us to wait until after layout to do fix-up,
because implied-position stops (set by step 3)
may depend on stops that need layout information to place,
and which may be corrected by step 2.
Swapping steps 2 and 3 would let us interpolate color stops purely at computed-value time,
which is a nice plus,
at the cost of changing behavior from level 3 for some edge cases that triggered fixup.
Make sure this is handled well in the serialization rules.
At each color stop position,
the line is the color of the color stop.
Between two color stops,
the line's color is interpolated between the colors of the two color stops,
with the interpolation taking place in premultiplied RGBA space.
By default,
this interpolation is linear--
at 25%, 50%, or 75% of the distance between two color stops,
the color is a 25%, 50%, or 75% blend of the colors of the two stops.
However, if a color interpolation hint was provided between two color stops,
the interpolation is non-linear,
and controlled by the hint:
The ''image-set()'' notation can alter the intrinsic resolution of an image,
which ideally would be automatically honored without having to set this property.
How should we best address this?
Change the initial value to ''auto'', meaning "1dppx, unless CSS says otherwise"?
Say that image-resolution has no effect on images whose resolution was set by something else in CSS?
Or somehow wordsmithing ''image-set()'' in some way such that it always produces ''1dppx'' images somehow?
The 'image-resolution' property specifies the intrinsic resolution of all raster images used in or on the element.
It affects both content images
(e.g. replaced elements and generated content)
and decorative images
(such as 'background-image').
The intrinsic resolution of an image is used to determine the image's intrinsic dimensions.
Values have the following meanings:
Should we move the current ''auto'' behavior to a well-named keyword (''smooth''?)
and just define ''auto'' to be "whatever the UA wants",
which is what ''auto'' usually means?
This property does not dictate any particular scaling algorithm to be used.
For example, with ''image-rendering: auto'',
a user agent might scale images with bilinear interpolation by default,
switch to nearest-neighbor interpolation in high-load situations,
and switch to a high-quality scaling algorithm like Lanczos interpolation for static images that aren't moving or changing.
Similarly, with 'image-rendering: crisp-edges',
a user agent might scale images with nearest-neighbor interpolation by default,
and switch to EPX interpolation in low-load situations.
This property previously accepted the values ''optimizeSpeed'' and ''optimizeQuality''.
These are now deprecated;
a user agent must accept them as valid values
but must treat them as having the same behavior as auto,
and authors must not use them.
Special-case interpolating to/from no image,
like "background-image: url(foo);" to "background-image: none;".
This section needs review and improvement.
In particular, I believe the handling of linear-gradient() is incomplete -
I think we want to specifically interpolate the "length" of the gradient line
(the distance between 0% and 100%)
between the starting and ending positions explicitly,
so it doesn't grow and then shrink over a single animation.
Gradient images can be interpolated directly in CSS transitions and animations,
smoothly animating from one gradient to another.
There are only a few restrictions on what gradients are allowed to be interpolated:
background-image: image-set( "foo.png" 1x,
"foo-2x.png" 2x,
"foo-print.png" 600dpi );
Using Elements as Images: the ''element()'' notation
The ''element()'' function allows an author to use an element in the document as an image.
As the referenced element changes appearance,
the image changes as well.
This can be used, for example,
to create live previews of the next/previous slide in a slideshow,
or to reference a canvas element for a fancy generated gradient or even an animated background.
Note: The ''element()'' function only reproduces the appearance of the referenced element,
not the actual content and its structure.
Authors should only use this for decorative purposes,
and must not use ''element()'' to reproduce an element with significant content across the page.
Instead, just insert multiple copies of the element into the document.
The syntax for ''element()'' is:
element() = element( <
where <
An element is not rendered 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
Note: Because images clip anything outside their bounds by default,
this means that decorations that extend outside the decorated bounding box,
like box shadows,
may be clipped.
The image is constructed by rendering the referenced element and its descendants
(at the same size that they would be in the document)
over an infinite ''transparent'' canvas,
positioned so that the edges of the decorated bounding box are flush with the edges of the image.
<p> element can be reused as a background elsewhere in the document:
<style>
#src { color: white; background: lime; width: 300px; height: 40px; }
#dst { color: black; background: element(#src); padding: 20px; margin: 20px 0; }
</style>
<p id='src'>I'm an ordinary element!</p>
<p id='dst'>I'm using the previous element as my background!</p>
<pattern> element in an HTML document:
<!DOCTYPE html>
<svg>
<defs>
<pattern id='pattern1'>
<path d='...'>
</pattern>
</defs>
</svg>
<p style="background: element(#pattern1)">
I'm using the pattern as a background!
If the pattern is changed or animated,
my background will be updated too!
</p>
HTML also defines that a handful of elements,
such as <canvas>, <img>, and <video>,
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:
<!DOCTYPE html>
<script>
var canvas = document.querySelector('#animated-bullet');
canvas.width = 20; canvas.height = 20;
drawAnimation(canvas);
</script>
<canvas id='animated-bullet' style='display:none'></canvas>
<ul style="list-style-image: element(#animated-bullet);">
<li>I'm using the canvas as a bullet!</li>
<li>So am I!</li>
<li>As the canvas is changed over time with Javascript,
we'll all update our bullet image with it!</li>
</ul>
<!DOCTYPE html>
<p id='one' style="display:none;">one</p>
<iframe src="http://example.com">
<p id='two'>I'm fallback content!</p>
</iframe>
<ul>
<li style="background: element(#one);">
A display:none element isn't rendered, and a P element
doesn't provide a paint source.
</li>
<li style="background: element(#two);">
The descendants of a replaced element like an IFRAME
can't be used in element() either.
</li>
<li style="background: element(#three);">
There's no element with an id of "three", so this also
gets rendered as a transparent image.
</li>
</ul>
<defs> element is considered to be not rendered.
<!DOCTYPE html>
<script>
function navigateSlides() {
var currentSlide = ...;
document.querySelector('#prev-slide').id = '';
document.querySelector('#next-slide').id = '';
currentSlide.previousElementSibling.id = 'prev-slide';
currentSlide.nextElementSibling.id = 'next-slide';
}
</script>
<style>
#prev-preview, #next-preview {
position: fixed;
...
}
#prev-preview { background: element(#prev-slide); }
#next-preview { background: element(#next-slide); }
</style>
<a id='prev-preview'>Previous Slide</a>
<a id='next-preview'>Next Slide</a>
<section class='slide'>...</section>
<section class='slide current-slide'>...</section>
...
In this example, the navigateSlides 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 click handlers on the preview boxes to help navigate through the page.
Paint Sources
Host languages may define that some elements provide a paint source.
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 not rendered.
In HTML, the <img>, <video>, and <canvas> elements provide paint sources
(defined in each element's section in HTML5).
In SVG, any element that provides a paint server provides a paint source.
Note: In SVG1.1,
the <linearGradient>,
<radialGradient>,
and <pattern> elements
provide paint sources.
They are drawn as described in the spec,
with the coordinate systems defined as follows:
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.
Using Out-Of-Document Sources: the
The ''element()'' function normally selects elements within a document,
but elements that provide a paint source don't necessarily need to be in-document.
For example, an HTML ElementSources interface<canvas> element can be created, maintained, and drawn into entirely in script,
with no need for it to be inserted into the document directly.
All that's needed is a way to refer to the element,
as an ID selector cannot select elements outside of the document.
The elementSources Map object provides this.
partial interface CSS {
[SameObject] readonly attribute Map elementSources;
};
Any entries in the elementSources map with a string key
and a value that is an object providing a paint source
are made available to the ''element()'' function.
Whenever ''element()'' uses an <# character)
is first looked up in the elementSources map:
<script>
var bg = document.createElement('canvas');
bg.height = 200;
bg.width = 1000;
drawFancyBackground(bg);
CSS.elementSources.set('fancy', bg);
</script>
<style>
h1 {
background-image: element(#fancy);
}
</style>
As the "fancy" canvas is drawn into and animated,
the backgrounds of all the H1 elements will automatically update in tandem.
Note that the elementSources map is consulted before the document
to match the ID selector,
so even if there's an element in the document that would match ''#fancy'',
the backgrounds will still predictably come from the elementSources value instead.
Cycle Detection
The ''element()'' function can produce nonsensical circular relationships,
such as an element using itself as its own background.
These relationships can be easily and reliably detected and resolved, however,
by keeping track of a dependency graph and using common cycle-detection algorithms.
The dependency graph consists of edges such that:
If the graph contains a cycle,
any ''element()'' functions participating in the cycle are invalid images.
<use> element depends on the element it referenced.
Combining images: the ''cross-fade()'' notation
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 ''cross-fade()'' function,
which indicates the two images to be combined
and how far along in the transition the combination is.
Note: Authors can also use the ''cross-fade()'' 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.
The syntax for ''cross-fade()'' is defined as:
cross-fade() = cross-fade( [ <
The function represents an image generated by
combining two images.
The <widthA × p + widthB × (1-p)
and height equal to heightA × p + heightB × (1-p).
The contents of the image must be constructed by
first scaling A and B to the size of the generated image,
then applying dissolve(A,p) plus dissolve(B,1-p).
The "dissolve()" function and "plus" compositing operator are defined in the literature by Porter-Duff. [[PORTERDUFF]]
Gradients
A gradient is an image that smoothly fades from one color to another.
These are commonly used for subtle shading in background images, buttons, and many other things.
The gradient notations described in this section allow an author to specify such an image in a terse syntax,
so that the UA can generate the image automatically when rendering the page.
The syntax of a <
<gradient> = [
<
background: linear-gradient(white, gray);
list-style-image: radial-gradient(circle, #006, #00a 90%, #0000af 100%, white 100%)
Linear Gradients: the ''linear-gradient()'' notation
A linear gradient is created by specifying a straight 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.
linear-gradient() syntax
The linear gradient syntax is:
linear-gradient() = linear-gradient(
[ [ <
The first argument to the function specifies the gradient line,
which gives the gradient a direction and determines how color-stops are positioned.
It may be omitted;
if so, it defaults to ''to bottom''.
The gradient line's direction may be specified in two ways:
Starting from the center of the gradient box,
extend a line at the specified angle in both directions.
The ending point is the point on the gradient line
where a line drawn perpendicular to the gradient line
would intersect the corner of the gradient box in the specified direction.
The starting point is determined identically, but in the opposite direction.
The length of the gradient line (between the starting point and ending point) is:
abs(W * sin(A)) + abs(H * cos(A))
The length of the gradient line (between the starting and ending point) is:
abs(W * sin(A)) + abs(H * cos(A))
Linear Gradient Examples
All of the following ''linear-gradient()'' examples are presumed to be backgrounds applied to a box that is 200px wide and 100px tall.
linear-gradient(yellow, blue);
linear-gradient(to bottom, yellow, blue);
linear-gradient(180deg, yellow, blue);
linear-gradient(to top, blue, yellow);
linear-gradient(to bottom, yellow 0%, blue 100%);
linear-gradient(135deg, yellow, blue);
linear-gradient(-45deg, blue, yellow);
linear-gradient(yellow, blue 20%, #0f0);
linear-gradient(to top right, red, white, blue)
Radial Gradients: the ''radial-gradient()'' notation
In a radial gradient,
rather than colors smoothly fading from one side of the gradient box to the other
as with linear gradients,
they instead emerge from a single point
and smoothly spread outward in a circular or elliptical shape.
A radial gradient is specified by indicating the center of the gradient
(where the 0% ellipse will be)
and the size and shape of the ending shape
(the 100% ellipse).
Color stops are given as a list,
just as for ''linear-gradient()''.
Starting from the gradient center
and progressing towards (and potentially beyond) the ending shape
uniformly-scaled concentric ellipses are drawn and colored
according to the specified color stops.
radial-gradient() Syntax
The radial gradient syntax is:
radial-gradient() = radial-gradient(
[ [ <
radial-gradient(5em circle at top left, yellow, blue)
If <
If <
radial-gradient() = radial-gradient(
[ [ circle || <
Placing Color Stops
Color-stops are placed on a gradient line shaped like a ray
(a line that starts at one point, and extends infinitely in a one direction),
similar to the gradient line of linear gradients.
The gradient line's starting point is at the center of the gradient,
and it extends toward the right,
with the ending point on the point where the gradient line intersects the ending shape.
A color-stop can be placed at a location before 0%;
though the negative region of the gradient line is never directly consulted for rendering,
color stops placed there can affect the color of non-negative locations on the gradient line through interpolation or repetition
(see repeating gradients).
For example, ''radial-gradient(red -50px, yellow 100px)'' produces an elliptical gradient
that starts with a reddish-orange color in the center
(specifically, #f50)
and transitions to yellow.
Locations greater than 100% simply specify a location a correspondingly greater distance from the center of the gradient.
The color of the gradient at any point is determined by
first finding the unique ellipse passing through that point
with the same center, orientation, and ratio between major and minor axises as the ending-shape.
The point's color is then the color of the positive section of the gradient line at the location where this ellipse intersects it.
Degenerate Radial Gradients
Some combinations of position, size, and shape
will produce a circle or ellipse with a radius of 0.
This will occur, for example,
if the center is on a gradient box edge and ''closest-side'' or ''closest-corner'' is specified
or if the size and shape are given explicitly and either of the radiuses is zero.
In these degenerate cases,
the gradient must be be rendered as follows:
Radial Gradient Examples
All of the following examples are applied to a box that is 200px wide and 100px tall.
radial-gradient(yellow, green);
radial-gradient(ellipse at center, yellow 0%, green 100%);
radial-gradient(farthest-corner at 50% 50%, yellow, green);
radial-gradient(circle, yellow, green);
radial-gradient(red, yellow, green);
radial-gradient(farthest-side at left bottom, red, yellow 50px, green);
radial-gradient(closest-side at 20px 30px, red, yellow, green);
radial-gradient(20px 30px at 20px 30px, red, yellow, green);
radial-gradient(closest-side circle at 20px 30px, red, yellow, green);
radial-gradient(20px 20px at 20px 30px, red, yellow, green);
Conic Gradients: the ''conic-gradient()'' notation
A conic gradient starts by specifying the center of a circle,
similar to radial gradients,
except that conic gradient color-stops are placed around the circumference of the circle,
rather than on a line emerging from the center,
causing the color to smoothly transition as you spin around the center,
rather than as you progress outward from the center.
A conic gradient is specified by indicating the center of the gradient,
and then specifying a list of color-stops.
Unlike linear and radial gradients,
whose color-stops are placed by specifying a <
''conic-gradient()'' Syntax
The syntax for a conic gradient is:
conic-gradient() = conic-gradient(
[ at <
The <
Placing Color Stops
Color stops are placed on a gradient line that curves around the center in a circle,
with both the 0% and 100% locations at 0deg.
Just like linear gradients,
0deg points to the top of the page,
and increasing angles correspond to clockwise movement around the circle.
Note: It may be more helpful to think of the gradient line as forming a spiral,
where only the segment from 0deg to 360deg is rendered.
This avoids any confusion about "overlap" when you have angles outside of the rendered region.
A color-stop can be placed at a location before 0% or after 100%;
though these regions are never directly consulted for rendering,
color stops placed there can affect the color of color-stops within the rendered region
through interpolation or repetition (see repeating gradients).
For example, ''conic-gradient(red -50%, yellow 150%)'' produces a conic gradient
that starts with a reddish-orange color at 0deg (specifically, #f50),
and transitions to an orangish-yellow color at 360deg (specifically, #fa0).
The color of the gradient at any point is determined by first finding the unique ray
anchored at the center of the gradient that passes through the given point.
The point's color is then the color of the gradient line at the location where this ray intersects it.
Conic Gradient Examples
Repeating Gradients: the ''repeating-linear-gradient()'', ''repeating-radial-gradient()'', and ''repeating-conic-gradient()'' notations
In addition to ''linear-gradient()'', ''radial-gradient()'', and ''conic-gradient()'',
this specification defines repeating-linear-gradient(),
repeating-radial-gradient(),
and repeating-conic-gradient() values.
These notations take the same values
and are interpreted the same
as their respective non-repeating siblings defined previously.
When rendered, however, the color-stops are repeated infinitely in both directions,
with their positions shifted by multiples of the difference between
the last specified color-stop's position
and the first specified color-stop's position.
For example, ''repeating-linear-gradient(red 10px, blue 50px)''
is equivalent to ''linear-gradient(..., red -30px, blue 10px, red 10px, blue 50px, red 50px, blue 90px, ...)''.
Note that the last color-stop and first color-stop will always coincide at the boundaries of each group,
which will produce sharp transitions if the gradient does not start and end with the same color.
repeating-linear-gradient(red, blue 20px, red 40px)
repeating-radial-gradient(red, blue 20px, red 40px)
repeating-radial-gradient(circle closest-side at 20px 30px, red, yellow, green 100%, yellow 150%, red 200%)
repeating-conic-gradient(at 20%, white 0deg, white 20deg, red 20deg, red 40deg)
Note: As usual, implementations may use whatever algorithm they wish,
so long as it produces the same result as the above.
rgb(75%,50%,75%)):
repeating-linear-gradient(red 0px, white 0px, blue 0px);
The following gradient would render the same as the previous under normal circumstances
(because desktop monitors can't faithfully render color-stops 1/10th of a pixel apart),
but would render as a normal repeating gradient if, for example,
the author applied "zoom:100;" to the element on which the gradient appears:
repeating-linear-gradient(red 0px, white .1px, blue .2px);
Gradient Color-Stops
<color-stop-list> =
[ <
Plus:
Sequence:
N:
Note: If the hint is placed halfway between the two stops,
this is thus the ordinary linear interpolation.
If the hint is placed anywhere else,
it dictates the position of the "halfway point",
where the color is an equal blend between the two color stops,
and produces smooth, even blends between the color stops and the "halfway point".
Before the first color stop,
the line is the color of the first color stop.
After the last color stop, the line is the color of the last color stop.
If multiple color stops have the same position,
they produce an infinitesimal transition from the one specified first in the rule
to the one specified last.
In effect, the color suddenly changes at that position rather than smoothly transitioning.
PlogH(.5).
(1 - C) of the first stop and C of the second stop.
1. linear-gradient(red, white 20%, blue)
=1=>
linear-gradient(red 0%, white 20%, blue 100%)
2. linear-gradient(red 40%, white, black, blue)
=13=>
linear-gradient(red 40%, white 60%, black 80%, blue 100%)
3. linear-gradient(red -50%, white, blue)
=13=>
linear-gradient(red -50%, white 25%, blue 100%)
4. linear-gradient(red -50px, white, blue)
=13=>
linear-gradient(red -50px, white calc(-25px + 50%), blue 100%)
5. linear-gradient(red 20px, white 0px, blue 40px)
=2=>
linear-gradient(red 20px, white 20px, blue 40px)
6. linear-gradient(red, white -50%, black 150%, blue)
=12=>
linear-gradient(red 0%, white 0%, black 150%, blue 150%)
7. linear-gradient(red 80px, white 0px, black, blue 100px)
=23=>
linear-gradient(red 80px, white 80px, black 90px, blue 100px)
8. linear-gradient(red, 25%, white)
=14=>
linear-gradient(red 0%, rgb(100%,50%,50%) 25%, white 100%)
linear-gradient(90deg, red, transparent, blue)
In premultiplied space,
transitions to or from "transparent" always look nice:
On the other hand,
if a gradient were to incorrectly transition in non-premultiplied space,
the colors near "transparent" would noticeably darken to a grayish color,
because "transparent" is actually a shorthand for ''rgba(0,0,0,0)'', or transparent black:
Sizing Images and Objects in CSS
Images used in CSS may come from a number of sources:
from binary image formats (such as gif, jpeg, etc),
dedicated markup formats (such as SVG),
and CSS-specific formats (such as the linear-gradient() value type defined in this specification).
As well, a document may contain many other types of objects,
such as video, plugins, or nested documents.
These images and objects
(just objects hereafter)
may offer many types of sizing information to CSS,
or none at all.
This section defines generically the size negotiation model between the object and the CSS layout algorithms.
Object-Sizing Terminology
In order to define this handling,
we define a few terms,
to make it easier to refer to various concepts:
<iframe> element in HTML.
An object cannot have only two intrinsic dimensions,
as any two automatically define the third.
If an object (such as an icon) has multiple sizes,
then the largest size (by area) is taken as its intrinsic size.
If it has multiple aspect ratios at that size,
or has multiple aspect ratios and no size,
then the aspect ratio closest to the aspect ratio of the default object size is used.
Determine this by seeing which aspect ratio produces the largest area
when fitting it within the default object size using a contain constraint fit;
if multiple sizes tie for the largest area,
the wider size is chosen as its intrinsic size.
CSS⇋Object Negotiation
Objects in CSS are sized and rendered by the object size negotiation algorithm as follows:
src attribute on an <img> element,
CSS queries the object for its intrinsic dimensions.
Concrete Object Size Resolution
Currently the rules for sizing objects are described in each context that such objects are used.
This section defines some common sizing constraints
and how to resolve them
so that future specs can refer to them instead of redefining size resolution in each instance.
Default Sizing Algorithm
The default sizing algorithm is a set of rules commonly used to find an object's concrete object size.
It resolves the simultaneous constraints presented by the object's intrinsic dimensions
and either an unconstrained specified size
or one consisting of only a definite width and/or height.
Some object sizing rules
(such as those for 'list-style-image')
correspond exactly to the default sizing algorithm.
Others
(such as those for 'border-image')
invoke the default sizing algorithm
but also apply additional sizing rules before arriving at a final concrete object size.
The default sizing algorithm is defined as follows:
Cover and Contain Constraint Sizing
Two other common specified sizes are the contain constraint and the cover constraint,
both of which are resolved against a specified constraint rectangle
using the object's intrinsic aspect ratio:
In both cases,
if the object doesn't have an intrinsic aspect ratio,
the concrete object size is the specified constraint rectangle.
Examples of CSS Object Sizing
Sizing Objects: the 'object-fit' property
Name: object-fit
Value: fill | contain | cover | none | scale-down
Initial: fill
Applies to: replaced elements
Inherited: no
Percentages: n/a
Media: visual
Computed value: specified value
Animatable: no
The 'object-fit' property specifies how the contents of a replaced element
should be fitted to the box established by its used height and width.
If the content does not completely fill the replaced element's content box,
the unfilled space shows the replaced element's background.
Since replaced elements always clip their contents to the content box,
the content will never overflow.
See the 'object-position' property for positioning the object with respect to the content box.
fit attribute in [[SMIL10]]
and the <preserveAspectRatio attribute in [[SVG11]].
Note: Per the object size negotiation algorithm,
the concrete object size
(or, in this case, the size of the content)
does not directly scale the object itself -
it is merely passed to the object as information about the size of the visible canvas.
How to then draw into that size is up to the image format.
In particular, raster images always scale to the given size,
while SVG uses the given size as the size of the "SVG Viewport"
(a term defined by SVG)
and then uses the values of several attributes on the root <svg> element to determine how to draw itself.
Positioning Objects: the 'object-position' property
Name: object-position
Value: <
The 'object-position' property determines the alignment of the replaced element inside its box.
The <
Image Processing
Overriding Image Resolutions: the 'image-resolution' property
The image resolution is defined as
the number of image pixels per unit length,
e.g., pixels per inch.
Some image formats can record information about the resolution of images.
This information can be helpful when determining the actual size of the image in the formatting process.
However, the information can also be wrong,
in which case it should be ignored.
By default, CSS assumes a resolution of one image pixel per CSS ''px'' unit;
however, the 'image-resolution' property allows using some other resolution.
Name: image-resolution
Value: [ from-image || <
As vector formats such as SVG do not have an intrinsic resolution,
this property has no effect on vector images.
img.high-res {
image-resolution: 300dpi;
}
With this set, an image meant to be 5 inches wide at 300dpi
will actually display as 5in wide;
without this set,
the image would display as approximately 15.6in wide
since the image is 15000 image pixels across,
and by default CSS displays 96 image pixels per inch.
img { image-resolution: from-image }
These rules both specify that the UA should use the image resolution found in the image itself,
but if the image has no resolution,
the resolution is set to ''300dpi'' instead of the default ''1dppx''.
img { image-resolution: from-image 300dpi }
img { image-resolution: 300dpi from-image }
img { image-resolution: 300dpi }
This rule, on the other hand,
if used when the screen's resolution is 96dpi,
would instead render the image at 288dpi
(so that 3 image pixels map to 1 device pixel):
img { image-resolution: 300dpi snap; }
The ''snap'' keyword can also be used when the resolution is taken from the image:
img { image-resolution: snap from-image; }
An image declaring itself as 300dpi will,
in the situation above,
display at 288dpi
(3 image pixels per device pixel)
whereas an image declaring 72dpi will render at 96dpi
(1 image pixel per device pixel).
Orienting an Image on the Page: the 'image-orientation' property
Issue: This property is likely going to be deprecated and its functionality moved to HTML.
At minimum, it will likely lose all but its initial value and ''image-orientation/from-image''.
If a picture is taken with a camera turned on its side,
or a document isn't positioned correctly within a scanner,
the resultant image may be "sideways" or even upside-down.
The 'image-orientation' property provides a way to apply an "out-of-band" rotation to image source data to correctly orient an image.
Note: This property is not intended to specify layout transformations
such as arbitrary rotation or flipping the image in the horizontal or vertical direction.
(See [[CSS3-2D-TRANSFORMS]] for a feature designed to do that.)
It is also not needed to correctly orient an image when printing in landscape versus portrait orientation,
as that rotation is done as part of layout. (See [[CSS3PAGE]].)
It should only be used to correct incorrectly-oriented images.
Name: image-orientation
Value: from-image | <
This property specifies an orthogonal rotation to be applied to an image before it is laid out.
It applies only to content images
(e.g. replaced elements and generated content),
not decorative images
(such as 'background-image').
CSS layout processing applies to the image after rotation.
This implies, for example:
Values have the following meanings:
The 'image-orientation' property must be applied before any other transformations,
such as being specified in the ''image()'' function with an opposite directionality to its context,
or using CSS Transforms.
img.ninety { image-orientation: 90deg }
...
<img class="ninety" src=...>
The same effect could be achieved with, for example,
an angle of -270deg or 450deg.
Determing How To Scale an Image: the 'image-rendering' property
Name: image-rendering
Value: auto | crisp-edges | pixelated
Initial: auto
Applies to: all elements
Inherited: yes
Media: visual
Computed value: specified value
Animatable: no
The 'image-rendering' property provides a hint to the user-agent
about what aspects of an image are most important to preserve when the image is scaled,
to aid the user-agent in the choice of an appropriate scaling algorithm.
When specified on an element,
it applies to all images given in properties for the element,
such as background images,
list-style images,
or the content of replaced elements when they represent an image that must be scaled.
The values of the 'image-rendering' property are interpreted as follows:
Interpolation
This section describes how to interpolate between new value types defined in this specification,
for use with modules such as CSS Transitions and CSS Animations.
If an algorithm below simply states that two values should be "interpolated" or "transitioned" without further details,
then the value should be interpolated as described by the Transitions spec.
Otherwise, the algorithm may reference a variable "t" in its detailed description of the interpolation.
This is a number which starts at 0% and goes to 100%,
and is set to a value that represents the progress through the transition,
based on the duration of the transition,
the elapsed time,
and the timing function in use.
For example, with a linear timing function and a 1s duration,
after .3s t is equal to 30%.
Interpolating <
All images can be interpolated,
though some special types of images
(like some gradients)
have their own special interpolation rules.
In general terms,
images are interpolated by scaling them to the size of the start image
and cross-fading the two while they transition to the size of the end image.
In specific terms,
at each point in the interpolation
the image is equal to cross-fade( (100% - t) start image, end image).
Interpolating cross-fade()
If both the starting and ending images are cross-fade()s
which differ only by by their <
Interpolating <
If the two gradients satisfy both of those constraints,
they must be interpolated as described below.
If not, they must be interpolated as a generic <
Serialization
This section describes the serialization of all new properties and value types introduced in this specification,
for the purpose of interfacing with the CSS Object Model [[CSSOM]].
To serialize any function defined in this module,
serialize it per its individual grammar,
in the order its grammar is written in,
omitting components when possible without changing the meaning,
joining space-separated tokens with a single space,
and following each serialized comma with a single space.
For ''cross-fade()'',
always serialize the <Linear-Gradient( to bottom, red 0%,yellow,black 100px)
must serialize as:
linear-gradient(red, yellow, black 100px)
Changes since Images 3