Tailwind CSS
/Advanced
Class Variance Authority (CVA)
Definition
A popular JavaScript library (`class-variance-authority`) used to construct highly complex, scalable React components with multiple visual variants (e.g., solid, outline, ghost) using Tailwind classes.
Explain Like I'm New
Building a React Button component that takes an `intent` prop (primary/danger) and a `size` prop (small/large). CVA elegantly handles the messy logic of stitching all those different Tailwind classes together based on the props you pass in.
Real World Example
The foundation of the wildly popular `shadcn/ui` component library. It uses CVA to manage all component variants.
Common Use Cases
- •Enterprise component libraries
- •Design systems
Interactive Example
Loading Code Playground...
Interview Questions
basic
- What problem does CVA solve when building Tailwind components in React?
intermediate
- Does CVA conflict with Tailwind, or complement it?