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] Better consideration to the CSS alternative #1440
Compared with the HTML preview input, this has several advantages:
It can accept the full CSS syntax.
CSS rules and queries can select and reuse previews.
Abstract placeholders remain in the presentation layer.
Also CSS colors and images from the cascade can be used, e.g. a gradient based on theme colors.
It also has disadvantages:
Preview URLs may be discovered only after stylesheets are fetched and parsed, leaving less time for the preview to appear before the selected image.
This doesn't make sense. Rendering anything needs to wait for the cascade anyway.
Keeping the preview separate from the image's source attributes makes it easier for the preview and selected image to become mismatched.
People can use attr() etc, or opt to use the style attribute directly if they want tight coupling. I'm not sure people would always want the image source and preview to be tightly coupled.
Cascade or query changes may replace a preview while loading, causing requests or decoding work to be restarted or discarded.
Also not a strong case. This is also true for background images. Hopefully people would use inline data/gradient/etc images or images that are very quick to load.
Without a reflected HTMLImageElement property, scripts must read and update the preview through styles instead of the image API.
People can use the style property if they want it inline and close to the image, but they won't be required to do so.
It's a bit orthogonal.
Customizing the transitions and relationship between the states/images seems like a good idea for advanced users,
but what I'm saying here is that this whole declaration of the preview image should be a CSS feature, like yet-another CSS image in addition to background-image, border-image. That image would have some default behavior of how it's replaced etc, and then something like #1405 can be used to customize that behavior.
If we had #1405, would you even need a new prop? It could just be content or background-image on one of those proposed pseudos.
I like #1405 as a customization but maybe it's a bit low level as the only way to achieve this? Seems to me that a preview-image with a good default behavior would be better for most cases rather than asking people to customize it from scratch.
.... Another way to use image previews is with a sprite map and object-view-box. I am curious how that would look like with an HTML attribute, but it's a no brainer in css.
Activity
noamr commentedon Nov 12, 2026
Olga Gerchikov (@ogerchikov) Alex Russell (@slightlyoff)
Compare HTML and CSS alternatives for image previews (#1442)
jakearchibald commentedon Nov 26, 2026
Noam Rosenthal (@noamr) I thought in a similar direction here #1405
noamr commentedon Nov 26, 2026
It's a bit orthogonal.
Customizing the transitions and relationship between the states/images seems like a good idea for advanced users,
but what I'm saying here is that this whole declaration of the preview image should be a CSS feature, like yet-another CSS image in addition to
background-image,border-image. That image would have some default behavior of how it's replaced etc, and then something like #1405 can be used to customize that behavior.jakearchibald commentedon Nov 26, 2026
If we had #1405, would you even need a new prop? It could just be
contentorbackground-imageon one of those proposed pseudos.noamr commentedon Nov 26, 2026
I like #1405 as a customization but maybe it's a bit low level as the only way to achieve this? Seems to me that a
preview-imagewith a good default behavior would be better for most cases rather than asking people to customize it from scratch.jakearchibald commentedon Nov 26, 2026
Fair. I don't mind either way on that.
noamr commentedon Nov 26, 2026
.... Another way to use image previews is with a sprite map and object-view-box. I am curious how that would look like with an HTML attribute, but it's a no brainer in css.