-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Controlling the appearance of images being loaded #3631
Comments
Additionally:
|
This placeholder can also be relevant for |
I strongly agree that, at minimum, giving a control over "just display the alt as inline text" vs "show a box with some placeholder" is important, and that it would be great to control the placeholder as well; tons of sites are doing this manually right now, so it's clearly an attractive cowpath for us to pave. And yeah, whatever we end up doing, it needs to work on both I would be remiss at this point if I didn't mention FLIF; if we just implemented that ("just"), there'd be no need for a low-src, you can just display whatever prefix of the file you've downloaded so far. (It even supports animation now! That's new and exciting!) |
Apparently there used to be a
https://html.spec.whatwg.org/multipage/obsolete.html#attr-img-lowsrc |
I can imagine a few kinds of image placeholders that authors may want, for the case of lazy loading or slow loading:
For the case of an image failing to load or images being disabled, they may additionally want:
I think we should keep these cases a bit separate. As far as I am aware, no popular website uses text as the placeholder for an image while loading is in progress. FLIF is a neat way to address the slow-loading case, but it doesn't really work for the browser lazy loading case (in the rare case where the user's scrolling outpaces the browser's loading speed, particularly where the issue is latency rather than bandwidth) and it may not produce the desired aesthetic effect. |
Another placeholder technique:
I think a solid color and gradient are sufficiently handled using CSS, but other ideas could be explored. I suppose SVG could be used. For the other cases, a new attribute like I think using |
@zcorpan For my edification, how do you define a color or gradient placeholder for an image using CSS? Is there a CSS pseudo-class by this? If it's by setting an always-on background, that doesn't work for images with transparency. I tend to agree that a new attribute is better than reusing |
I was thinking of using 'background', but as you point out it would need to be turned off when the image is loaded. Also, it wouldn't work right if there's padding on the image. Adding pseudo-classes for different states could help with styling, like https://developer.mozilla.org/en-US/docs/Web/CSS/:-moz-loading . That combined with 'background', or maybe 'content' if that should work for normal elements. |
Another placeholder technique that seems to be gaining traction is using a blurhash: https://github.com/woltapp/blurhash We could add a single attribute to |
The appearance of images with no So this proposal needs to cover both selector hooks allowing authors to style images in their various states, and the default UA style rules. |
Additionally:
|
The topic of how images can be presented while they are loading was recently brought up in an issue about loading images lazily. This seems like a discussion worth its own issue, since images can often be observed loading in the viewport even when they are not doing so lazily.
Here's a brief summary of the points made in that issue:
@domenic mentioned the possibility of bringing back the
lowsrc
attribute, which was previously used to display a smaller version of an image before the larger one insrc
had loaded.Some comments discussed the use of CSS to display a placeholder. @othermaciej mentioned that a "CSS
background-image
with adata:
URL seems like a pretty inelegant (and potentially inefficient) way to do it".I added that some sites may be more inclined to use a solid colour - likely the dominant one from the loading image - rather than a smaller version of the image, and that CSS may not be the best way to supply either a placeholder image or colour given a strict CSP that forbids inline styles.
At the moment, some browsers display a blank box while others show the text of the
alt
attribute until an image has loaded. I believe it could be helpful to give developers a way to control the appearance of loading images that does not depend on either JS or CSS, making it possible for the browser to paint the placeholder at the earliest possible time and improve perceived loading speed.The text was updated successfully, but these errors were encountered: