Skip to content

[Image Preview for HTML Images] Better consideration to the CSS alternative #1440

Open

Description

@noamr

(Responding to points in the explainer)

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.

Activity

  1. added
    Image Preview
    on Nov 12, 2026
  2. jakearchibald commented on Nov 26, 2026

    @jakearchibald

    Noam Rosenthal (@noamr) I thought in a similar direction here #1405

  3. noamr commented on Nov 26, 2026

    @noamr
    Author

    Noam Rosenthal (@noamr) I thought in a similar direction here #1405

    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.

  4. jakearchibald commented on Nov 26, 2026

    @jakearchibald

    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.

  5. noamr commented on Nov 26, 2026

    @noamr
    Author

    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.

  6. jakearchibald commented on Nov 26, 2026

    @jakearchibald

    Fair. I don't mind either way on that.

  7. noamr commented on Nov 26, 2026

    @noamr
    Author

    .... 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Image Preview

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions