CSS Gradients for Dark Mode UI

Build linear, radial, and conic CSS gradients with a visual editor. Drag color stops, pick presets, and copy ready-to-use CSS, Tailwind, or custom property output.

CSS Gradients for Dark Mode UI

Designing gradients for dark mode requires a different approach to color than light mode, because high-chroma stops that read as vibrant accents on a white surface appear neon or washed out against a dark background. Effective dark-mode gradients reduce chroma below 0.15 in oklch terms, keep lightness stops between 0.12 and 0.25, and use very small lightness deltas to create depth without visual noise.1

The prefers-color-scheme media query swaps gradient stops by reassigning CSS custom properties, keeping the gradient declaration itself unchanged.2 Consequently, a single gradient function reference adapts to both themes through the custom property values. Building on this, subtle surface gradients with lightness deltas of 0.04 to 0.08 add depth to sidebars, cards, and hero sections without the pronounced banding that appears when dark-mode gradients use the same contrast ratios as light-mode designs.

What this page covers

  • Dark-surface lightness range 0.15 to 0.35 in oklch terms avoids the neon look
  • Dark-surface chroma range 0.05 to 0.15 in oklch terms

Opens the CSS Gradient Builder with this page's checklist shown at the top of the tool.

Open in the tool →

High-chroma gradients on dark surfaces

A gradient that uses oklch(0.7 0.25 250) to oklch(0.65 0.22 300) works well on a white or light grey background. On a dark surface (background around oklch(0.12 0 0)), those same stops appear luminous and neon rather than atmospheric.3 The high chroma relative to the dark surrounding context creates an extreme contrast that draws attention away from UI content. This effect is especially pronounced on OLED displays where the dark background emits no light at all, making the gradient stops appear to float as self-illuminated color fields against a void.

Dialing chroma down to the 0.08 to 0.15 band is what keeps a dark-mode gradient from reading as neon while the color stays visible. Using oklch(0.4 0.1 250) to oklch(0.35 0.08 300) on a dark background produces a muted blue-purple gradient that reads as a surface tone rather than a focal accent. Yet some UI elements like call-to-action buttons intentionally use high-chroma gradients even on dark surfaces: a primary button at oklch(0.65 0.22 250) stands out from the dark surrounding content as intended. Building on this, the chroma reduction rule applies to large surface areas (hero backgrounds, sidebar panels, cards) rather than small interactive elements where high contrast is the goal.

Using prefers-color-scheme to swap gradient stops

CSS custom properties let you define gradient stop colors once and swap them at the variable level.4 Declare custom properties for the start and end stops in :root with light-mode values, then redefine them inside @media (prefers-color-scheme: dark). The gradient background-image declaration stays unchanged. The same pattern works for theme toggling via a data-theme attribute by scoping the property overrides to [data-theme="dark"] instead of the media query.

Custom property swap pattern

Define the properties in :root with light-mode oklch values, then reassign them inside the prefers-color-scheme: dark query with lower lightness values. The gradient function references both properties with var(), so the gradient adapts to the user's system preference with no JavaScript and no duplicated gradient declarations. The same pattern works for theme toggling via a data-theme attribute by scoping the property overrides to [data-theme="dark"] instead of the media query.

When the user switches between light and dark mode at the operating system level, the browser re-evaluates the media query and the gradient transitions immediately to the new color values. For projects that support both system-level preference and a manual theme toggle, defining the custom properties under both the media query and a data-theme selector covers all three scenarios: system light, system dark, and manual override. Adding a CSS transition on the custom property values combined with @property registration produces a smooth animated gradient shift when the user toggles between themes.

Subtle surface gradients with small lightness deltas

Dark UI surfaces often benefit from a gradient with a very small lightness difference rather than a color difference. A gradient from oklch(0.14 0 0) to oklch(0.18 0 0) is nearly achromatic but creates visible depth on a dark card or panel. The lightness delta of 0.04 is large enough to read as a gradient but small enough not to appear as a color shift. Testing the chosen tint on both OLED and LCD panels reveals whether the subtle hue shift reads as intended or disappears entirely, since OLED true-black backgrounds amplify the perceived tint compared to LCD panels with backlight bleed.

