Variants
CVA is best used in SSR/SSG environments. Because
cva returns a plain string, your users don’t need any of this JavaScript at runtime — it can all be resolved at build time or on the server.Creating a component with variants
Pass base classes as the first argument tocva, then describe each variant group inside the variants key.
components/button.ts
Tailwind CSS is optional. CVA works with any class-based styling approach, including plain CSS class names and CSS Modules.
components/button.ts
Boolean variants
Variant keys can be the string"true" or "false", and CVA will accept an actual boolean value for that prop. This is useful for representing toggled states like disabled, loading, or active.
Set the false value to null when you don’t need extra classes for the off state:
components/button.ts
Extending a component
Every CVA component accepts an optionalclass or className prop for one-off overrides. The extra classes are appended after all variant classes.
You can pass
class or className, but not both at the same time. The two props are mutually exclusive in CVA’s type system.