shadcn/ui Component Style OverrideNot Working — Fixed [2026]
Also covers: cn() merging · tailwind-merge · cva() variants · CSS variables · extending components
⚡ The Problem
// className added but component still looks the same
<Button className="bg-red-500 text-white">Click me</Button>
// → Button still shows default indigo/primary color✅ Root cause — Tailwind class conflict, cn() resolves it
// Inside button.tsx — cn() merges classes, tailwind-merge resolves conflicts
className={cn(buttonVariants({ variant, size }), className)}
// Your className is appended last — wins the conflict via tailwind-mergeWhy shadcn/ui Style Overrides Don't Apply
All shadcn/ui components use the cn() function to merge their built-in classes with your className prop. The cn() function uses tailwind-merge internally, which resolves conflicts between Tailwind utilities — the last class in conflicting groups wins. Your className is appended last, so it should win.
If your override isn't working, usually the component isn't forwarding your className through cn() correctly, or the classes aren't actually conflicting (they target different CSS properties).
Pass className and Let cn() Merge Correctly
Your className is appended last — should winimport { Button } from "@/components/ui/button"
// ✅ Override background color
<Button className="bg-emerald-600 hover:bg-emerald-700 text-white">
Custom green
</Button>
// ✅ Override width
<Button className="w-full">Full width button</Button>
// ✅ Override padding
<Button className="px-8 py-3">Larger padding</Button>
// ✅ Override border radius
<Button className="rounded-full">Pill button</Button>
// ❌ Won't work — !important not needed, tailwind-merge handles conflicts
<Button className="!bg-red-500">This is unnecessary</Button>Use tailwind-merge to Resolve Class Conflicts
Custom components not merging correctlyWhen building your own components on top of shadcn, always use cn() to merge classes — never string concatenation.
import { cn } from "@/lib/utils"
import { Button } from "@/components/ui/button"
// ❌ String concatenation — conflicts not resolved
function DangerButton({ className, ...props }) {
return <Button className={"bg-red-500 " + className} {...props} />
// If className includes another bg-*, both classes exist — unpredictable
}
// ✅ cn() — conflicts resolved correctly by tailwind-merge
function DangerButton({ className, ...props }) {
return (
<Button
className={cn("bg-red-500 hover:bg-red-600 text-white", className)}
{...props}
/>
)
// className bg wins because it comes AFTER "bg-red-500" in the cn() call
}Add Custom Variants with cva()
Add a 'success' or 'warning' variant to Buttonimport { cva } from "class-variance-authority"
const buttonVariants = cva(
"inline-flex items-center justify-center ...", // base classes
{
variants: {
variant: {
default: "bg-primary text-primary-foreground hover:bg-primary/90",
destructive: "bg-destructive text-destructive-foreground ...",
outline: "border border-input bg-background ...",
// ✅ Add your custom variants here:
success: "bg-emerald-600 text-white hover:bg-emerald-700",
warning: "bg-amber-500 text-white hover:bg-amber-600",
brand: "bg-violet-600 text-white hover:bg-violet-700",
},
size: {
default: "h-10 px-4 py-2",
sm: "h-9 rounded-md px-3",
lg: "h-11 rounded-md px-8",
xl: "h-12 rounded-md px-10 text-base", // ✅ custom size
},
},
defaultVariants: {
variant: "default",
size: "default",
},
}
)
// Usage:
<Button variant="success">Saved!</Button>
<Button variant="warning" size="xl">Warning</Button>Override CSS Variables for Global Theming
Change the primary color across all componentsFor brand-wide color changes, update the CSS variables in globals.css instead of overriding classes on every component.
:root {
/* Change primary from indigo to violet */
--primary: 262 83% 58%; /* violet-600 */
--primary-foreground: 0 0% 100%; /* white */
/* Change border radius for all components */
--radius: 0.75rem; /* more rounded */
/* Change ring/focus color */
--ring: 262 83% 58%;
}
.dark {
--primary: 263 69% 72%; /* lighter violet for dark mode */
}Extend the Component Directly
You own the code — just modify itUnlike npm packages, shadcn components are copied into your project. You can modify them freely — add props, change markup, wrap with additional logic.
import { Loader2 } from "lucide-react"
interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
variant?: VariantProps<typeof buttonVariants>["variant"]
size?: VariantProps<typeof buttonVariants>["size"]
isLoading?: boolean // ← custom prop added directly to shadcn component
asChild?: boolean
}
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
({ className, variant, size, isLoading, children, disabled, ...props }, ref) => {
return (
<button
className={cn(buttonVariants({ variant, size }), className)}
ref={ref}
disabled={isLoading || disabled}
{...props}
>
{isLoading && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
{children}
</button>
)
}
)
// Usage:
<Button isLoading={isPending}>
{isPending ? "Saving..." : "Save"}
</Button>Prevention
- Always use cn() when merging classes — never string concatenation or template literals
- Remember: tailwind-merge resolves conflicts by keeping the last class in a conflict group
- For brand-wide changes (colors, radius), use CSS variables — not per-component overrides
- Add custom variants to cva() in the component file instead of duplicating the component
- Since you own the component code, extend it directly with new props when needed
- Test overrides in both light and dark mode — CSS variable changes affect both
Frequently Asked Questions
Why does my className not override shadcn/ui component styles?+−
What is tailwind-merge and why does shadcn/ui use it?+−
Can I change shadcn/ui button colors?+−
What is cva() in shadcn/ui?+−
How do I add a new button variant to shadcn/ui?+−
Can I globally change the border radius of all shadcn/ui components?+−
Need Expert Help?
We Build Custom Design Systems with shadcn/ui
Softplix engineers create branded component libraries on shadcn/ui — custom variants, themes, and extended components. Let us help.
Talk to an Engineer