Architecture Overview
Oat UI’s CSS is organized into a layered architecture that provides predictable specificity and easy customization.Cascade Layers
From 00-base.css:1 and 01-theme.css:1, Oat UI defines explicit cascade layers:CSS cascade layers allow you to control specificity by organizing styles into named layers. Styles in later layers override earlier ones, regardless of selector specificity.
- theme - CSS custom properties and design tokens
- base - Element defaults and resets
- components - Component-specific styles
- animations - Animation definitions
- utilities - Utility classes and overrides
Benefits
Predictable Overrides
Layer order determines precedence, not selector specificity. Your utility classes in the
utilities layer will always override component styles.No Specificity Wars
Avoid
!important and complex selector chains. Layers handle precedence naturally.Easy Customization
Add your own styles in the appropriate layer without worrying about specificity conflicts.
Clear Organization
Styles are organized by purpose, making the codebase easy to navigate and maintain.
Modern CSS Features
Oat UI embraces cutting-edge CSS features for a superior developer experience.CSS Nesting
Oat UI uses native CSS nesting for cleaner, more maintainable styles (from button.css:22-32):Custom Properties for State
Oat UI uses scoped custom properties for component states (from button.css:3):The
--_hov variable uses an underscore prefix to indicate it’s a private, component-scoped variable (not part of the public theming API).Color Functions
light-dark()
Automatic theme adaptation (from 01-theme.css:5):color-mix()
Dynamic color generation for hover states (from button.css:42):rgb(from …)
Opacity manipulation while preserving color (from 00-base.css:97):Logical Properties
Oat UI uses logical properties for internationalization support (from 00-base.css:137):Logical properties like
inline-start and block-end adapt automatically to different writing modes and text directions (LTR/RTL).margin-block-start/margin-block-endinstead ofmargin-top/margin-bottompadding-inline-start/padding-inline-endinstead ofpadding-left/padding-rightborder-inline-startinstead ofborder-left
Selector Strategy
Oat UI uses a deliberate selector strategy that balances specificity, performance, and maintainability.:where() for Zero Specificity
The:where() pseudo-class has zero specificity, making styles easy to override (from form.css:15):
:is() for Grouping
The:is() pseudo-class groups selectors efficiently (from button.css:2):
Attribute Selectors for Variants
Data attributes create semantic variants (from button.css:34, 41)::has() for Contextual Styling
The:has() pseudo-class enables parent selectors (from form.css:7):
Responsive Design
Fluid Typography
Oat UI usesclamp() for responsive typography without media queries (from 01-theme.css:52-54):
- Text scales fluidly between minimum and maximum based on viewport width
- No breakpoints needed
- Accessible and user-friendly
Container-Based Sizing
Oat UI uses relative units (rem, em, %) and avoids fixed pixel widths:State Management
Interactive States
From 00-base.css:177-185, Oat UI provides consistent state styling:ARIA State Styling
Styles respond to ARIA attributes for accessibility (from form.css:42-48):Data Attribute States
Component states via data attributes (from form.css:252-255):Performance Optimizations
Transitions
Targeted transitions for smooth interactions (from button.css:20):Will-Change Sparingly
Oat UI avoidswill-change unless absolutely necessary, as it can harm performance when overused.
Minimal Repaints
Usingtransform instead of positional properties (from button.css:31):
Resets and Normalization
Modern CSS Reset
Oat UI includes a minimal reset (from 00-base.css:4-11):Font Smoothing
Optimized text rendering (from 00-base.css:28):Media Defaults
Responsive media elements (from 00-base.css:35-37):Customization Patterns
Adding Custom Styles
Create your own layer for custom utilities:Extending Components
Add component variants in the components layer:Overriding Theme Defaults
Simply redefine CSS custom properties:Best Practices
Use the layer system
Use the layer system
Organize your custom CSS into the appropriate layer. This prevents specificity conflicts and makes overrides predictable.
Leverage custom properties
Leverage custom properties
Use CSS variables for any value that might change or needs theming support.
Prefer logical properties
Prefer logical properties
Use logical properties for better internationalization support.
Use semantic selectors
Use semantic selectors
Target semantic HTML elements and data attributes rather than creating utility classes.
Minimize custom classes
Minimize custom classes
Let Oat UI’s element styles do the work. Only add classes when absolutely necessary.
Test in multiple browsers
Test in multiple browsers
Oat UI uses modern CSS features. Ensure your target browsers support the features you’re using.
Browser Support
Oat UI targets modern, evergreen browsers and uses cutting-edge CSS features:- CSS Nesting
- CSS Cascade Layers (
@layer) light-dark()functioncolor-mix()function:has()pseudo-class:where()and:is()pseudo-classes- Logical properties
clamp()function
File Size
Oat UI’s entire CSS library is approximately 8KB minified and gzipped, making it one of the smallest full-featured UI frameworks available. The minimal footprint is achieved through:- No preprocessor overhead - Native CSS features only
- Semantic selectors - Styling elements directly instead of utility classes
- CSS custom properties - Single source of truth for design tokens
- Modern CSS - Leveraging browser capabilities instead of polyfills
By understanding Oat UI’s CSS architecture, you can write maintainable, performant styles that integrate seamlessly with the framework while keeping your bundle size minimal.