Styling approach
Apsara components are styled using:- CSS Modules - Scoped CSS classes that prevent naming conflicts
- Data attributes - Semantic HTML attributes for styling variants and states
- CSS variables - Design tokens for theming and customization
Benefits of this approach
- No runtime CSS-in-JS overhead
- Predictable CSS specificity
- Easy to override with standard CSS
- Works with any bundler that supports CSS imports
- Full control over styling without JavaScript
Component CSS structure
Here’s how a typical Apsara component is styled (frombutton.module.css):
button.module.css
Using data attributes
Components use data attributes to handle variants and states. This makes the HTML semantic and the CSS easy to override:Customizing component styles
There are several ways to customize component styles:Method 1: Override CSS variables
The easiest way to customize components globally:Method 2: Target component classes
Override specific components using CSS selectors:custom.css
Method 3: Use className prop
All Apsara components accept aclassName prop for custom styling:
MyButton.module.css
Real-world examples
Example 1: Badge component
The Badge component uses size and variant classes (frombadge.module.css):
Example 2: Hover and active states
Components define interactive states with pseudo-classes:Example 3: Radix UI state attributes
Components integrate with Radix UI’s data attributes for complex states:Working with CSS Modules
If you’re using CSS Modules in your project, you can import and compose Apsara styles:MyComponent.module.css
Accessibility considerations
When customizing styles, maintain accessibility:Best practices
Prefer CSS variables
Use CSS variables for theming instead of hardcoding values
Maintain specificity
Avoid using
!important - leverage CSS specificity correctlyTest responsively
Ensure custom styles work across different screen sizes
Keep accessibility
Maintain focus states, contrast ratios, and semantic HTML
Related resources
Theming
Customize colors, spacing, and typography
Dark mode
Implement dark theme support