CSS Variables & Functions in CSS
From the CSS cheat sheet ยท Custom Properties & Functions ยท verified Jul 2026
CSS Variables & Functions
Define reusable values with custom properties and use calc, clamp, min, max
css
:root {
--color-primary: #3b82f6;
--spacing: 1rem;
--radius: 8px;
}
.btn {
background: var(--color-primary);
padding: var(--spacing);
border-radius: var(--radius);
}
.container {
width: min(100% - 2rem, 1200px);
}๐ก CSS variables cascade and inherit โ override them in any scope for easy theming
โก clamp(min, preferred, max) replaces min-width + max-width + media queries in one line
๐ var(--name, fallback) provides a default value if the variable is not defined
๐ข Use @media (prefers-color-scheme: dark) with variable overrides for system dark mode
variablescustom-propertiescalcclamp