What is the picture element for responsive images in HTML5?
The
element is used. 5. Key use cases include art direction, serving high-DPI images, and delivering modern formats like WebP or AVIF with JPEG/PNG fallbacks. 6. The
tag must always be included as the last child for accessibility and compatibility. 7. Unlike simple responsive scaling,

The <picture></picture> element in HTML5 is a container used to define multiple sources for an image, allowing the browser to choose the most appropriate image based on device characteristics like screen size, resolution, or pixel density. It’s primarily used for responsive images, helping deliver optimized visuals for different viewing contexts—improving performance and user experience.

How the <picture></picture> Element Works
Instead of replacing the <img src="/static/imghw/default1.png" data-src="small.jpg" class="lazy" alt="What is the picture element for responsive images in HTML5?" > tag, the <picture></picture> element acts as a wrapper that provides a set of image sources. The actual image is still rendered using the <img src="/static/imghw/default1.png" data-src="small.jpg" class="lazy" alt="What is the picture element for responsive images in HTML5?" > element inside <picture></picture>. The browser looks at the sources defined in <source></source> elements and selects the best match, falling back to the <img src="/static/imghw/default1.png" data-src="small.jpg" class="lazy" alt="What is the picture element for responsive images in HTML5?" > if no sources apply.
<picture> <source media="(min-width: 800px)" srcset="large.jpg"> <source media="(min-width: 400px)" srcset="medium.jpg"> <img src="/static/imghw/default1.png" data-src="small.jpg" class="lazy" alt="Descriptive text"> </picture>
In this example:

- Devices with a screen width of 800px or more get
large.jpg - Screens between 400px and 799px get
medium.jpg - Smaller screens get
small.jpgas the default
Key Use Cases
- Art direction: Serve differently cropped or composed images for various screen sizes.
- High-DPI displays: Deliver higher-resolution images (e.g., for Retina screens) using
srcsetandsizeswithin<source>. - Modern image formats: Provide next-gen formats like WebP or AVIF while falling back to JPEG or PNG.
Example with format support:
<picture> <source type="image/webp" srcset="image.webp"> <source type="image/avif" srcset="image.avif"> <img src="/static/imghw/default1.png" data-src="image.jpg" class="lazy" alt="Fallback image"> </picture>
Here, browsers that support WebP or AVIF will load those (smaller, more efficient) formats; others fall back to the JPEG.

Important Notes
- The
<picture></picture>element is not for general responsive scaling (likeimg { max-width: 100% }). It’s for conditional image loading. - Always include an
<img alt="What is the picture element for responsive images in HTML5?" >tag as the last child—it’s required for accessibility and fallback. - Order matters: sources are evaluated in order, and the first matching one is used.
Basically, <picture></picture> gives developers more control over which image resource is delivered, making it a powerful tool for responsive design and performance optimization.
The above is the detailed content of What is the picture element for responsive images in HTML5?. For more information, please follow other related articles on the PHP Chinese website!
Hot AI Tools
Undress AI Tool
Undress images for free
AI Clothes Remover
Online AI tool for removing clothes from photos.
Undresser.AI Undress
AI-powered app for creating realistic nude photos
ArtGPT
AI image generator for creative art from text prompts.
Stock Market GPT
AI powered investment research for smarter decisions
Hot Article
Popular tool
Notepad++7.3.1
Easy-to-use and free code editor
SublimeText3 Chinese version
Chinese version, very easy to use
Zend Studio 13.0.1
Powerful PHP integrated development environment
Dreamweaver CS6
Visual web development tools
SublimeText3 Mac version
God-level code editing software (SublimeText3)
Hot Topics
20521
7
13633
4
How to center an image vertically in HTML5? (Layout techniques)
Mar 07, 2026 am 02:05 AM
Flexbox is the most stable for centered images. The key is to set display:flex and align-items:center in the parent container and specify the height; using place-items:center for Grid is more concise; absolute positioning requires top:50% with transform:translateY(-50%); vertical-align is invalid for block-level centering.
How to use SVG graphics directly in HTML5? (Inline SVG)
Mar 07, 2026 am 01:40 AM
SVG tags can be written directly into HTML without any external reference. The core of InlineSVG is to use it as an ordinary HTML element. The browser supports it natively. It does not require additional loading, does not trigger HTTP requests, and can be directly controlled by CSS and JS. A common mistake is to insert it as an image - this way you lose the advantage of inlining, the style cannot penetrate, and JS cannot get inside. Directly copy the SVG source code (exported from Figma, or handwritten), and paste it into an HTML file or any container. Make sure the beginning is, the end is, and there is no DOCTYPE in the middle. Delete useless attributes such as xmlns="http://www.





