Customization
[07] Customization
Customizing Styles
Override VaneUI React component styles with Tailwind CSS classes in className: which properties win, when a CSS variable or a prop fits better, and pitfalls.
VaneUI components are styled through boolean props and CSS variables, but you can override any visual property using standard Tailwind CSS classes via the className prop. This page explains how overrides work, when to use each approach, and common pitfalls.
How className overrides work
VaneUI uses tailwind-merge to combine theme-generated classes with your className. When a conflict exists, your class always wins because className is passed last:
// Internally, VaneUI does:const finalClasses = twMerge(...themeGeneratedClasses, className);This means the conflict is resolved at the JavaScript level: the losing class is removed from the string entirely before the DOM renders. There are no CSS specificity wars or !important hacks.
An override holds at every width. A responsive component (Section, Card, Stack, Container, Alert, Modal, Popup and the titles) repeats its padding, gap and font size for tablet and mobile, and a class that overrides one of those values replaces all three, so <Section className="py-8"> keeps py-8 on a phone. This covers py-*, px-*, p-*, gap-* and font-size classes. A one-sided class such as pt-* or gap-x-* still gives way to the component's own value below 1024px. Before @vaneui/ui 1.6.0, a class replaced the desktop value only.
Properties className can override
VaneUI components use CSS variable consumer classes like border-(--border-color), text-(--text-color), and bg-(--bg-color). These compile to standard CSS (border-color: var(--border-color)). Any Tailwind utility that targets the same CSS property will override them.
Border color
// VaneUI generates: border-(--border-color)// Your class: border-red-300// Result: border-red-300 (VaneUI class removed)<Card className="border-red-300">Custom border</Card>Text color
// VaneUI generates: text-(--text-color)// Your class: text-emerald-600// Result: text-emerald-600<Text className="text-emerald-600">Custom text color</Text>Background color
// VaneUI generates: bg-(--bg-color)// Your class: bg-gradient-to-r from-blue-500 to-purple-500// Result: bg-gradient-to-r from-blue-500 to-purple-500<Card className="bg-gradient-to-r from-blue-500 to-purple-500"> Gradient card</Card>Hover, active, and focus states
State-specific overrides work too. Each state variant is resolved independently:
// Override hover background<Button className="hover:bg-blue-700">Custom hover</Button>
// Override focus ring<Input className="focus-visible:outline-purple-500" placeholder="Custom focus" />
// Override active state<Button className="active:bg-blue-900">Custom active</Button>Shadow
<Card className="shadow-2xl">Extra large shadow</Card><Card className="shadow-none">No shadow</Card>Non-conflicting properties are preserved
twMerge only removes classes that target the same CSS property. Different properties coexist:
// border-width and border-color are separate properties// VaneUI's border-width stays, only color is overridden<Card className="border-red-300"> {/* Has both: border-[length:var(--bw)] (width) + border-red-300 (color) */}</Card>Override hierarchy
From lowest to highest priority:
| Level | Mechanism | Scope | Use When |
|---|---|---|---|
| 1 | Component defaults | Library-wide | You're the library author |
| 2 | themeOverride | Provider subtree | Modify theme internals programmatically |
| 3 | themeDefaults | Provider subtree | Change defaults for all components in a section |
| 4 | extraClasses | Provider subtree | Add classes based on active props |
| 5 | className | Single instance | One-off style adjustments |
| 6 | style | Single instance | Runtime-computed values that can't be a class |
Inside one ThemeProvider, the themeOverride function runs first, and themeDefaults and extraClasses are applied to the theme it returns. A default set in themeDefaults therefore wins over a default that themeOverride set in the same category:
<ThemeProvider themeDefaults={{ button: { main: { success: true } } }} themeOverride={(theme) => { theme.button.main.defaults = { ...theme.button.main.defaults, primary: false, danger: true, }; return theme; }}> <Button>Success from themeDefaults</Button></ThemeProvider>For most use cases, className (level 5) is the right tool. Use themeDefaults or extraClasses when you need the override to apply across many components.
CSS variable approach
Instead of replacing the consumer class with a utility like border-red-300, set the underlying CSS variable with an arbitrary-property class. This keeps VaneUI's consumer class active but changes the value it reads:
// Set the variable with an arbitrary-property class: the component's own// border-(--border-color) still fires, but reads your custom value instead of the theme's<Card className="[--border-color:var(--color-red-300)]"> Theme-aware border override</Card>Replacing the utility vs setting the variable:
The CSS variable approach fits when you want descendants to inherit your override. The value reaches every descendant that does not set the variable again. A Row or Col with border and the accent border of a Blockquote have no appearance of their own, so they take the Card's red. Components with their own appearance, such as Input, Button and Badge, set the color variables on their own element and keep their colors. Divider draws its line from --divider-color, a separate variable, so it stays unchanged too:
A bordered Row inherits the red border
The Blockquote accent border inherits it too
<Card className="[--border-color:red]"> <Row border padding> <Text>A bordered Row inherits the red border</Text> </Row> <Blockquote>The Blockquote accent border inherits it too</Blockquote> <Input placeholder="Input keeps its own colors"/> <Input className="[--ring-color:red]" placeholder="Variable set on this Input"/> <Divider/></Card>To recolor a component that has its own appearance, set the variable on that component, as the second Input does (a text field draws its outline as a ring, from --ring-color), or give it an appearance prop such as danger.
When to use VaneUI props instead
VaneUI provides boolean props for most common styling needs. Always prefer props over Tailwind classes when a prop exists. This ensures the styling integrates with the size system, responds to theme changes, and works with ThemeProvider overrides.
| Instead of Tailwind | Use VaneUI Prop |
|---|---|
className="font-bold" | fontBold |
className="text-center" | textCenter |
className="uppercase" | uppercase |
className="rounded-full" | pill |
className="flex items-center" | flex itemsCenter |
className="cursor-pointer" | cursorPointer |
className="gap-4" | Use size props (xs through xl) |
className="bg-red-500" | danger filled |
className is for things VaneUI props don't cover
Good uses of className:
{/* Custom width/height */}<Card className="w-full max-w-md">Fixed-width card</Card>
{/* Stacking order: the sticky prop already pins the row to the top edge */}<Row sticky className="z-10">Sticky header</Row>
{/* Animations */}<Badge className="animate-pulse">Live</Badge>
{/* Gradients */}<Card className="bg-gradient-to-br from-indigo-500 to-purple-600"> Gradient card</Card>
{/* Aspect ratio */}<Img className="aspect-video" src="/banner.jpg" alt="Banner" />className pitfalls to avoid
Don't override gap with Tailwind classes
Gap is controlled by VaneUI's size system. Use size props instead:
// Wrong: fights the size system<Row className="gap-10">Content</Row>
// Right: gap scales with size<Row lg>Content</Row><Row xs>Tight content</Row>Don't override padding with Tailwind classes
Padding is also size-driven and scales proportionally:
// Wrong<Card className="p-8">Content</Card>
// Right: padding scales with size<Card lg>Content</Card>Don't use appearance-colored Tailwind classes when an appearance prop exists
// Wrong: bypasses the theme system<Button className="bg-red-500 text-white border-red-600">Delete</Button>
// Right: uses the theme system<Button danger filled>Delete</Button>Beware of className on typography components
Typography components have built-in letter spacing, line height, and font size that scale with the size prop. Overriding these with Tailwind classes breaks the proportional scaling:
// Wrong: breaks size scaling<Text className="text-2xl tracking-wide leading-10">Content</Text>
// Right: use size props<Text xl>Content</Text>