Adding hue to subtle gradients

A slight hue addition enhances the depth gradient without introducing visible color. Moving from completely achromatic (C = 0) to a chroma of 0.03 to 0.05 adds a barely perceptible tint. For example, oklch(0.14 0.03 250) to oklch(0.20 0 0) transitions from a very slightly blue-tinted dark to a neutral dark. The hue is visible up close but reads as neutral at a glance. Furthermore, subtle blue tints at low chroma tend to read as modern and technical; warm tints at the same low chroma can make dark surfaces feel more premium. The choice depends on the product's design language rather than technical constraints. Testing the chosen tint on both OLED and LCD panels reveals whether the subtle hue shift reads as intended or disappears entirely, since OLED true-black backgrounds amplify the perceived tint compared to LCD panels with backlight bleed.

Cross-browser testing strategy for dark-mode gradients

Safari on macOS color-manages CSS gradients differently than Chrome on the same display. On a P3 display such as the MacBook Pro M4, Safari renders oklch() colors with accurate P3 gamut mapping, while Chrome maps oklch() values through sRGB before passing them to the display.5 For dark-mode gradients using oklch() with low chroma, this difference is minor. For gradients with chroma above 0.15, checking the gradient in both browsers on a P3 display reveals any color rendering discrepancy before deployment.

Testing dark-mode gradients also requires verifying the prefers-color-scheme swap in isolation. Open DevTools in Chrome and switch the Rendering panel's Emulate CSS media feature to prefers-color-scheme: dark without enabling a system-level dark mode. This lets you inspect the dark-mode custom property values and the resulting gradient in the same browser session used for light-mode development. Safari's Web Inspector provides the same emulation under the Responsive Design Mode settings.

OLED display verification

Dark-mode gradients intended for OLED displays (iPhone 17 Pro, Samsung Galaxy S25, many premium Android phones) should be tested directly on those devices. Simulator-level testing in Xcode or Android Studio renders gradients using the workstation display profile rather than the device's OLED panel. A subtle lightness delta that reads clearly on a P3 IPS display may appear as banding on an OLED due to the different gamma curve at near-black luminance values.

When to use this

Use dark-mode specific gradient stops for large surface areas: hero backgrounds, sidebars, card panels, and page backgrounds. Retain higher chroma for interactive elements like primary buttons and active state indicators where visibility is the priority.

Examples

Dark hero background with subtle blue-to-neutral gradient

Use oklch(0.14 0.04 250) to oklch(0.18 0 0) for a dark blue-to-neutral sweep. The lightness delta reads as depth, and the chroma drop from 0.04 to 0 adds a color character without appearing neon. Apply via CSS custom properties and swap in the prefers-color-scheme query.

Card surface gradient that adapts to light and dark themes

Define --card-from and --card-to in :root with light values and override them in the prefers-color-scheme: dark query. The card background: linear-gradient(135deg, var(--card-from), var(--card-to)) adapts automatically. No JavaScript or class toggling required.

Sidebar panel with a vertical depth gradient for dark mode

Apply a top-to-bottom gradient from oklch(0.16 0.02 250) at the top to oklch(0.12 0 0) at the bottom. The darker bottom anchors the sidebar visually to the page footer. Keep the chroma difference minimal (0.02 maximum) to avoid color banding on high-DPI displays.

