October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

HTML Picture Element: How to Serve Responsive Images

Learn when to use HTML picture for art direction or formats, when img srcset is enough, and how to size candidates and keep a fallback.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use <picture> when an image needs a different crop or format for different conditions; use <img srcset> with sizes when the composition stays the same and the browser should choose an appropriate resolution. In either case, keep an <img> with useful alternative text and dimensions as the semantic image and fallback.

Choose between <picture> and <img srcset>

The choice depends on what changes between image candidates:

As an Amazon Associate I earn from qualifying purchases.

  • Different composition or crop: use <picture> with media-conditioned <source> elements. This is art direction.
  • Same composition, different pixel dimensions: put width candidates in srcset on an <img>, and use sizes to describe the image’s rendered slot.
  • Different file formats: use <picture> to offer format alternatives, with the ordinary image in the <img> as fallback.

MDN describes <picture> as containing zero or more <source> elements and one <img> to offer alternatives for different display or device scenarios: MDN’s picture element reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use srcset and sizes for resolution switching

When the image itself does not change, provide multiple widths. The browser uses the width candidates and the expected rendered slot in sizes to select an appropriate source.

<img
  src="landscape-800.jpg"
  srcset="landscape-480.jpg 480w,
          landscape-800.jpg 800w,
          landscape-1200.jpg 1200w"
  sizes="(max-width: 600px) 100vw,
         800px"
  width="1200"
  height="800"
  alt="A kayaker crossing a lake at sunrise">

The 800px value and 600px breakpoint are illustrative. Replace them with the slot sizes and breakpoints your actual CSS layout uses. With w descriptors, sizes describes the expected rendered width, not the physical width of an image file. Use media-conditioned slot widths followed by an unconditional final size.

When density descriptors are simpler

For an image rendered at fixed dimensions where the candidates differ only by display density, srcset can use density descriptors such as 2x. Do not mix w and x descriptors in one candidate list. Density candidates do not use sizes as a selection control.

Use picture for art direction

When a narrow layout needs a different crop or composition—not merely a smaller copy of the same image—put the specific media condition in a <source> and retain the default image in the final <img>.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option
<picture>
  <source
    media="(max-width: 600px)"
    srcset="portrait-crop.jpg">
  <img
    src="wide-landscape.jpg"
    width="1200"
    height="800"
    alt="A kayaker crossing a lake at sunrise">
</picture>

Put the more specific intended conditions before broader alternatives. The browser examines sources and uses the first suitable one; if none is usable, it displays the <img> source. Write the alt text for the image’s meaning and purpose, not to explain how the source changes at a breakpoint.

Offer modern formats with a fallback

When the image content and crop are the same but you have encoded alternatives, offer them in preference order and put a broadly usable fallback in <img>.

<picture>
  <source srcset="scene.avif" type="image/avif">
  <source srcset="scene.webp" type="image/webp">
  <img src="scene.jpg" width="1200" height="800" alt="A kayaker crossing a lake at sunrise">
</picture>

A browser skips a source when it does not support its declared type, then considers later sources and ultimately the <img> fallback. Ensure that each file is actually encoded in the format declared and that the server returns the correct MIME type. Browser and deployment support can vary; the fallback is part of the pattern, not an assumption that every environment supports every format.

Keep the image accessible and prevent layout shifts

  • Keep the <img> inside <picture>; it is required and carries the alternative text and dimensions.
  • Give informative images concise, meaningful alt text. If an image is purely decorative, use an empty alt value rather than describing visual details that add no information.
  • Set intrinsic width and height on the <img> where appropriate so the browser can reserve space while the image loads.
  • Use a source’s media condition for a genuine composition change. If only resolution changes, srcset and sizes on the image express that job directly.

Check candidate sizing against the real layout

  1. Inspect the CSS layout at its actual breakpoints and determine how wide the image slot is at each one.
  2. Write sizes to describe those rendered slot widths, including a final unconditional size. For example, if an image fills the viewport only on small screens but occupies half the content column on wider screens, do not claim it fills the full viewport at every width.
  3. Check the intrinsic dimensions and actual encoding of each candidate, then test the media conditions at the layout breakpoints where they are intended to apply.
  4. Verify that the image loads as expected, the fallback works, and its alternative text is appropriate.

A misleading sizes value can cause the browser to select a larger file than the layout needs. Appropriate candidate selection can reduce unnecessary image transfer, but the actual effect depends on the assets, layout, network, and browser; no fixed speed or file-size improvement applies universally.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Troubleshoot common responsive-image mistakes

The browser downloads a larger image than expected

Check whether sizes describes the actual rendered slot rather than the viewport or the source file’s dimensions. Update its media conditions to match the CSS layout.

The mobile crop never appears

Confirm that the <source> has the intended media condition, that it precedes the fallback <img>, and that its file is available. Use art direction only where the composition should change.

Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

A format alternative is skipped

Check the declared type against the file’s actual encoding and the server’s MIME type. Keep subsequent alternatives and the <img> fallback in place.

The markup has no working fallback

Include one <img> as the final child of each <picture>. It supplies the fallback source, dimensions, and alternative text.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The srcset list behaves unpredictably

Use either width descriptors such as 480w or density descriptors such as 2x within a given srcset list, not both. Use sizes with width descriptors when the rendered slot varies.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If you need a screenshot of how a page renders rather than responsive-image markup for your site, ScreenshotNeo is a website screenshot API and MCP server. A single GET request captures a URL as an image or PDF; use this cURL example to save a WebP screenshot:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for request options. It accepts cookie and consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; these steps can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers report the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf for AI agents. The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Sign up for free.

Frequently Asked Questions

Should every responsive image use a picture element?

No. Use <img srcset> for the same composition at different resolutions; reserve <picture> for art direction or format alternatives.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Does sizes set the displayed width of an image?

No. It tells the browser the expected rendered slot width for width-descriptor candidates; CSS determines the rendered layout.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.