AVIF in CSS background-image Across Modern Browsers

This article provides an overview of how the CSS background-image property handles the AVIF image format across all modern rendering engines. It covers the current support landscape across Blink, Gecko, and WebKit, details native implementation behaviors, and demonstrates the practical techniques—such as the CSS image-set() function and cascading fallbacks—required to deliver AVIF background assets reliably without breaking older browsers.

Modern Rendering Engine Support for AVIF

All three primary rendering engines—Blink (Google Chrome, Microsoft Edge, Opera), Gecko (Mozilla Firefox), and WebKit (Apple Safari)—natively support AVIF (AV1 Image File Format) inside the CSS background-image property.

Because all current stable releases of these engines include AVIF decoders, declaring background-image: url('hero.avif') works universally on up-to-date browsers.

Delivering AVIF with Fallbacks

While current engine releases support AVIF, real-world deployment requires graceful degradation for older clients (such as Safari 16.3 and below, or legacy Internet Explorer/Edge releases).

Method 1: The CSS image-set() Function

The modern and standard method to serve AVIF background images with appropriate fallbacks is the CSS image-set() function combined with the type() specifier.

.hero {
  /* Fallback for engines with no image-set support */
  background-image: url('hero.jpg');

  /* Modern format negotiation */
  background-image: image-set(
    url('hero.avif') type('image/avif'),
    url('hero.webp') type('image/webp'),
    url('hero.jpg') type('image/jpeg')
  );
}

When an engine parses image-set(), it evaluates the formats listed inside the type() functions from top to bottom. If the engine supports image/avif, it fetches and renders the AVIF resource, ignoring the subsequent formats. If the engine does not support AVIF, it skips to WebP or standard JPEG/PNG.

All modern engines fully support the standard image-set() syntax with type() declarations:

Method 2: The @supports Rule

An alternative approach leverages the CSS @supports at-rule. Because CSS feature queries cannot directly evaluate image decoding support dynamically, this method is typically combined with a lightweight feature-detection script (such as Modernizr) or targeted selector strategies:

.element {
  background-image: url('fallback.jpg');
}

/* Applied when a feature-detection script confirms AVIF support */
.avif .element {
  background-image: url('optimized.avif');
}

Performance Characteristics

Using AVIF within background-image provides substantial payload reductions—often 20% to 50% smaller than WebP and up to 80% smaller than legacy JPEG/PNG files. Modern engines process AVIF background assets similarly to any other image format:

  1. Network Fetching: The rendering engine requests the resource during the style and layout phase when the element is matched to the DOM.
  2. Decoding: Decoding takes place asynchronously. Modern engines avoid painting blocks by displaying the element's background-color until the AVIF decode operation completes.
  3. Caching: Decoded raster caches are stored in GPU memory when appropriate, matching the rendering efficiency of traditional image formats.