Component Architecture
Reflex UI components follow a hierarchical architecture with clear separation of concerns:CoreComponent
All Reflex UI components inherit fromCoreComponent, which provides the foundation for styling and customization:
reflex_ui/components/component.py
CoreComponent:
- Automatic style merging: Default styles are automatically merged with user-provided
class_nameprops using thecn()utility - Unstyled mode: Set
unstyled=Trueto remove all default styles and start from scratch - Consistent API: All components share the same styling approach
BaseUIComponent
Components that wrap Base UI primitives extendBaseUIComponent:
reflex_ui/components/base_ui.py
- Accessibility: ARIA attributes and keyboard navigation built-in
- Unstyled primitives: Complete control over styling
- React components: Modern, maintained React component library
Component Structure
Reflex UI components typically follow these patterns:Simple Components
Simple Components
Simple components like These components:
Button and Badge extend either CoreComponent or native HTML elements:reflex_ui/components/base/button.py
- Define variant and size props for visual customization
- Apply default styles based on the selected variant and size
- Support the
class_nameprop for custom styling
Composite Components
Composite Components
Complex components like This pattern provides:
Checkbox and Card use a namespace pattern:reflex_ui/components/base/checkbox.py
- Low-level API:
checkbox.root()andcheckbox.indicator()for full control - High-level API:
checkbox()for common use cases - Exposed class names:
checkbox.class_namesfor style customization
Tailwind CSS Integration
Reflex UI is built with Tailwind CSS v4, leveraging:Modern CSS Features
- CSS Custom Properties: Theme colors are defined as CSS variables in
:root - @theme directive: Tailwind theme is configured using CSS rather than JavaScript
- light-dark() function: Automatic dark mode support using CSS color schemes
Semantic Color System
Colors follow a semantic naming system based on Radix Colors:demo/assets/css/globals.css
- 1-12: Light to dark shades for backgrounds, borders, and text
- a1-a12: Alpha variants for overlays and subtle effects
Design Principles
Accessibility First
Built on Base UI primitives with ARIA attributes, keyboard navigation, and screen reader support built-in.
Customizable
Every component supports
class_name for custom styling, and most support unstyled mode for complete control.Consistent API
All components follow the same patterns for variants, sizes, and styling, making them predictable and easy to learn.
Type Safe
Full TypeScript support with literal types for variants, ensuring compile-time validation.
Next Steps
Styling Components
Learn how to customize component styles using the
class_name prop and cn() utility.Theming
Discover how to implement themes and dark mode using CSS variables.