Cookie Consent by Free Privacy Policy Generator

How to embed an HDR image in a website

There is no single image format that you can embed in a web page and that keeps the HDR effect on every capable display. There are many HDR file formats, but they are hard to convert to, and none of them works in every browser. So to show an HDR image on a website, you need to convert it into several formats and embed it so that each browser picks the file it can show.
Upload your HDR image to HDRJPG. HDRJPG converts it into a set of files that all keep the HDR: a gain map JPEG (JPEG-XT), a JPEG-XL, an HDR AVIF and two short, silent HDR MP4 videos. Download them and put them on your web server.
Then embed them with the HTML below. Each visitor's browser picks the file it can show in HDR, so your image looks like full HDR almost everywhere. On a screen without HDR, visitors see a normal photo.
Using WordPress? You don't need to do any of this by hand. The free HDRJPG WordPress plugin converts the HDR photos you upload to your media library and adds the embedding markup for you.

Recommended method

The recommended method uses JPEG-XT, AVIF and MP4 files generated by HDRJPG to reach near-100% browser compatibility with today's standards and browsers.
The two MP4 videos are the same photo in two codecs. The HEVC one (image.hevc.mp4) is 10-bit, so skies and other smooth gradients stay free of banding, and its colors are closer to the original. Not every browser plays HEVC, so the script checks first. Browsers that can play it get the HEVC video, and the others get the H.264 one (image.mp4).
Embed the image in your HTML like this:
<div class="hdrjpg" data-mp4-src="image.mp4" data-mp4-hevc-src="image.hevc.mp4">
    <picture>
        <source srcset="image.avif" media="all and (min--moz-device-pixel-ratio:0) and (min-resolution: 3e1dpcm) {}" type="image/avif" /> 
        <img src="image.jpg" loading="lazy" decoding="async" style="image-rendering: -webkit-optimize-contrast;"> 
    </picture>
</div>
Then add the hdrjpg-js script to the page:
<script src="https://cdn.jsdelivr.net/npm/hdrjpg-js@1.3.0/dist/hdrjpg.min.js" defer></script>
Or use the npm package instead
npm install hdrjpg-js
And import it in your app:
import 'hdrjpg-js';
Users with obsolete browser versions or without an HDR compatible screen will see a standard dynamic range instead.

Simple but low compatibility method

JPEG-XT images created with HDRJPG can be used in HTML pages just like regular images, and will be displayed in HDR in capable devices. Simply embed images like you would with any other image:
<img src="image.jpg" />
This is the simplest possible method of embedding HDR images because it works simply like any other image. However, this method is only compatible with Chrome, Brave, Opera and other Chromium-based browsers (~70% browser market share compatibility as of november 2024, according to StatCounter).
Users with other browsers like Safari or Firefox, or without an HDR compatible screen will see a standard dynamic range instead.