{ HTML Picture Element Builder }

// generate picture elements with sources and breakpoints

Build elements with multiple entries, media breakpoints, image types, and fallback tags. Export clean HTML instantly.

// SOURCE ENTRIES
📐

No source entries yet

Click + ADD SOURCE to add a <source> element, or load a preset
// GENERATED HTML
🖼️

Configure settings and sources above

Click Generate to build your <picture> element

HOW TO USE

  1. 01
    Set Fallback

    Enter the fallback <img> src, alt text, and optional width/height for the base image.

  2. 02
    Add Sources

    Click Add Source or load a preset. Configure each source with media query, type, srcset, and sizes.

  3. 03
    Generate & Copy

    Hit Generate to build the complete <picture> element. Copy and paste into your HTML.

FEATURES

Art Direction WebP / AVIF Media Queries srcset Support Lazy Loading Presets

USE CASES

  • 🖼️ Serve WebP/AVIF to modern browsers
  • 📱 Different images at mobile vs desktop
  • ⚡ Hero images with priority loading
  • 🎨 Art direction with crop variations
  • 📦 CMS/template image component code

WHAT IS THIS?

The HTML <picture> element lets browsers choose the best image format and size based on media conditions. This tool generates the boilerplate with correct attribute ordering, multiple <source> entries, and a <img> fallback.

RELATED TOOLS

FREQUENTLY ASKED QUESTIONS

What is the HTML <picture> element?

The <picture> element is an HTML container that holds multiple <source> elements and one <img> fallback. The browser evaluates each source in order and selects the first one whose media query and type conditions it satisfies.

What's the difference between srcset and <picture>?

The srcset attribute on <img> handles resolution switching — giving the browser different sizes of the same image. The <picture> element handles art direction and format switching — different crops, formats (WebP, AVIF), or images entirely depending on media conditions.

How do media queries work in <source>?

The media attribute on <source> uses standard CSS media query syntax: media="(max-width: 768px)" or media="(min-width: 1024px)". The browser uses the first matching source. Order matters — put most specific conditions first.

Should I always include a JPEG fallback?

Yes. The <img> fallback is required and is used when no <source> matches (older browsers, or no conditions match). Use a universally supported format like JPEG or PNG for the fallback to ensure all users see an image.

What is the "type" attribute on <source>?

The type attribute specifies the MIME type of the image: image/webp, image/avif, image/png, etc. If a browser doesn't support that MIME type, it skips that source and tries the next one. This enables format-based fallbacks without JavaScript.

What does fetchpriority="high" do?

The fetchpriority="high" attribute tells the browser to prioritize downloading this image over other resources. Use it only for above-the-fold hero images that are critical to the initial render. Using it on all images defeats the purpose.

When should I use loading="lazy"?

Use loading="lazy" on images that are below the fold — not visible when the page first loads. It defers loading until the user scrolls near the image. Avoid it on hero or above-the-fold images as it delays their loading unnecessarily.

What does decoding="async" do?

decoding="async" tells the browser it can decode the image off the main thread, allowing the page to continue rendering without waiting for the image to be fully decoded. It improves perceived performance and is generally safe to apply to all images.

What is the HTML <picture> Element?

The HTML <picture> element is a powerful responsive image container that gives web developers granular control over which image a browser downloads and displays. Rather than leaving the decision entirely to the browser (as with srcset alone), <picture> lets you specify exact conditions — screen size, orientation, supported formats — and serve the optimal image for each scenario.

💡 Looking for premium HTML templates and themes? MonsterONE offers unlimited downloads of responsive templates, UI kits, and web assets — worth checking out.

The Anatomy of a <picture> Element

A complete <picture> element consists of three parts: zero or more <source> elements (each representing an alternative image), and one required <img> element as the fallback. The browser reads the sources in document order and uses the first one that matches. The <img> element at the end is used either when no source matches, or in browsers that don't support <picture> at all.

<picture>
  <source media="(max-width: 767px)" srcset="hero-mobile.webp" type="image/webp">
  <source media="(max-width: 767px)" srcset="hero-mobile.jpg">
  <source srcset="hero-desktop.webp" type="image/webp">
  <img src="hero-desktop.jpg" alt="Hero image" width="1200" height="600" loading="lazy" decoding="async">
</picture>

Format Switching: WebP and AVIF

One of the most common use cases for <picture> is serving modern image formats with a legacy fallback. AVIF offers the best compression rates (up to 50% smaller than JPEG at equivalent quality), followed by WebP (25–35% smaller than JPEG). By listing AVIF first, WebP second, and JPEG last, browsers automatically download the best format they support.

The type attribute on each <source> specifies the MIME type: image/avif, image/webp, image/jpeg, or image/png. Browsers that don't recognize a MIME type simply skip to the next source — no JavaScript required.

Art Direction: Different Images for Different Screens

Art direction goes beyond resolution switching. It means serving a fundamentally different composition — a tighter crop for mobile, a wide panorama for desktop, or a portrait image for tall screens. This is only possible with <picture> and media attributes.

For example, a food photography hero might show a tight close-up of the dish on mobile, while the desktop version shows the full table setting with atmospheric background. The media attribute controls this: media="(max-width: 767px)" matches phones, while the fallback <img> handles desktop. The browser downloads only one image — the right one for the current viewport.

The srcset and sizes Attributes

Within a <source>, the srcset attribute can list multiple image URLs with either width descriptors (800w, 1600w) or pixel density descriptors (1x, 2x). When paired with a sizes attribute describing how wide the image will render, the browser selects the most appropriate resolution — downloading a smaller file on mobile and a larger one on desktop retina screens.

Performance Attributes: lazy, async, fetchpriority

Three modern attributes dramatically affect image loading performance. loading="lazy" defers off-screen images until the user scrolls near them — reducing initial page weight and Time to Interactive. decoding="async" lets the browser decode images off the main thread, preventing rendering jank. fetchpriority="high" signals that this image is critical — useful for above-the-fold hero images that should load as fast as possible.

The combination of loading="lazy" and decoding="async" is appropriate for most below-the-fold images. For hero images, use fetchpriority="high" and omit loading="lazy" to ensure the image loads at maximum priority during page initialization.

Browser Support and Progressive Enhancement

<picture> is supported by all modern browsers (Chrome, Firefox, Safari, Edge). Older browsers like Internet Explorer that don't support <picture> simply render the <img> fallback as if the wrapper element doesn't exist — which is exactly the right behavior. This makes <picture> a safe progressive enhancement: users with modern browsers get optimal images, while legacy users still see the content.

The same applies to AVIF and WebP: browsers that don't recognize the type skip those sources silently. There's no error, no JavaScript, no polyfill needed. The format negotiation is entirely declarative HTML.

Best Practices for Responsive Images

When to Use <picture> vs srcset on <img>

If you only need different resolutions of the same image (e.g., photo.jpg, photo@2x.jpg, photo@3x.jpg), use srcset directly on <img> — it's simpler. Use <picture> when you need format switching (WebP/AVIF fallbacks), art direction (different crops per breakpoint), or both. In practice, most production-grade responsive image setups benefit from <picture>.