shadcn/uiStylingError Fix2026 Updated

shadcn/ui Component Style OverrideNot Working — Fixed [2026]

Also covers: cn() merging · tailwind-merge · cva() variants · CSS variables · extending components

January 20266 min readshadcn/ui · Tailwind CSS · tailwind-merge · cva

⚡ The Problem

Error
// 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

How cn() works inside shadcn components
// 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-merge

Why 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).

1

Pass className and Let cn() Merge Correctly

Your className is appended last — should win
2 min
Correct override patterns
import { 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>
2

Use tailwind-merge to Resolve Class Conflicts

Custom components not merging correctly
2 min

When building your own components on top of shadcn, always use cn() to merge classes — never string concatenation.

Use cn() in your own components
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
}
3

Add Custom Variants with cva()

Add a 'success' or 'warning' variant to Button
5 min
components/ui/button.tsx — add custom variant
import { 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>
4

Override CSS Variables for Global Theming

Change the primary color across all components
3 min

For brand-wide color changes, update the CSS variables in globals.css instead of overriding classes on every component.

globals.css — change primary color
: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 */
}
5

Extend the Component Directly

You own the code — just modify it
5 min

Unlike npm packages, shadcn components are copied into your project. You can modify them freely — add props, change markup, wrap with additional logic.

components/ui/button.tsx — add an icon prop
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

Frequently Asked Questions

Why does my className not override shadcn/ui component styles?+
Tailwind CSS class conflicts are resolved by the order classes appear in the generated CSS, not the order in your HTML. When you add a className to a shadcn component, both your class and the component's class exist. tailwind-merge (used inside cn()) resolves this by keeping only the last class in conflicting groups — but only if you pass your className through cn() correctly.
What is tailwind-merge and why does shadcn/ui use it?+
tailwind-merge is a library that intelligently merges Tailwind CSS classes, removing conflicts. For example, merging 'px-4 px-6' produces 'px-6' — the last value wins. Without it, both classes would exist in the HTML and CSS cascade order determines which wins, leading to unpredictable results.
Can I change shadcn/ui button colors?+
Yes. Either pass a custom className with your color classes, override the CSS variables (--primary) in globals.css, or add a new variant using cva() inside the Button component file. Since you own the component code, you can modify it directly.
What is cva() in shadcn/ui?+
cva() (class-variance-authority) is a utility that creates variant-based class sets. shadcn components use cva() to define named variants (like 'default', 'destructive', 'outline') and sizes ('sm', 'md', 'lg'). You can add new variants by adding cases to the cva() call in the component file.
How do I add a new button variant to shadcn/ui?+
Open components/ui/button.tsx and find the cva() call. Add your new variant name and its Tailwind classes inside the variants object. Then use it as <Button variant='your-variant'>. Since you own the file, you can freely extend it.
Can I globally change the border radius of all shadcn/ui components?+
Yes. In globals.css, change the --radius CSS variable: --radius: 0.75rem changes all components that use rounded-md to a larger radius. You can also change it per component by passing className='rounded-none' to override the default.

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