CSS Dynamic-Range High for HDR Displays

The CSS dynamic-range media query allows web developers to detect whether a user's display hardware supports High Dynamic Range (HDR) and adjust visual styles accordingly. Modern screens with HDR capabilities can display significantly higher peak brightness, deeper contrast ratios, and wider color gamuts than traditional Standard Dynamic Range (SDR) monitors. By querying @media (dynamic-range: high), stylesheets can progressively enhance user interfaces, photographs, and video accents using advanced CSS color spaces to present richer, more luminous colors without washing out or clipping on standard screens.

Understanding the Dynamic-Range Media Feature

The dynamic-range media feature evaluates the output device's ability to produce high levels of peak luminance and contrast. While standard monitors operate within limited brightness and contrast constraints, HDR displays can output much higher nit values and deeper black levels simultaneously.

The media feature accepts two primary values:

  • standard: Matches displays designed for typical SDR limits, where peak brightness and contrast are restricted.
  • high: Matches displays capable of exceeding SDR limits, reproducing brighter highlights, deeper shadows, and extended dynamic ranges.

Enhancing Color Spaces for HDR Displays

Historically, web colors were confined to the sRGB color space, which covers a fraction of the visible spectrum and assumes an SDR canvas. Modern CSS specifications, particularly CSS Color Module Level 4 and Level 5, introduce wider color spaces such as display-p3, rec2020, and luminance-independent models.

While the color-gamut media query specifically tests for chromaticity (the breadth of distinct hues a screen can produce), dynamic-range: high tests for luminance range (the brightness and contrast variance). When both features are present, developers can use ultra-vivid colors that appear significantly more intense than standard sRGB equivalents.

/* Base SDR styles */
.hero-badge {
  background-color: rgb(255, 60, 0);
  box-shadow: 0 0 10px rgba(255, 60, 0, 0.5);
}

/* HDR-enhanced styles */
@media (dynamic-range: high) {
  .hero-badge {
    background-color: color(display-p3 1 0.2 0);
    box-shadow: 0 0 20px color(display-p3 1 0.3 0 / 0.8);
  }
}

Preventing Clipping and Preserving Balance

On an SDR display, requesting colors outside the standard range can cause gamut clipping or inconsistent tonemapping, resulting in crushed details or unnatural banding. Using @media (dynamic-range: high) establishes a safe boundary: standard monitors receive finely tuned sRGB colors, while HDR-compatible hardware renders the enhanced spectrum.

Furthermore, dynamic range queries help prevent visual fatigue. Overusing HDR luminance across an entire layout can strain the user's eyes. Targeting high-dynamic-range rules specifically to accents, highlights, key indicators, and media overlays allows developers to deliver impactful, lifelike visuals while maintaining readable, comfortable baseline content across all devices.