10 min read
0%

Modern CSS Functions

Back to Blog
Modern CSS Functions

Modern CSS Functions: Practical Patterns That Ship

Modern CSS functions reduce utility-class bloat and custom media edge cases.

A useful baseline toolkit:

  • clamp()
  • min() / max()
  • calc()
  • color-mix()
  • light-dark()
.headline {
  font-size: clamp(1.5rem, 1rem + 2vw, 3rem);
}

Clamp for Fluid Type and Spacing

.stack {
  gap: clamp(0.75rem, 0.5rem + 1vw, 1.5rem);
}

This avoids multiple breakpoints for simple interpolation.

Min/Max for Better Constraints

.content {
  width: min(72ch, 100% - 2rem);
}

Readable line length + responsive gutters in one line.

Calc for Explicit Math

.hero {
  min-height: calc(100svh - var(--nav-height));
}

Use it when design intent is arithmetic, not guesswork.

Color Mix for Token Variants

.chip {
  background: color-mix(in srgb, var(--brand) 18%, transparent);
  border-color: color-mix(in srgb, var(--brand) 34%, transparent);
}

Great for deriving consistent tints from a single source token.

Light-Dark for Theme-Aware Values

:root {
  color-scheme: light dark;
}

.surface {
  background: light-dark(#ffffff, #0f172a);
  color: light-dark(#0f172a, #e2e8f0);
}

Cleanly maps values without duplicating selectors.

Real-World Combo

.card {
  padding: clamp(1rem, 0.8rem + 0.8vw, 1.75rem);
  border-radius: max(12px, 1.25vw);
  background: light-dark(#fff, #0b1220);
  border: 1px solid color-mix(in srgb, currentColor 14%, transparent);
}

Pitfalls

  1. Overusing nested functions until values become unreadable.
  2. Ignoring fallback behavior in older environments.
  3. Mixing units without understanding resulting interpolation.

Conclusion

Modern functions are a leverage multiplier.
Use them intentionally and you can replace a lot of repetitive breakpoint and utility code.


Browser support snapshot

Live support matrix for css-math-functions from Can I Use.

Show static fallback image Data on support for css-math-functions across major browsers from caniuse.com

Source: caniuse.com

Canvas is not supported in your browser