You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Image Preview for HTML Images] Define swapping and transitions in CSS #1405
::image - the main image - displays the main image
::preview - displays the preview
::wrapper - contains both
Then have a series of pseudo-classes on the <img> that communicate the state of the image and preview:
:complete - a pseudo-class that's active when the image has fully loaded
:scan-complete - a pseudo-class that's active when the image has loaded an initial complete scan
This would allow defining things like cross-fades between the preview and image. You could even apply a blur to the wrapper, which animates away once the image is ready, meaning the image appears to come into focus when it's ready.
It seems like the proposal is strongly leaning towards view transitions for this currently, but I don't see the benefit, and it means a capturing cycle for things we already have rasterised.
Thanks for the suggestion! I’m open to other ways to animate the handoff between the preview and final image. My main goal is to understand whether customizable animations are part of the minimum solution developers would actually use, or whether they can be added later.
I’m also curious how this would support CSS gradients, as you mentioned in this comment. Are you thinking that the preview source itself would be specified as a CSS property that accepts an <image> value? Right now, I understand how the pseudo-elements would let us style the preview and final image, but I’m not sure how the gradient becomes the preview.
I think you could do this without introducing ::image or ::wrapper, by layering the ::preview on top of the image when the browser deems it necessary to show it.
Advantage of not using ::image is that it remains clear to what part the styles declared on img itself apply to. Say you have a display: block declared on img … does that apply to the ::image, ::preview, ::wrapper, or all? And what does getComputedStyle on img return when you’ve manipulated the ::wrapper? There have been similar discussions for ::interest-button and interest invokers — w3c/csswg-drafts#13981 (comment)
The downside of using only ::preview is that it would require some form or @exit-style though, to animate-out the ::preview when it’s no longer necessary to show — w3c/csswg-drafts#9500
I think you could do this without introducing ::image or ::wrapper, by layering the ::preview on top of the image when the browser deems it necessary to show it.
I think those pieces are necessary for three reasons:
Alpha transparency - Both the image and its preview may contain an alpha channel, so simply layering the preview over the top would be additive rather than replacing. Better to do proper replacing.
Animated images - If the main image is display:none whilst the preview is showing, it isn't trying to play animations. This means, when the swap occurs, the animation starts.
Cross-fading - Same as with view transitions, the wrapper allows you to apply the isolation to produce a true cross-fading animation from one to the other. I guess the image itself could act as that wrapper, but it depends if you'd want things like blurs to impact borders on the image or not.
And what does getComputedStyle on img return when you’ve manipulated the ::wrapper?
I don't understand the issue here. To be clear, the ::wrapper is still inside the img, not outside it. Similar to how the ::view-transition-image-pair is inside the ::view-transition-group. Maybe instead of ::wrapper it should be ::image-pair.
Thanks, this helps clarify how the CSS approach could define and customize the handoff between preview and final image states.
However, I have a more fundamental question. My understanding was that this issue was primarily proposing an alternative to using View Transitions for the preview-to-final-image handoff. But in your example, CSS can also be used to specify the preview itself (for example via --image-preview and ::preview).
Should I think of this proposal as:
An alternative to View Transitions for defining the handoff and animations between image states, while still relying on something like Image.previewSrc / previewsrc to provide the preview image?
or
A broader alternative to the Image.previewSrc approach itself, where the preview is specified entirely through CSS rather than an HTML attribute/API?
I'm trying to understand whether the proposal is focused on transitions only, or whether it is also proposing a different mechanism for supplying preview content.
Advantages of the system I'm proposing over the current one:
It avoids all the screen capturing & position animation stuff that comes with view transitions, which is unnecessary because we already have the before and after states as decoded images.
It allows both states to be animated images during a transition.
It allows blurring the image and/or preview, without blurring the <img> itself (which would also blur its borders etc).
It allows CSS to fully define the appearance of the preview, allowing things like gradients.
If we didn't have previewsrc and just relied on CSS, then the preview download wouldn't start until styles resolve, which seems far too late. It might also make other things tricky like different previews for different <source>s, but I haven't thought too much about it.
So, this proposal is more than just 1, as a key benefit is that it does allow pure CSS representations of the preview. But, I didn't intend this to replace the previewsrc attribute. In my proposal, previewsrc would be used to set the replaced content of ::preview.
Something that came up at TPAC: We might have an opportunity here to give developers control of failed-to-load images, and the display of alt text during & after loading.
Something that came up at TPAC: We might have an opportunity here to give developers control of failed-to-load images, and the display of alt text during & after loading.
A separate placeholder part would let authors use a color, gradient, or shimmer while waiting for a preview or when there isn’t one. The group would handle shared clipping and isolation.
The rough idea would be to:
Style each part independently, without also affecting the image’s border or padding.
Expose the current presentation through something like :image-phase(none | waiting | preview | image), rather than treating it as a network-completion signal.
Use normal CSS transitions, with display transitions keeping outgoing placeholder/preview content around while it animates out.
For example, using the current previewsrc name and the proposed CSS hooks:
<imgclass="photo"
src="photo.avif"
previewsrc="thumb.avif"
width="800" height="600"
alt="A mountain reflected in a lake">
With UA-provided active/inactive and entry styles, this would show a gradient placeholder, fade into a blurred preview, then crossfade into the main image.
Separately, authors could choose native/progressive reveal timing or wait for a complete, decoded first frame, using the same policy for placeholder and preview handoffs. The exact mechanism needs definition (for example image-reveal: normal | complete-frame CSS property).
We could start with just the placeholder/image parts and add preview support later. That would let the CSS work move independently of the HTML preview API and partially address the styling use cases in w3c/csswg-drafts#7467.
This also leaves room for failed-image and alt-text styling through resource-state selectors or additional parts, rather than trying to make ::preview cover everything.
Activity
jakearchibald commentedon Sep 23, 2026
It seems like the proposal is strongly leaning towards view transitions for this currently, but I don't see the benefit, and it means a capturing cycle for things we already have rasterised.
ogerchikov commentedon Oct 3, 2026
Thanks for the suggestion! I’m open to other ways to animate the handoff between the preview and final image. My main goal is to understand whether customizable animations are part of the minimum solution developers would actually use, or whether they can be added later.
I’m also curious how this would support CSS gradients, as you mentioned in this comment. Are you thinking that the preview source itself would be specified as a CSS property that accepts an
<image>value? Right now, I understand how the pseudo-elements would let us style the preview and final image, but I’m not sure how the gradient becomes the preview.jakearchibald commentedon Oct 5, 2026
So, with the idea in my OP, the UA stylesheet would be roughly like:
This doesn't fully capture the loading sequence in the explainer, but hopefully it's enough to get the idea across.
Then, a developer could choose to do:
And:
Hopefully it's clear that you could easily animate/transition between these states.
bramus commentedon Oct 5, 2026
I think you could do this without introducing
::imageor::wrapper, by layering the::previewon top of the image when the browser deems it necessary to show it.Advantage of not using
::imageis that it remains clear to what part the styles declared onimgitself apply to. Say you have adisplay: blockdeclared onimg… does that apply to the::image,::preview,::wrapper, or all? And what doesgetComputedStyleonimgreturn when you’ve manipulated the::wrapper? There have been similar discussions for::interest-buttonand interest invokers — w3c/csswg-drafts#13981 (comment)The downside of using only
::previewis that it would require some form or@exit-stylethough, to animate-out the::previewwhen it’s no longer necessary to show — w3c/csswg-drafts#9500jakearchibald commentedon Oct 5, 2026
I think those pieces are necessary for three reasons:
display:nonewhilst the preview is showing, it isn't trying to play animations. This means, when the swap occurs, the animation starts.jakearchibald commentedon Oct 5, 2026
I don't understand the issue here. To be clear, the
::wrapperis still inside theimg, not outside it. Similar to how the::view-transition-image-pairis inside the::view-transition-group. Maybe instead of::wrapperit should be::image-pair.ogerchikov commentedon Oct 7, 2026
Thanks, this helps clarify how the CSS approach could define and customize the handoff between preview and final image states.
However, I have a more fundamental question. My understanding was that this issue was primarily proposing an alternative to using View Transitions for the preview-to-final-image handoff. But in your example, CSS can also be used to specify the preview itself (for example via
--image-previewand::preview).Should I think of this proposal as:
Image.previewSrc/previewsrcto provide the preview image?or
Image.previewSrcapproach itself, where the preview is specified entirely through CSS rather than an HTML attribute/API?I'm trying to understand whether the proposal is focused on transitions only, or whether it is also proposing a different mechanism for supplying preview content.
jakearchibald commentedon Oct 8, 2026
Advantages of the system I'm proposing over the current one:
<img>itself (which would also blur its borders etc).If we didn't have
previewsrcand just relied on CSS, then the preview download wouldn't start until styles resolve, which seems far too late. It might also make other things tricky like different previews for different<source>s, but I haven't thought too much about it.So, this proposal is more than just 1, as a key benefit is that it does allow pure CSS representations of the preview. But, I didn't intend this to replace the
previewsrcattribute. In my proposal,previewsrcwould be used to set the replaced content of::preview.jakearchibald commentedon Oct 29, 2026
Something that came up at TPAC: We might have an opportunity here to give developers control of failed-to-load images, and the display of alt text during & after loading.
ogerchikov commentedon Oct 29, 2026
Do you have more context for this?
jakearchibald commentedon Oct 29, 2026
It was just a hallway chat. They're states of an image that are currently difficult to customise.
ogerchikov commentedon Oct 29, 2026
I think we could build on your image/preview/group idea and make it useful beyond previews:
A separate placeholder part would let authors use a color, gradient, or shimmer while waiting for a preview or when there isn’t one. The group would handle shared clipping and isolation.
The rough idea would be to:
:image-phase(none | waiting | preview | image), rather than treating it as a network-completion signal.displaytransitions keeping outgoing placeholder/preview content around while it animates out.For example, using the current
previewsrcname and the proposed CSS hooks:With UA-provided active/inactive and entry styles, this would show a gradient placeholder, fade into a blurred preview, then crossfade into the main image.
Separately, authors could choose native/progressive reveal timing or wait for a complete, decoded first frame, using the same policy for placeholder and preview handoffs. The exact mechanism needs definition (for example
image-reveal: normal | complete-frameCSS property).We could start with just the placeholder/image parts and add preview support later. That would let the CSS work move independently of the HTML preview API and partially address the styling use cases in w3c/csswg-drafts#7467.
This also leaves room for failed-image and alt-text styling through resource-state selectors or additional parts, rather than trying to make
::previewcover everything.Please let me know what you think about this.
jakearchibald commentedon Oct 30, 2026
I'm not sure about
image-reveal. It sounds like we could achieve that with more pseudo-classes. But the general direction seems good.Revise Image Preview inputs, responsive support, and lifecycle (#1436)