Styling & CSS Architecture
UI Lab uses a sophisticated styling system combining CSS Modules for component encapsulation, semantic CSS variables for theming, and Tailwind CSS for layout utilities. This guide explains how the styling system works and how to customize it.
Architecture Overview
The styling system is built on three foundations:
- CSS Modules – Scoped component styles to prevent conflicts
- Semantic CSS Variables – Consistent theming across all components
- Tailwind CSS v4 – Utility classes for layout and responsive design
CSS Module Pattern
Each component uses CSS Modules for scoped, encapsulated styling:
File Structure
CSS Modules Basics
button.module.css:
button.tsx:
Benefits
- Scoped Classes – Class names are local to the component
- No Naming Conflicts – Component can't interfere with other styles
- Type Safety – TypeScript knows available class names
- Easy Overrides – CSS variables make customization straightforward
- Tree Shakeable – Unused component styles are removed
CSS Variable System
All components use semantic CSS variables for consistent theming. Variables are organized by category:
Typography Variables
Text Sizes:
Font Families:
Font Weights:
Line Heights:
Color Variables
Colors use OKLch color space (perceptually uniform) with numeric scale 50–950:
Background Colors:
Semantic Aliases:
Foreground/Text & Semantic Colors:
| Category | Variables | Purpose |
|---|---|---|
| Text | --foreground-50 to --foreground-950 | Text color scale |
| Text Aliases | --foreground-primary, -secondary, -muted | Semantic text roles |
| Brand | --color-primary, --color-secondary | Primary/secondary actions |
| Status | --color-success, -warning, -danger, -info | Feedback states |
Spacing Variables
Responsive spacing scale:
Layout Variables
Border Radius:
Borders:
Shadows:
Transitions:
Using CSS Variables
In component styles:
Data Attributes for Styling
Components use data attributes to represent state and variants. These allow CSS to style based on component props:
Available Data Attributes
Variants & Sizes:
Styled with:
States:
Styled with:
Interactive States:
Complete State Example
Tailwind CSS Integration
UI Lab uses Tailwind CSS v4 for layout utilities and responsive design. The @theme directive defines all design tokens:
@theme Directive
Root CSS file uses @theme to define all variables:
@apply Directive in Components
CSS Modules can use @apply to compose Tailwind utilities:
Why This Approach
- Zero Runtime Overhead – No CSS-in-JS processing
- Composable – Tailwind utilities + CSS variables work together
- Customizable – Change any variable in @theme for full customization
- Responsive – Use Tailwind responsive prefixes (sm:, md:, lg:)
- Dark Mode – Variables automatically work with light/dark themes
Customizing Component Styles
Method 1: CSS Variables (Recommended)
Override CSS variables globally to change all components at once:
Method 2: CSS Modules Override
Create wrapper components with custom styles:
Method 3: Tailwind Utilities
Combine with Tailwind classes for layout:
Theme Customization
Preset Themes
UI Lab provides preset themes:
vitesse-light – Light theme with cool colors
vitesse-dark – Dark theme with high contrast
Creating Custom Themes
Generate a custom theme file during CLI setup:
Edit the generated theme:
Import in your app:
Dark Mode Support
CSS variables automatically support light/dark mode:
Or manually switch:
Advanced Styling Techniques
Responsive Design with CSS Variables
Use CSS variables with responsive design:
All components using these variables automatically respond.
Color Scales for Consistency
OKLch color space maintains perceptual uniformity:
Animations with Transitions
Use transition variables for consistent animation timing:
CSS Variable Reference
Quick reference for all available variables:
| Category | Examples | Usage |
|---|---|---|
| Typography | --text-sm, --text-base, --text-3xl | Font sizes |
| Colors | --color-primary, --background-500 | All colors |
| Spacing | --spacing-2, --spacing-4, --spacing-8 | Padding/margin |
| Radius | --radius-sm, --radius-md, --radius-full | Border radius |
| Shadows | --shadow-sm, --shadow-card | Drop shadows |
| Transitions | --transition-fast, --transition-smooth | Animation timing |
Best Practices
1. Use CSS Variables for Theming
✅ Do this:
❌ Don't do this:
2. Scope Styles with CSS Modules
✅ Do this:
❌ Don't do this:
3. Use Data Attributes for Variants
✅ Do this:
❌ Don't do this:
4. Avoid CSS-in-JS
✅ Do this:
❌ Don't do this:
5. Leverage @apply for Composition
✅ Do this:
❌ Don't do this:
Summary
The UI Lab styling system provides:
- CSS Modules – Scoped, encapsulated component styles
- Semantic CSS Variables – Consistent, customizable theming
- Tailwind CSS v4 – Modern utility-first layout system
- Dark Mode Support – Automatic theme switching
- Data Attributes – Clean prop-to-style mapping
- Zero Runtime – Pure CSS, no processing overhead
This combination creates a powerful, maintainable, and performant styling system that scales from small projects to large applications.