Skip to content

Gradient

Applies a subtle lightness gradient to a surface using oklch relative color syntax. Creates depth without introducing a second color — the gradient is derived from the input color itself.

Falls back to a flat background color in browsers that do not support relative color syntax.

@use 'mixins' as *;
.header {
@include gradient(var(--color-header-background));
}
ParameterDefaultDescription
$colorrequiredBase color — must be a resolved value
$anglefrom configGradient angle — defaults to shadow direction
$intensityfrom configLightness variation — defaults to shadow hardness × 1.5

The angle and intensity default to config values so gradient and shadow share a consistent light source:

  • Angle — derived from $shadow-direction via shadow-direction-to-angle()
  • Intensity$shadow-hardness × 1.5
Shadow directionGradient angle
"none"180deg — top to bottom
"left"135deg — top-left to bottom-right
"right"225deg — top-right to bottom-left

Override either at the call site:

// custom angle
@include gradient(#1A73FF, 90deg);
// custom intensity
@include gradient(#1A73FF, null, 20);
// both
@include gradient(#1A73FF, 90deg, 20);

The gradient runs from a lighter version of the color at 0% to a darker version at 100%, with the original color anchored at 62%. This mimics natural light falling on a surface — brighter where light hits, darker in shadow:

0% — l + intensity × 0.01 lighter
10% — l + intensity × 0.0067 slightly lighter
62% — original color
90% — l - intensity × 0.0067 slightly darker
100% — l - intensity × 0.01 darker