Quickstart
Create your first variant component
Define a Calling the component resolves the correct class string:
button component with cva. Pass base classes as the first argument, then describe your variants, compoundVariants, and defaultVariants in the config object.components/button.ts
Use of Tailwind CSS is optional. CVA works with any class-based styling approach, including plain CSS class names and CSS Modules.
Use it in your framework
cva returns a plain string, so it works anywhere you can set a class attribute.- React
- Plain HTML
components/Button.tsx
Extract variant types with VariantProps
Use the You can then use
VariantProps utility type to derive the TypeScript prop types directly from your cva definition. This keeps your types and your variant config in sync automatically.components/button.ts
ButtonVariants in your component props interface:components/Button.tsx
Next steps
Core concepts: Variants
Learn about variants, compound variants, boolean variants, and default variants in depth.
API Reference
Full reference for
cva, cx, compose, defineConfig, and VariantProps.