1001Ferramentas
🖼️Utilities

Picture Tag Builder

Builds a <picture> tag with multiple <source> (modern formats like webp, avif) and an <img> fallback.



  

Picture tag with AVIF, WebP and fallback

You exported the same photo as avif, webp and jpg to save bandwidth, and now you have to recall the picture and source syntax, which format goes first, and where alt and classes belong. Getting the order wrong throws no error at all: the browser quietly serves the heaviest file while you assume the optimization landed.

The browser reads the sources top to bottom and stops at the first type it can decode, falling back to the img if none match. That is why the tool writes avif first, webp next and img last, smallest format to most compatible one. Leave the avif or the webp field blank and that line simply does not appear in the output.

The img is not just the backup plan, it is the element that actually renders, so width, height, classes and loading equals lazy all belong there rather than on picture. Adding width and height reserves the space and keeps the page from jumping. The alt text is copied verbatim, so a double quote inside it will break the attribute. Art direction, meaning a different crop per breakpoint, needs a media attribute on each source, which this form does not write.

Frequently asked questions

Does the source order really matter?
It does. The browser takes the first format it can display, so the most efficient one has to come first. Put jpg on top and nobody ever reaches the avif.
I only have webp and jpg. Now what?
Leave the avif field empty. That line drops out and you get one webp source plus the img fallback.
Where do class, width and loading go?
On the img. The picture element is only a wrapper that picks a file; the inner image is what receives styling and layout attributes.

Related Tools