Short answer: Inside a <picture> element, put a <source> with type="image/avif" first, a <source> with type="image/webp" second, and a plain <img> pointing at the PNG or JPG last. The browser uses the first source whose type it supports and falls back to the <img> when none match. Give each one a srcset with 1x and 2x files, and put alt, width, height and loading on the <img>.
Say you are handing a landing-page hero to a developer who wants AVIF and WebP with a safe fallback. This is the markup to aim for:
<picture>
<source type="image/avif" srcset="hero.avif 1x, [email protected] 2x">
<source type="image/webp" srcset="hero.webp 1x, [email protected] 2x">
<img src="hero.png"
srcset="hero.png 1x, [email protected] 2x"
width="640" height="360"
alt="Revenue dashboard with a line chart and three summary cards"
fetchpriority="high" decoding="async">
</picture>What does the picture element do?#
The <picture> element offers the browser several versions of one image and lets it choose one it can use. It holds zero or more <source> elements followed by one <img> (MDN: picture).
The <img> is required and does two jobs:
- It is the fallback. If no source matches, the browser loads the
<img>'ssrc. - It is the image on the page. Whichever source wins is shown in its place, so
alt,width,heightand your CSS go on the<img>, not on<picture>.
In what order should AVIF, WebP and the fallback go?#
AVIF first, WebP second, PNG or JPG in the <img>. The browser reads the sources in order and skips any whose type, the format's MIME type, it doesn't support.
| Position | Element | type |
Who ends up with it |
|---|---|---|---|
| 1 | <source> |
image/avif |
Browsers that support AVIF |
| 2 | <source> |
image/webp |
Browsers that support WebP but not AVIF |
| 3 | <img> |
none | Everyone else, including browsers without <picture> |
The browser doesn't compare file sizes. If your AVIF comes out larger than the WebP, AVIF-capable browsers still download the larger file. Check the exported sizes and drop a format that isn't pulling its weight. Our AVIF vs WebP vs PNG comparison covers which formats suit which UI assets.
Always write the type. Without it, the browser has nothing to skip on, and the format fallback doesn't happen.
Do you still need a fallback?#
Yes, and it's cheap. As of October 2026, caniuse lists full AVIF support from Chrome 85, Edge 121, Firefox 93 and Safari 16.4 (16.0 on iOS), and full WebP support from Safari 16.0 (14 on iOS), the last of the four to add it. Both are above 95% of global usage. MDN's image format guide still recommends a JPEG or PNG fallback for both, and browsers that show the newer formats never request it.
How do you add 1x and 2x files with srcset?#
Give each <source>, and the <img>, a srcset that lists the 1x and 2x files, each followed by an x descriptor. The browser usually takes the 1x file on standard screens and the 2x file on high-density ones, but it makes the final choice.
The rules, from MDN's picture and img references:
- A density descriptor is a number followed by
x, such as2x. A candidate with no descriptor counts as1x. - Don't mix
wandxin onesrcset, and don't list the same descriptor twice. - Keep
srcon the<img>. Withxdescriptors it also counts as the 1x candidate, and it is what loads when no source matches.
Selection happens in two passes. The browser picks a source by type, then a file from that source's srcset by density. An AVIF-capable browser on a high-density screen will usually get [email protected].
x descriptors fit images that render at one fixed CSS size, like a logo or a pricing card. If the image changes width with the layout, such as a full-width hero, use w descriptors with sizes instead. You write those lists by hand, because UIXport's markup uses x descriptors only. For the pixel math, see 1x, 2x and 3x explained.
What goes on the img: width, height, alt and loading?#
Set width and height to the 1x size in CSS pixels, write an alt that describes the image, and add loading="lazy" only below the fold. decoding is optional.
width and height. Whole numbers, no units. In Figma, that is the frame's width and height. The browser works out the aspect ratio from them before the file arrives and reserves the space, so the page doesn't jump (MDN: img). If your CSS resizes the image, add height: auto so the ratio holds (web.dev: optimize CLS).
alt. Describe what the image shows, or what it does, in this context. For pure decoration, use alt="", which MDN says marks the image as not a key part of the content.
loading. loading="lazy" defers the download until the image nears the viewport. web.dev's lazy-loading guide advises against lazy-loading images likely to be in view on load, and its LCP guide says never to lazy-load the LCP image, the largest image or text block in view, which sets your Largest Contentful Paint time. For that image, leave loading out and consider fetchpriority="high", which the LCP guide suggests.
| Where the image sits | loading |
fetchpriority |
|---|---|---|
| Hero, or the largest image in view on load | Leave it out (eager is the default) | high |
| In view on load, but not the largest | Leave it out | Leave it out |
| Below the fold | lazy |
Leave it out |
decoding. decoding="async", in UIXport's output, lets the browser decode the image after showing the rest of the content. The default is auto.
Steps to export AVIF, WebP and PNG from Figma#
Figma's own export covers PNG, JPG, SVG and PDF, with no AVIF or WebP (Figma help). In UIXport, one frame and six format rows give you every file the markup needs, in one run. The exception: if the site's image CDN already picks AVIF, WebP or JPEG per browser (web.dev: image CDNs), hand over one high-resolution PNG and skip the picture markup.
- Name the layer. In Figma's layers panel, rename the frame to something like
hero-dashboard, using only letters, numbers, hyphens and underscores. The file names and the markup both come from this name. - Select it and open UIXport. It starts on the Exporter tab, with the frame in the list, checked.
- Set the first row. The Export as card starts with one PDF row at 1x. Change it to AVIF and 1x. AVIF is Pro: on the Free plan, a run with AVIF rows uses one of your 10 free Pro runs a month, or you can skip them.
- Add the other rows. Click Add format five times. New rows start as PNG at 1x. Set them to AVIF 2x, WEBP 1x, WEBP 2x, PNG 1x and PNG 2x.
- Suffix the 2x rows. On each 2x row, open the row menu (⋯), type
@2xin Filename suffix and click Done. Leave the 1x rows without a suffix. - Set the quality. The Quality Level slider (5 to 100, default 90) or a preset such as High (80%) applies to the AVIF and WebP rows. PNG ignores it.
- Export. Click Export Selected (N Formats). The six files arrive in
UIXport Export.zip.
On the Free plan, the WebP and PNG rows have no export limit, and the AVIF rows make the run use one free Pro run. Format details: AVIF export and WebP export.
How should you name the files so the markup matches?#
Use name.ext for 1x and [email protected] for 2x, with the same name in the files and the markup. The browser requests exactly the URLs in srcset, so a name that doesn't match is a missing image.
With the default {frame} pattern and the suffixes from step 5, you get:
| Row | Filename suffix | File |
|---|---|---|
| AVIF 1x | none | hero-dashboard.avif |
| AVIF 2x | @2x |
[email protected] |
| WEBP 1x | none | hero-dashboard.webp |
| WEBP 2x | @2x |
[email protected] |
| PNG 1x | none | hero-dashboard.png |
| PNG 2x | @2x |
[email protected] |
Three things break the match:
- No suffix on the 2x rows.
{frame}adds no scale, so both PNG rows wanthero-dashboard.png, and the second arrives ashero-dashboard (1).png. {scale}instead of a suffix. A pattern like{frame}@{scale}marks the 1x file too ([email protected]), while the markup expects a plain 1x name.- Spaces and symbols in the layer name. The Exporter keeps spaces, but the markup turns anything other than letters, numbers, hyphens and underscores into an underscore.
Hero imageexports asHero image.png, and the markup asks forHero_image.png.
Rename the layer itself. Renaming the item in the Exporter list changes the output file only, and Picture Tag reads the layer name. The batch export page lists the other naming tokens.
Steps to generate the markup with Picture Tag#
Picture Tag, in UIXport's Dev tools tab, writes the <picture> element using the file names above.
- Select the same layer. Picture Tag uses the first selected item only.
- Open Picture Tag. In the Dev tools tab, choose Picture Tag.
- Match the formats. Under Included formats, keep only what you exported. AVIF, WEBP and PNG are on by default, so untick AVIF if you skipped it.
- Match the resolutions. Under Resolutions, keep the default 1x and 2x. Add 3x only if you exported 3x files.
- Pick the fallback. The Fallback src format (PNG by default, or JPG or WebP) goes in the
<img>, and the other formats become sources. If you pick JPG or WebP, untick PNG under Included formats. Otherwise PNG becomes a<source>, every browser supports it, and your fallback never loads. - Copy the HTML. Click Copy HTML under Generated HTML Code.
For hero-dashboard with the defaults, the output looks like this:
<picture>
<source type="image/avif" srcset="hero-dashboard.avif 1x, [email protected] 2x" />
<source type="image/webp" srcset="hero-dashboard.webp 1x, [email protected] 2x" />
<img
src="hero-dashboard.png"
srcset="hero-dashboard.png 1x, [email protected] 2x"
alt="hero-dashboard"
loading="lazy"
decoding="async"
/>
</picture>Before it goes live, add the folder path to each bare file name, add width and height from the frame's 1x size (the generated <img> has neither), and replace the alt, which is the layer name. On a hero image, also remove loading="lazy".
The Picture Tag feature page lists every option.
How do you test which file the browser loaded?#
Check the selected URL, then switch formats off one at a time.
- Read
currentSrc. In the console, rundocument.querySelector('picture img').currentSrc. It returns the URL the browser selected (MDN: currentSrc). An AVIF-capable browser should return the.aviffile, or the@2xone on a high-density screen. - Turn off AVIF, then WebP. In Chrome DevTools, open the Rendering tab, check Disable AVIF image format and reload.
currentSrcshould now be the WebP file. Check Disable WebP image format too, reload, and you should get the PNG (Chrome DevTools docs). - Watch the Network panel. Filter to images. Only one file from the set should download. A 404 means a file name in the ZIP doesn't match a URL in the markup.
Picture Tag is free and has no run limit. Install UIXport from Figma Community, rename one frame, export its files and generate its <picture> element.