Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use a <picture> element to offer a JPEG XL image first and keep a broadly supported format in its nested <img> element. Browsers that do not support JPEG XL can skip that source and display a supported alternative instead.

Use a picture element with a fallback

Declare JPEG XL with the MIME type image/jxl and the usual .jxl file extension. Put a conventional image in the final <img>; that image is the fallback if none of the listed sources can be used.

<picture>
  <source srcset="photo.jxl" type="image/jxl">
  <img src="photo.jpg" alt="Describe the image">
</picture>

The type attribute tells the browser what format the source uses. A browser that does not support that format can skip it and use another supported source or the <img> fallback. This is the standard pattern described by MDN’s image format guide and the WHATWG HTML Living Standard.

Offer several formats

Place preferred candidates before less preferred ones, and leave the fallback image last:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<picture>
  <source srcset="photo.jxl" type="image/jxl">
  <source srcset="photo.avif" type="image/avif">
  <source srcset="photo.webp" type="image/webp">
  <img src="photo.jpg" width="1200" height="800" alt="Describe the image">
</picture>

The browser selects a source it supports. Keep meaningful alternative text on the <img> and use dimensions that match the image’s intended display ratio; the dimensions can help the page reserve space while the image loads.

Use responsive image candidates when needed

For multiple sizes of an image, provide a width-descriptor srcset and an appropriate sizes value on each relevant <source>. The browser uses these source-set inputs to choose an image candidate for the layout and display conditions. For example:

<picture>
  <source
    type="image/jxl"
    srcset="photo-800.jxl 800w, photo-1600.jxl 1600w"
    sizes="(max-width: 800px) 100vw, 800px">
  <img
    src="photo-800.jpg"
    srcset="photo-800.jpg 800w, photo-1600.jpg 1600w"
    sizes="(max-width: 800px) 100vw, 800px"
    width="1600" height="1067"
    alt="Describe the image">
</picture>

Generate matching candidates for every format you offer. If you only have one size, the simpler single-URL pattern is enough.

Choose a practical fallback

Match the fallback to the image and what must be preserved:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Photographs: JPEG is a straightforward fallback with broad support.
  • Transparency, diagrams, screenshots, or line art: PNG is often preferable when transparency or lossless reproduction matters.
  • Additional web formats: AVIF or WebP can be included as intermediate choices, but add them only if you can create and maintain those assets and want to serve them.

JPEG XL supports lossy and lossless compression, progressive decoding, HDR, wide color gamuts, transparency, and animation. Which of these capabilities matter depends on the asset and the browsers you need to serve. MDN discusses JPEG XL as an option for large, high-resolution raster images while also identifying AVIF and WebP as strong general-purpose choices in its image format guide.

Check browser support before relying on JPEG XL

JPEG XL support is not a universal baseline, and compatibility listings can differ as browsers change or move features between preview, flagged, partial, and stable states. MDN’s guide, last modified September 22, 2026, lists Safari 17 and later, Chrome 145 and later behind the #enable-jxl-image-format flag, and Firefox preview releases; it also notes that Safari can render JPEG XL after the full download but does not support progressive download. Its compatibility notes should be read with those qualifications.

Other snapshots show different release ranges. Can I Use lists Chrome support in versions 155–157, partial Safari support from version 17, and Firefox support in versions 158–160; the Can I Use JPEG XL entry is a changing compatibility snapshot. The MDN browser-compat-data entry lists Chrome 155, Safari 17 with animated images unsupported, and Firefox as preview. These differences may reflect when the data was captured or how a support state is defined. Check the versions and release status relevant to your audience rather than assuming that a browser name alone guarantees support.

With a correctly configured <picture> and a valid fallback URL, a browser that cannot decode JPEG XL should use the next supported source or the <img> image instead of requiring JPEG XL to work. Test both the preferred source and fallback in the browsers and versions you target.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Compare formats using your own images

There is no universal compression winner. Compare files at a visual quality your site can accept, include the kinds of images you actually publish, and account for lossless size, progressive display, transparency, animation, HDR, color needs, browser support, and the work of creating and maintaining multiple files.

Mozilla’s Jake Archibald illustrated why results depend on the asset and settings in an August 24, 2026 Mozilla Hacks comparison. In its sleeping-fox sample, AVIF was 116 kB and JPEG XL 134 kB at the reported SSIMULACRA 2 score of 62.8; at score 80, the files were 227 kB and 264 kB, respectively. For the same sample’s lossless encodes, AVIF was 1.76 MB, JPEG XL 1.45 MB, and WebP 1.55 MB. In a separate Interop dashboard screenshot example, AVIF was 11.6 kB and JPEG XL 23.8 kB at score 78; the lossless files were 164 kB and 92 kB, respectively. These are specific example images and encoding settings, not predictions for every site’s assets.

Archibald’s practical advice is: “The key is to test with a representative set of images for your site, at a quality that works best for your users, and remember to optimise for high density.”

Deploy and verify the image delivery

  1. Create the assets. Export JPEG XL files and the fallback files you intend to serve. If you offer AVIF or WebP, create those variants too; at scale, plan how your image pipeline or delivery layer will generate and retain each version.
  2. Add the markup. Put the JPEG XL <source> first, add any other candidates in preference order, and keep the fallback in the final <img>. Preserve useful alt text and correct dimensions.
  3. Serve the right content type. Configure the web server or CDN to return JPEG XL files as image/jxl. Confirm that the file URL resolves and that the response is an image, not an HTML error page.
  4. Test both paths. Verify that a browser with JPEG XL support loads the JXL asset and that a browser or test environment without it loads the fallback. Also test responsive candidates if you use srcset and sizes.
  5. Check failure cases. Inspect the browser’s network panel for missing files, incorrect content types, and failed requests. A fallback handles lack of format support; it does not repair a broken fallback URL or a missing asset.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.