The img Element and How src Works
The image element is a void element with two required attributes, and the second one is the one most people leave out. Its behaviour on failure is worth understanding.
Images, alt text, video and audio, and getting responsive images right without a framework.
The image element is a void element with two required attributes, and the second one is the one most people leave out. Its behaviour on failure is worth understanding.
The hardest part of alt text is knowing when to write nothing at all. An empty alt attribute is often the correct answer, and it is not the same as omitting it.
Images are usually the largest thing on a page, so format choice has more effect on load time than almost any other decision you make.
Serving one large image to every device wastes bandwidth on phones and looks soft on high density screens. Two attributes let the browser choose properly.
The picture element is not a better srcset. It answers a different question, and using it for the wrong one produces markup that is harder to maintain for no gain.
A caption and alt text do different jobs and should say different things. The figure element is what ties a caption to the thing it describes.
One attribute defers images until they are needed, and applying it to every image on the page is a reliable way to make the page feel slower.
For years the advice was to leave dimensions out of the markup. That advice reversed, and the reason is a metric that affects both users and rankings.
SVG can be embedded three ways and the choice is not cosmetic. Only one of them lets CSS reach inside the graphic.
The rule is simple and often ignored. If the image carries information it goes in the markup, and if it is decoration it goes in the stylesheet.
Video plays natively in every browser with no plugin. The attributes are simple, and one of them will silently refuse to work unless paired with another.
The audio element is the simpler sibling of video and follows the same rules. The most valuable thing you can add to it is not a player feature at all.