You can style alt text like any other text
In the You can style alt text like any other text article, Andy Bell showcases how the alt test of images can be styled with CSS.
And then goes on to provide a smooth gracefully degrading experience by leveraging JavaScript to style image loading errors differently than successfully loaded images.
I like that CSS gives us plenty of opportunities to add finer details when we want them. One of those finer details is making the experience of an image not loading a little better.
The alt
text is surfaced on the page when an image fails to load.
It’s yet another reason to write good alt text and really hone your skills in creating a user-focused experience by being descriptive.
What’s happening here is I’m hooking a function up to the<img>
’s built-inonerror
event. When that event fires, I’m setting adata-img-loading-error
attribute.
(via)