Understanding the Variable System
Klef uses a unique variable-driven architecture that combines CSS custom properties with attribute selectors to create a declarative styling system.The Core Principle
“Classes define intention. Variables define behavior.”This means:
- Semantic classes (
.btn,.card,.nav) define what a component is - CSS variables (inline or in
:root) define how it looks and behaves
Customizing Design Tokens
Override Root Variables
The simplest way to customize the theme is to override CSS variables in your own stylesheet:Custom Color Palette
Create your own brand color system:Dark Mode Implementation
The design system includes commented dark mode support that you can enable:Manual Dark Mode Toggle
Implement a manual dark mode toggle:Using the Variable-Driven System
Inline Variable Styling
The Klef v2+ system allows you to use variables directly in HTML:Available Variable Shortcuts (v3)
Klef v3 introduces ergonomic short tokens:Flag Variables
Simple boolean-like flags for common patterns:Custom Component Themes
Customizing Buttons
Customizing Cards
Typography Customization
Custom Font Integration
Custom Typography Scale
Animation Customization
Custom Easing Functions
Custom Animations
Complete Theme Example
Here’s a complete custom theme:Best Practices
- Start with tokens: Always customize design tokens (colors, spacing, etc.) before individual components
- Maintain consistency: Use the existing variable system rather than hard-coded values
- Test thoroughly: Check your customizations across all breakpoints and themes
- Document changes: Keep track of which variables you’ve overridden
- Use semantic variables: Prefer
--text-primaryover direct color values for better theme switching
Next Steps
- Explore CSS Variables for a complete reference
- Learn about Responsive Design to ensure your theme works on all devices
- Check the component documentation for customization options

