Rustyle 0.3.0
The Ultimate CSS-in-Rust Solution for Leptos 0.8.14
Rustyle 0.3.0 is the undisputed #1 CSS-in-Rust solution, delivering best-in-class features, unmatched developer experience, seamless Leptos integration, and zero-compromise performance.
Features
Core Features
- ✅ Compile-time CSS processing - Zero runtime overhead for static styles
- ✅ Automatic scoped styles - Unique class names prevent style conflicts
- ✅ Full SSR/CSR support - Works seamlessly in both server-side and client-side rendering
- ✅ Type-safe class names - Compile-time validation of CSS syntax
- ✅ CSS nesting support - Write nested CSS like modern preprocessors
- ✅ Pure Rust implementation - Uses
lightningcssfor CSS parsing
Design System & Tokens
- ✅ Comprehensive design token system - Colors, spacing, typography, shadows, borders, animations
- ✅ Type-safe color scales - 50-950 color scales with semantic colors
- ✅ Component system - Pre-built Button, Card, and Input components with variants
- ✅ Multi-theme support - Light/dark themes with smooth transitions
- ✅ System theme detection - Automatic dark/light mode support
Modern CSS Features (2025)
- ✅ View Transitions API - Smooth page transitions
- ✅ Advanced selectors -
:has(),:is(),:where()support - ✅ @scope and @starting-style - Modern CSS scoping and entry animations
- ✅ CSS Grid Subgrid - Full grid system with subgrid support
- ✅ Container queries - Type-safe container query builders
Performance & Optimization
- ✅ Complete Critical CSS extraction - Real HTML/DOM parsing, selector matching, and route-based splitting
- ✅ Complete Tree Shaking - Unused CSS removal with component-level analysis
- ✅ Advanced minification - Dead code elimination using lightningcss
- ✅ Optimized Style Registry - Thread-safe DashMap for concurrent access
- ✅ CSS optimization - Automatic vendor prefixing and browser targeting
Reactive Styling
- ✅ Complete
style_signal!macro - Full reactive styling with embedded Rust expressions, automatic signal dependency extraction - ✅ Full Leptos signal integration - Reactive styles that update with signals
- ✅ Zero-overhead when signals don't change - Optimized reactive updates
- ✅ Animation state management - State-driven animations
- ✅ Dynamic style builders - Runtime style generation when needed
Developer Experience
- ✅ Intelligent Error System - Enhanced error messages with exact source locations, visual code snippets, multiple ranked suggestions, and quick-fix actions
- ✅ Enhanced Hot Module Replacement - Incremental updates, state preservation, and change notifications
- ✅ Advanced Debugging Tools - Style inspector with real-time visualization, component style tree, and performance profiling
- ✅ Comprehensive CSS Linting - 50+ accessibility, performance, and best practice rules with auto-fix capabilities
- ✅ Complete CSS Modules - Full file system support, build-time compilation, and type-safe class accessors
- ✅ Testing utilities - CSS validation and style testing helpers
Accessibility
- ✅ Focus management - Automatic focus-visible styles
- ✅ Reduced motion support - Respects user preferences
- ✅ Color contrast checking - WCAG AA/AAA validation
Advanced Features
- ✅ Style composition - Mixins and style inheritance
- ✅ Runtime style generation - Type-safe dynamic style builders
Installation
Add Rustyle to your Cargo.toml:
[]
= "0.3.0"
= "0.8.14"
[]
# Enable dev tools for development
= ["rustyle-css/dev"]
Quick Start
Basic Usage
use *;
use style;
Using Design Tokens
use ;
let tokens = default;
let button = new;
let css = button.to_css;
Using Components
use ;
// Button with variant and state
let button = new
.state;
// Select dropdown
let select = new
.state;
// Badge
let badge = new;
// Alert
let alert = new;
// Progress bar
let progress = new;
// Loading spinner
let spinner = new;
Reactive Styling
use *;
use style_signal;
CSS Modules
use css_module;
// Load CSS module from file at compile time
let module = css_module!;
let button_class = module.get;
API Reference
Macros
style! - Scoped Styles
let class = style! ;
style_with_vars! - Styles with CSS Variables
let theme = style_with_vars! ;
global_style! - Global Styles
global_style!
view_transition! - View Transitions
view_transition!
scope_style! - @scope Rules
scope_style!
Design Tokens
use DesignTokens;
let tokens = default;
// Or create custom tokens
let custom_tokens = custom;
Components
use ;
// Button with variant and size
let button = new;
// Card with elevation
let card = new.elevation;
// Input with validation state
let input = new
.validation;
Theming
use ;
// Apply a theme
let theme = light;
apply_theme;
// Multi-theme support
let mut manager = new;
manager.add_theme;
manager.switch_to;
// System theme detection
register_system_theme;
Accessibility
use ;
// Register focus styles
let focus_style = new;
register_focus_styles;
// Register reduced motion support
register_reduced_motion;
Testing & Linting
use ;
// CSS assertions
assert!;
// Linting
let results = lint;
for result in results
Examples
See the examples/ directory for complete examples:
basic.rs- Basic styling exampletheming.rs- CSS variables and themingreactive.rs- Reactive component stylingssr_csr.rs- SSR/CSR compatibilitycomplete_app.rs- Complete application examplecontainer_queries.rs- Container queriestype_safe.rs- Type-safe utilitiesanimations.rs- Animations and keyframesresponsive.rs- Responsive designdesign_tokens.rs- Design tokens usagecomponents.rs- Component styles (Button, Card, Input)theming_advanced.rs- Advanced theming with multi-theme supportaccessibility.rs- Accessibility features demonstration
Migration from 0.1.0
Rustyle 0.2 maintains backward compatibility with 0.1.0 for basic usage. However, we recommend migrating to the new APIs:
- Use
DesignTokensfor centralized design system - Use component styles (
ButtonStyle,CardStyle, etc.) instead of manual CSS - Use
ThemeManagerfor multi-theme support - Enable
devfeature for development tools
Requirements
- Rust 1.85.0 or later (for edition 2024)
- Leptos 0.8.14
License
Licensed under the Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.