← Back to Resources
CSS & Typography

Step-by-Step: Writing Accessible CSS Custom Properties for Translucent Overlays

CSS Custom Properties (variables) are essential for building maintainable interfaces. When working with translucent layouts, variables make it easy to adjust colors, opacity, and blur settings between light and dark themes.

Declaring Theme Tokens

Define your tokens at the root level so they automatically update when the theme switches:

:root {
  --panel-bg: rgba(255, 255, 255, 0.45);
  --panel-border: rgba(255, 255, 255, 0.3);
  --accent-color: #00D2FF;
  --blur-radius: 20px;
}

[data-theme="dark"] {
  --panel-bg: rgba(15, 23, 42, 0.55);
  --panel-border: rgba(255, 255, 255, 0.15);
  --accent-color: #00D2FF;
  --blur-radius: 24px;
}

With this setup, the glass elements adjust their styling automatically when the user toggles dark mode, keeping all content legible without any manual overrides.