Styling Example
The styling example showcases Iced’s theming system, demonstrating how to apply built-in themes and create custom styles for all available widgets.Features
- Theme picker with all built-in themes
- Keyboard shortcuts for theme navigation
- Examples of every widget style
- Light and dark theme support
- Custom styled components
- Bordered containers and cards
Running the Example
Application Structure
State
- Current theme (None means system default)
- Widget values for demonstration
Messages
Theme System
Selecting Themes
theme method allows dynamic theme switching.
Built-in Themes
Iced includes several built-in themes accessible viaTheme::ALL:
- Default
- Dark
- Light
- Dracula
- Nord
- Solarized Light
- Solarized Dark
- Gruvbox Light
- Gruvbox Dark
- Catppuccin Latte
- Catppuccin Frappé
- Catppuccin Macchiato
- Catppuccin Mocha
- Tokyo Night
- Tokyo Night Storm
- Tokyo Night Light
- Kanagawa Wave
- Kanagawa Dragon
- Kanagawa Lotus
- Moonfly
- Nightfly
- Oxocarbon
- Ferra (and many more)
Theme Navigation
Button Styles
- Primary: Main actions
- Secondary: Secondary actions
- Success: Positive actions
- Warning: Cautionary actions
- Danger: Destructive actions
- Disabled state: Buttons without
on_press
Text Input
Slider & Progress Bar
Checkboxes & Togglers
Scrollable Content
Container Styles
container::bordered_box style creates a themed card with borders.
Rules (Dividers)
Keyboard Shortcuts
- ↑ / ←: Previous theme
- ↓ / →: Next theme
- Space: Clear theme (use system default)
Complete View
Custom Styles
While this example uses built-in styles, you can create custom styles:Testing
The example includes snapshot tests for all themes:Key Concepts
Theme Type
TheTheme type is central to styling:
Style Functions
Style functions take&Theme and Status to produce styles:
Extended Palette
Access fine-grained colors:Best Practices
- Use built-in themes when possible
- Provide theme picker for user preference
- Test with multiple themes to ensure consistency
- Use semantic colors from extended palette
- Support system theme as default
- Make custom styles theme-aware
- Test disabled states for all interactive widgets
Related Examples
- Counter - Basic styling
- Todos - Custom text styles
- Custom Widget - Custom widget styling
Source Code
View the complete example on GitHub:Next Steps
- Create your own theme
- Implement dark mode toggle
- Build a theme editor
- Add custom widget styles
- Explore color palettes
- Implement style presets
