One Picture Element Can Offer Different Crops
The photograph at the top of a web page can show a wide crop on a broad display and a tighter crop when the browser has less room. The WHATWG HTML standard allows the page to supply those alternatives through picture and gives the contained img element the job of displaying the chosen image. The image stays in the same place in the article; the file supplying its visible detail can change.

Suppose a page opens with a photograph of an orange poppy in a meadow. The wide crop leaves space for the field around the flower. The tight crop brings the whole bloom forward, leaving less of the field in view. The page would supply separately framed files, so the browser would have a choice of compositions before it had anything to draw. The standard calls changing the image content to suit the available space art direction.
Which element puts the crop on the page?
The easy mistake is to read picture as the name of the thing that draws the photograph. The WHATWG standard says, "Also, the picture element itself does not display anything"; the container gives the enclosed img a choice of URLs. Those URLs are the addresses of the files supplied by the page. The address can change while the element that presents the image stays the same.
The order of the supplied markup gives the parts separate jobs. The picture container takes the optional source entries before the img element. Each source can put forward a set of image files for a particular situation. The img at the end represents the image on the page. In the poppy example, that is the same img whether the rendered result shows the surrounding meadow or brings the petals close.
- Supplied markup
- picture groups the choices around img
- source offers a candidate crop
- img represents the image
- Rendered result in a browser using picture
- The container makes no separate picture of its own
- The candidate can supply the image without adding another image to the page
- The chosen crop appears through img
There is a difference between what is supplied and what is selected. Imagine that the page supplies only versions of the wide photograph at different resolutions. A browser choosing among those files would still have the same meadow composition to display. A tight composition only enters the choice when the page supplies it. For art direction, WHATWG allows a page to supply an alternative image, such as a different crop of the original photograph.
That distinction can be useful when a wide crop still appears in a narrow space. An image can fit into the space and yet leave the flower small within the frame. In the hypothetical page, the large flower comes from selecting the tight file. The narrow space explains why that file is offered there; it does not describe which petals or leaves the file contains.
What tells the browser where the tighter crop belongs?
A source inside picture can carry a media attribute, a condition the browser checks against its environment. One such condition is a maximum viewport width. The viewport is the part of the browser available for displaying the page; the condition in this example is about the width of that area, not the measured width of the photograph. A condition on the viewport can therefore match in a narrow desktop window as well as on a narrow mobile display.
Suppose the poppy page offers its tight crop under a maximum-width condition, with the wide file supplied on img. The media condition says when the close view belongs. The srcset on the same source gives the browser the address of the close view. If the condition matches and the offered file is the only eligible candidate in that set, it supplies the picture of the bloom. Above the width limit, the browser skips that entry and the wide view supplied by img is available.
- Viewport:
- The browser area available to the page.
- media:
- The condition a source can attach to its candidates.
- srcset:
- The attribute listing the candidate image files for a source inside picture.
When several otherwise eligible entries have width conditions, order has a visible result. WHATWG’s art-direction example selects the first source whose media query matches, then selects a file from that entry. Suppose a page has separate maximum-width conditions for a close crop and a medium crop. A very narrow viewport can satisfy both maximums. With the medium crop first, that viewport can get the medium crop; with the close crop first, the same width can get the close crop. The browser does not rank matching width conditions by how narrowly they were drawn.
Changing the viewport need not mean opening another page. The HTML standard says a browser using picture reacts to changes in its environment and encourages browsers to run image selection again when the viewport changes size. In the poppy example, making the window wider can make the tight crop’s condition stop matching. The environment has changed, though the markup and the supplied files can all stay as they were.
A page can also change how much of the viewport a photograph occupies as the layout changes. The WHATWG standard illustrates this with a page on which an image spans the viewport at a narrow width and takes only half of it at a wider width. The image can then be narrower on the wider viewport. For the poppy page, this means a viewport condition can describe where a particular composition belongs even when the space reserved for it does not grow in step with the window.
That layout information has a separate place in HTML. The sizes attribute describes the expected width of the displayed image for the purposes of selecting among files labelled with their widths. It can help the browser choose among copies of the same framing at different resolutions. In the poppy example, media qualifies the tight crop and sizes, if supplied with width-labelled files for that crop, helps the browser choose a version of it. A larger file from that set still shows the close view.
Where does the image come from if no source is selected?
When the picture alternatives yield no selected source, the img element supplies its own image choices. WHATWG specifies that the img element’s srcset, and its src where width descriptors are not used, contribute to the set in that case. A width descriptor is an annotation of a candidate file’s width. In the simple poppy example there are no such annotations and the wide file is the only address supplied on img. It can therefore be the default view outside the narrow condition.
The default need not be the wide composition on every page. Suppose an editor supplies the close view on img and puts the meadow view in a source that applies at a minimum viewport width. Under that arrangement, a broad display can qualify for the meadow view; below the threshold the close view is the default. The fallback follows where the files were put in the supplied markup. The standard does not assign any particular framing to img.
- Eligibility: A source whose media condition fails is skipped.
- No eligible source: The image choices come from img itself.
- Simple default: Where img supplies only src, that address is the default file.
There are also different ways for a proposed image to fall out of the process. A source whose condition does not match is skipped at selection. A file chosen from a matching source can instead fail when the browser tries to load or process it. The standard’s image update steps allow the request to be marked broken and an error to be reported. The no-match route to the default crop is a selection rule, rather than a promise that the same fallback crop appears after a failed download.
The choice can affect the shape of the image as well as what appears inside it. Suppose the meadow file is a shallow rectangle and the close view is taller in proportion to its width. WHATWG allows a selected source to supply its own width and height attributes for determining the dimensions and aspect ratio of the img. Aspect ratio is the relationship of width to height. That information can describe the proportions of the alternative without requiring the page to create a separate image element to display it.
The practical distinction is between the default address written on img and the address of the image currently used by that element. WHATWG defines currentSrc, a property a browser exposes for the img element, as the URL of its current image request. A wide default can still be present in the page source while currentSrc identifies the tight crop. The property reports an address; it does not identify which rectangle of the original photograph that file contains.
Frequently Asked Questions
Can a picture element offer different file formats as well as different crops?
The picture element can offer different formats for a crop through alternative source entries. The HTML standard defines type as the format information that allows the browser to skip an entry for a format it does not support. If type is absent and an unsupported format is only discovered after selection, the standard says the browser will not move to another source on that account.
Does the src attribute on source identify an image inside picture?
The src attribute has no meaning on a source inside picture. WHATWG assigns the file list on that element to srcset. That attribute can contain a single candidate; the plural idea of a set does not require several image files on every entry.
Can screen pixel density influence image choice in HTML?
HTML permits a srcset entry to describe the pixel density of its file, meaning how much image detail it offers relative to its display size. This allows choices at different densities for the same framing. The WHATWG standard shows how a page can combine a choice of crop for available width with a choice of density within the selected crop.
Which element carries the text alternative inside picture?
The img element carries the text alternative in its alt attribute. The text provides equivalent content for someone who cannot process the image or has image loading switched off. A separate crop offered by a source inside picture does not carry a separate alt attribute for that variant.
Can the HTML source element also appear inside video or audio?
The HTML source element can offer alternative resources for video or audio. In that setting src gives the address of the media resource. WHATWG notes another difference: a media condition on source is evaluated only once in the media element’s resource selection process, whereas picture responds to environmental changes.
Sources
- WHATWG: HTML Living Standard: The picture element (Last Updated 27 November 2026)
- WHATWG: HTML Living Standard: Embedded content (Last Updated 27 November 2026)
- WHATWG: HTML Living Standard: Images (Last Updated 27 November 2026)