Skip to content

[selectors-4] additional resource state pseudo-classes for img / picture elements #7467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
voxpelli opened this issue Jul 7, 2022 · 6 comments

Comments

@voxpelli
Copy link

voxpelli commented Jul 7, 2022

The Resource State Pseudo-classes section mentions (emphasis mine):

The pseudo-classes in this section apply to elements that represent loaded resources, particularly images/videos

Yet none of the currently defined pseudo classes seems to actually apply to any images.

Following up on a recent popular tweet that used onerror on img-tags to style failed images, I would like to mimic #3821 and resurrect a few of the pseudo-classes suggested in #3134

Primarily I would like to see:

  • :failed – a replacement for the use of onerror to style images that fail to load
  • :loading – a way to style images that are in the process of loading (would include both downloading and decoding I think)

Could also be useful to support the existing:

  • :stalled– as images on bad internet connections can very much stall to load as well, especially a progressive JPEG which could me stuck in a low quality state.
@hober hober added the selectors-4 Current Work label Aug 11, 2022
@fantasai
Copy link
Collaborator

fantasai commented Nov 7, 2022

Makes sense to me. I wonder if :buffering and :loading should be interchangeable?

Also :failed should probably be :loading-failed, since lots of things can fail in a lot of different ways. :)

Agenda+ to ask the CSSWG what it wants to do here.

@css-meeting-bot
Copy link
Member

The CSS Working Group just discussed Additional resource-state pseudo-classes for img/picture.

The full IRC log of that discussion <TabAtkins> Topic: Additional resource-state pseudo-classes for img/picture
<TabAtkins> fantasai: someone asked about pseudos for images to indicate whtehr they're loading, failed, stalled
<TabAtkins> fantasai: So does the WG think this is reasonable?
<dbaron> I think Gecko has internal pseudo-classes that do this
<TabAtkins> fantasai: do we make loading & buffering both amtch when a video is trying to buffer and when an image is loading?
<TabAtkins> TabAtkins: Like allow both to apply to either condition?
<TabAtkins> fantasai: Yeah they're both loading, tho i'm not sure if the words are appropraite
<TabAtkins> TabAtkins: I'm happy to defer that to editors
<bradk> applies to any element that can take time loading, eg iframes?
<TabAtkins> Rossen_: Sounds like there's general approval, should we reoslve on "yes, details TBD"?
<bradk> +1
<bramus> +1
<chrishtr> +1
<TabAtkins> fantasai: We can propose edits and come back.

@06b
Copy link

06b commented Jan 31, 2023

If it is any help for whoever creates the proposal, Firefox has the :-moz-broken pseudo-class which could be used as a model for broken images. This allows for the use case of setting a fallback via content: url() only when the image fails (as it currently always replaces an element as noted in #2831).

img:-moz-broken {
    content: url("placeholder.jpg");
}

@Crissov
Copy link
Contributor

Crissov commented Feb 1, 2023

I’d like to suggest that HTTP status codes, particularly those commonly encountered in response to GET requests, be associated with some of the pseudo-classes proposed herein and in #3134. They may also inform the selection of some other states that may have frontend presentation, e.g.:

  • :partial — 206, 416
  • :complete — 200
  • :broken — 404, 410
  • :failed – 401, 402, 403, 406, …; 500
  • :loading – 30x, before receiving 200 or 40x
  • :stalled – 503, 504
  • :cached — 304
  • :redirected — 300, 301, 302, 307, 308 encountered in the request process, i.e. not mutually exclusive with most of the other pseudoclasses

@Mouvedia
Copy link

Mouvedia commented Jan 20, 2024

  • :loading – 30x, before receiving 200 or 40x

Something that might be worth discussing is whether it should copy :-moz-loading matching mechanism or not.
i.e. match elements which are waiting to be loaded

Note that images that are in the process of loading are not matched by this pseudo-class.

which sounds more like :queued to me.


Concerning ad blockers, is a :-moz-suppressed alternative missing as well?

@Crissov
Copy link
Contributor

Crissov commented Jan 13, 2025

I guess there is also value in something like :delayed or :scheduled for lazy-loading scenarios.

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

No branches or pull requests

9 participants