Sources
  1. 1.

    MDN Web Docs, "oklch() CSS function," developer.mozilla.org, accessed June 2026. https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/color_value/oklch

  2. 2.

    MDN Web Docs, "prefers-color-scheme CSS media feature," developer.mozilla.org, accessed June 2026. https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/At-rules/@media/prefers-color-scheme

  3. 3.

    Thomas Steiner, "prefers-color-scheme: Hello darkness, my old friend," web.dev, accessed June 2026. https://web.dev/articles/prefers-color-scheme

  4. 4.

    CSS-Tricks, "oklch()," css-tricks.com, accessed June 2026. https://css-tricks.com/almanac/functions/o/oklch/

  5. 5.

    Nikita Vasilyev, "Wide Gamut Color in CSS with Display-P3," webkit.org, March 2020. https://webkit.org/blog/10042/wide-gamut-color-in-css-with-display-p3/

FAQ

High-lightness and high-chroma colors designed for light backgrounds appear neon or washed out on dark surfaces. The relative contrast between the gradient and its background changes entirely. Reduce lightness to 0.15 to 0.35 and chroma to 0.05 to 0.15 for dark-mode surface gradients to avoid the neon effect.

Define CSS custom properties for the stop colors in :root with light-mode values. Add @media (prefers-color-scheme: dark) with the same property names reassigned to dark-mode values. Reference the properties in the gradient function with var(). The gradient updates automatically when the system preference changes.

Surface gradients on dark backgrounds typically use lightness values between 0.10 and 0.28 in oklch terms. Keep the delta between the start and end stops below 0.10 to avoid visible banding. For subtle depth without a color shift, use an achromatic or near-achromatic gradient (chroma below 0.05) across a small lightness range.

The gradient geometry (angle, stop positions) transfers to dark mode unchanged. What changes are the stop colors. Use the builder to set the gradient layout, then adjust the oklch lightness and chroma values downward for the dark-mode variant. Assign the outputs to CSS custom properties and switch the values with the media query. CapyToolkit doesn't have a dedicated dark-mode preview, but copying the geometry and manually adjusting the stop lightness and chroma produces a reliable dark-mode variant of any gradient.

OLED screens render very dark colors at extremely high precision but show visible banding on gradients with subtle lightness transitions. Increase the lightness delta slightly (to 0.06 to 0.10) to ensure the gradient is perceptible. Adding a subtle hue shift alongside the lightness change also breaks up banding more effectively than a pure lightness gradient on dark OLED surfaces.

Additional resources

Guides

CSS Gradient Text with background-clip Apply a CSS gradient to text using background-image and background-clip: text. Browser support, fallback strategy, and live examples with the gradient builder. Animating CSS Gradients with @property Animate CSS gradient stops smoothly using @property custom properties. Browser support, fallback patterns, and OKLCH hue-rotation animations. CSS Mesh Gradient Technique Build mesh-style gradients in CSS using multiple layered radial-gradient() values on the same background-image. No SVG or canvas required. Tailwind CSS v4 Gradient Utilities Complete guide to Tailwind v4 gradient utilities. bg-linear-to-r, bg-radial, bg-conic, from-*, via-*, to-*, and in-oklch modifier reference. CSS Gradient Borders Apply CSS gradient borders using border-image or background-clip masking. Both techniques, browser support comparison, and border-radius workaround. OKLCH Interpolation in CSS Gradients Use OKLCH color space interpolation in CSS gradients with the in oklch modifier. How it eliminates grey midpoints and improves perceptual smoothness. CSS Gradients for Dark Mode UI Design CSS gradients for dark mode using reduced chroma, lower lightness stops, and prefers-color-scheme media queries. Practical patterns for UI surfaces. CSS Background Patterns with Gradients Build repeating CSS background patterns using gradient functions and background-size. Stripes, grids, dots, and diagonal tile techniques without images. Glassmorphism with CSS Gradients Implement the glassmorphism effect with CSS gradients, backdrop-filter blur, and translucent stops. Browser support and performance considerations. CSS Gradient Rendering Across Laptop and Phone Displays How CSS gradients render on the Dell XPS 16, iPhone 17 Pro, MacBook Air M4, MacBook Pro M4 and Galaxy S25: P3 color stops, OKLCH interpolation, OLED blacks and the browser engine each device runs.