light-dark() CSS function for automatic theme switching based on user preferences.
Automatic Light and Dark Modes
Oat UI automatically adapts to the user’s system color scheme preference without requiring JavaScript or manual theme switching.color-scheme property tells the browser to use the appropriate theme, while light-dark() automatically selects the correct color value based on the user’s preference.
The
light-dark(light-value, dark-value) function is a modern CSS feature that eliminates the need for @media (prefers-color-scheme: dark) queries.Color System
Oat UI uses a comprehensive color palette defined in 01-theme.css:5-26. All colors are semantic, making it easy to maintain consistent theming across your application.Semantic Color Variables
Background & Foreground
Background & Foreground
Base colors for backgrounds and text:Used for the main page background and body text color.
Card Colors
Card Colors
Elevated surfaces like cards and modals:Example usage:
Primary Colors
Primary Colors
For primary actions and interactive elements:Applied to buttons by default:
Secondary Colors
Secondary Colors
For secondary actions:Example:
Muted Colors
Muted Colors
For less prominent content:Used for disabled states and hints.
Faint Colors
Faint Colors
For very subtle backgrounds:Used for code blocks and subtle highlights.
Accent Colors
Accent Colors
For hover states and emphasis:
Status Colors
Status Colors
Semantic colors for user feedback:Examples:
Border & Input Colors
Border & Input Colors
For borders and form elements:The
--ring variable is used for focus outlines.Design Tokens
Beyond colors, Oat UI provides a complete set of design tokens for spacing, typography, shadows, and more.Spacing Scale
A consistent spacing scale based on rem units (01-theme.css:29-40):Border Radius
Consistent border radius values (01-theme.css:42-45):Typography
Font Families
Font Sizes
Fluid typography with responsive scaling (01-theme.css:52-60):The
clamp() function provides fluid typography that scales smoothly between minimum and maximum values based on viewport width.Font Weights
Line Height
Shadows
Three levels of elevation (01-theme.css:69-71):Transitions
Consistent animation timing (01-theme.css:73-74):Z-Index
Layering system (01-theme.css:76-77):Using Theme Variables
Theme variables are available globally and can be used in your custom CSS:Example: Custom Component
Example: Custom Colors with Dynamic Opacity
Oat UI uses the modernrgb(from ...) syntax for dynamic color manipulation:
Example: Color Mixing
Buttons usecolor-mix() for hover states (from button.css:3):
Customizing the Theme
To customize Oat UI’s theme, override the CSS variables in your own stylesheet:Scoped Theme Overrides
You can also create scoped theme variations:Best Practices
Always use semantic variables
Use
var(--primary) instead of hardcoded colors like #574747. This ensures your custom components adapt to theme changes.Respect the spacing scale
Use spacing variables (
var(--space-4)) instead of arbitrary values. This maintains visual consistency.Leverage color functions
Use
color-mix() and rgb(from ...) to create color variations that work in both light and dark modes.Test in both modes
Always verify your custom styles work correctly in both light and dark color schemes.
Layer System
Oat UI uses CSS cascade layers to manage specificity (from 01-theme.css:1 and 00-base.css:1):By understanding and leveraging Oat UI’s theming system, you can create consistent, accessible, and beautiful interfaces that automatically adapt to user preferences.