HTML: Picture Tag

By Xah Lee. Date: . Last updated: .

html picture tag

what is HTML picture tag

ai answer

The HTML <picture> element is a container used to provide multiple versions of an image so the browser can choose the most suitable one.

Purpose

It lets you serve different images based on:

The browser looks at the <source> elements inside <picture>, picks the best match, and displays it. If nothing matches (or the browser is very old), it falls back to the <img> element.

Basic Syntax

<picture>
  <source media="(min-width: 800px)" srcset="large.jpg">
  <source media="(min-width: 400px)" srcset="medium.jpg">
  <img src="small.jpg" alt="Description of the image">
</picture>

Common Use Cases

1. Different image formats (modern formats with fallback)

<picture>
  <source type="image/avif" srcset="photo.avif">
  <source type="image/webp" srcset="photo.webp">
  <img src="photo.jpg" alt="A photo">
</picture>

2. Art direction (completely different crops for different screens)

<picture>
  <source media="(min-width: 768px)" srcset="wide-landscape.jpg">
  <img src="tall-portrait.jpg" alt="A photo">
</picture>

Key Points

In short: use <picture> when you need more control than a simple <img> with srcset/sizes (especially for art direction or format switching).

The picture tag is similar to the Image Tag. It is for inline image with multiple sources for browser to chose a right size for user's device. It is invented sometimes around 2015.

The picture tag must contain zero or more source tags, and and must have one img tag at the end.


<picture>
 <source media="(min-width:1000px)" srcset="cat_big.jpg">
 <source media="(min-width:500px)" srcset="cat_small.jpg">
 <img src="cat.jpg" alt="cat">
</picture>

See also: CSS: @media query

HTML image tags