#Prevent original or png image format in <Picture>
3 messages · Page 1 of 1 (latest)
Astro’s <Picture /> component always generates a fallback <img> tag using the original image format (e.g., PNG if your source is a PNG), in addition to the formats you specify in the formats prop (like avif and webp). This fallback is included to ensure maximum browser compatibility.
Currently, there is no documented way to prevent the fallback image (the original format) from being generated or included in the output. The formats prop only controls the <source> elements, not the fallback <img> tag, which will always use the original format by default. The fallbackFormat prop allows you to change the fallback format (e.g., from PNG to JPG), but you cannot remove the fallback entirely or restrict it to only the formats in the formats array according to the official documentation:
Format to use as a fallback value for the
<img>tag. Defaults to.pngfor static images (or.jpgif the image is a JPG),.giffor animated images, and.svgfor SVG files.
Picture properties - fallbackFormat
So, while you can change the fallback format, you cannot prevent the fallback <img> from being generated altogether. If you only want to serve specific formats without a fallback, you would need to create a custom image component using the getImage() function and manually construct your <picture> element, but this approach is not covered in the official documentation for omitting the fallback <img> entirely.