#Prevent original or png image format in <Picture>

3 messages · Page 1 of 1 (latest)

crude brambleBOT
#

Hi @twilit patrol. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

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 .png for static images (or .jpg if the image is a JPG), .gif for animated images, and .svg for 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.

#

Summary:
You cannot prevent the fallback image (original format) from being generated in <Picture />—you can only change its format using fallbackFormat, not remove it or restrict it to only the formats in formats Picture component reference.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: