Title: CSS Images Module Level 3 Status: ED Shortname: css-images Level: 3 Group: csswg ED: https://drafts.csswg.org/css-images-3/ TR: https://www.w3.org/TR/css-images-3/ Work Status: Testing Editor: Tab Atkins Jr., Google, http://xanthir.com/contact/, w3cid 42199 Editor: Elika J. Etemad / fantasai, Invited Expert, http://fantasai.inkedblade.net/contact, w3cid 35400 Editor: Lea Verou, Invited Expert, http://lea.verou.me/about, w3cid 52258 Abstract: This module contains the features of CSS level 3 relating to the <> type and some replaced elements. It includes and extends the functionality of CSS level 2 [[CSS2]]. The main extensions compared to CSS2.1 are the generalization of the < > type to the < > type, several additions to the < > type, a generic sizing algorithm for images and other replaced content in CSS, definitions for interpolating several < > types, and several properties controlling the interaction of replaced elements and CSS's layout models. At Risk: 'image-orientation' Implementation Report: https://wpt.fyi/results/css/css-images?label=experimental&label=master&aligned Previous Version: https://www.w3.org/TR/2019/CR-css-images-3-20191010/ Previous Version: https://www.w3.org/TR/2012/CR-css3-images-20120417/ Ignored Terms: , background positioning area, border image area, , Ignored Vars: start image, end image Include Can I Use Panels: yes
spec:svg; type:element; text:feimage spec:css-backgrounds-3; type:value; text:centerIntroduction {#intro} ===================== In CSS Levels 1 and 2, image values, such as those used in the 'background-image' property, could only be given by a single URL value. This module introduces additional ways of representing 2D images, for example as a gradient. This module also defines several properties for manipulating raster images and for sizing or positioning replaced elements such as images within the box determined by the CSS layout algorithms. It also defines in a generic way CSS's sizing algorithm for images and other similar replaced elements. This subsection (above) is not normative. Module Interactions {#placement} -------------------------------- This module defines and extends the <
::first-line
and ::first-letter
.
Value Definitions {#values}
---------------------------
This specification follows
the CSS property definition conventions from [[!CSS2]].
using the value definition syntax from [[!CSS-VALUES-3]].
Value types not defined in this specification are defined in CSS Level 2 Revision 1 [[!CSS2]].
Other CSS modules may expand the definitions of these value types:
for example [[CSS-VALUES-3]], when combined with this module,
adds the ''initial'' keyword as a possible property value.
In addition to the property-specific values listed in their definitions,
all properties defined in this specification
also accept the CSS-wide keywords as their property value.
For readability they have not been repeated explicitly.
Image Values: the <<image> = <An <> | < >
background-image: url(wavy.png);
<mask id="foo">
element in the SVG document,
or be pointing to a <g id="foo">
element
and depending on the '':target'' pseudo-class to change how it renders as an image.
When this occurs,
the "icon.svg" file is loaded up and examined;
if the #foo element is indeed a <{mask}>,
the ''url()'' is treated as a reference to that element;
otherwise,
it's interpreted as an image.
<gradient> = <> | < > | < > | < >
background: linear-gradient(white, gray);
* list-style-image: radial-gradient(circle, #006, #00a 90%, #0000af 100%, white 100%)
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: : using <> | to < > ]? , < > ) <side-or-corner> = [left | right] || [top | bottom]
abs(W * sin(A)) + abs(H * cos(A))
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-gradient() = radial-gradient( [ <> || < > ]? [ at < > ]? , < > )
radial-gradient(5em circle at top left, yellow, blue)
radial-gradient() = radial-gradient( [ [ circle || <> ] [ at < > ]? , | [ ellipse || < >{2} ] [ at < > ]? , | [ [ circle | ellipse ] || < > ] [ at < > ]? , | at < > , ]? < > [ , < > ]+ ) <extent-keyword> = closest-corner | closest-side | farthest-corner | farthest-side
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);
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%)
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);
<color-stop-list> = <Percentages are resolved against 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 along the gradient line from the starting point in the direction of the ending point. [=Color stop=] and [=transition hint=] positions are usually placed between the starting point and ending point, but that's not required: the gradient line extends infinitely in both directions, and positions can be specified anywhere on the gradient line. When the position of a [=color stop=] is omitted, it is automatically assigned a position. The first or last [=color stop=] in the [=color stop list=] is assigned the [=gradient line’s=] [=starting point=] or [=ending point=] (respectively). Otherwise, it's assigned the position halfway between the two surrounding stops. If multiple stops in a row lack a position, they space themselves out equally between the surrounding positioned stops. See [[#color-stop-fixup]] for details.> , [ < >? , < > ]# <linear-color-stop> = < > && < >? <linear-color-hint> = < >
PlogH(.5)
.
(1 - C)
of the first stop and C of the second stop.
rgba(0, 0, 255, .5)
,
which would then be expressed as [0, 0, 127.5, .5]
in its premultiplied representation.
Interpolating colors using the premultiplied representations
rather than the plain rgba representations
tends to produce more attractive transitions,
particularly when transitioning from a fully opaque color to fully transparent.
Note that transitions where either the transparency or the color are held constant
(for example, transitioning between rgba(255, 0, 0, 100%)
(opaque red)
and rgba(0,0,255,100%)
(opaque blue),
or rgba(255,0,0,100%)
(opaque red)
and rgba(255,0,0,0%)
(transparent red))
have identical results whether the color interpolation is done in premultiplied or non-premultiplied color-space.
Differences only arise when both the color and transparency differ between the two endpoints.
linear-gradient(90deg, red, transparent, blue)With premultiplied colors, transitions to or from "transparent" always look nice: On the other hand, if a gradient were to incorrectly transition in non-premultiplied space, the center of the gradient would be a noticeably grayish color, because "transparent" is actually a shorthand for ''rgba(0,0,0,0)'', or transparent black, meaning that the red transitions to a black as it loses opacity, and similarly with the blue's transition:
1. linear-gradient(red, white 20%, blue) =1=> linear-gradient(red 0%, white 20%, blue 100%) 2. linear-gradient(red 40%, white, black, blue) =1,3=> linear-gradient(red 40%, white 60%, black 80%, blue 100%) 3. linear-gradient(red -50%, white, blue) =1,3=> linear-gradient(red -50%, white 25%, blue 100%) 4. linear-gradient(red -50px, white, blue) =1,3=> 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) =1,2=> linear-gradient(red 0%, white 0%, black 150%, blue 150%) 7. linear-gradient(red 80px, white 0px, black, blue 100px) =2,3=> linear-gradient(red 80px, white 80px, black 90px, blue 100px)
Name: object-fit Value: fill | contain | cover | none | scale-down Initial: fill Applies to: replaced elements Inherited: no Percentages: n/a Computed value: specified keyword Animation type: discreteThe 'object-fit' property specifies how the contents of a replaced element should be fitted to the box established by its used height and width.
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 {#the-object-position}
--------------------------------------------------------------------------
Name: object-position Value: <The 'object-position' property determines the alignment of the replaced element inside its box. The <> Initial: 50% 50% Applies to: replaced elements Inherited: no Percentages: refer to width and height of element itself Computed value: as for 'background-position' Animation type: as for 'background-position' Canonical Order: the horizontal component of the < >, followed by the vertical component
Name: image-orientation Value: from-image | none | [ <This property is optional for implementations. This property specifies an orthogonal rotation to be applied to the element’s images before they are used in the document. It applies to content images (e.g. replaced elements and generated content) and image sources referenced by SVG elements (such as <{feImage}>), as well as to decorative images applied via CSS rules (such as 'background-image' and other <> || flip ] Initial: from-image Applies to: all elements Inherited: yes Computed value: the specified keyword, or an < >, rounded and normalized (see text), plus optionally a ''flip'' keyword Animation type: discrete
img.ninety { image-orientation: 90deg } ... <img class="ninety" src=...>The same effect could be achieved with, for example, an angle of -270deg or 450deg.
Name: image-rendering Value: auto | smooth | high-quality | pixelated | crisp-edges Initial: auto Applies to: all elements Inherited: yes Computed value: specified keyword Animation type: discreteThe '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:
Linear-Gradient( to bottom, red 0%,yellow,black 100px)must serialize as:
linear-gradient(red, yellow, black 100px)