cnippet/ui
  1. docs
  2. handbook
  3. customization

guides

Customization

Change how components look and behave — with className, data attributes, new variants, edited defaults and wrapper components.

cnippet ui components are copied into your project, so you can change anything. Start with the lightest option that does the job:

className

Every part accepts className. Classes are merged with tailwind-merge, so yours win when they conflict with the built-in ones:

h-11 replaces the Button's own height instead of fighting it. Classes that don't conflict are added.

Use cn from @/lib/utils to merge classes in your own components the same way:

Styling parts and states

data-slot

Every part has a data-slot attribute, such as data-slot="card-title" or data-slot="button". Use it to style a part from a parent without passing className to each one:

**: targets any descendant, and *: targets direct children only. Each component page lists its slots in the Anatomy section.

State attributes

Parts expose their state as data attributes. Style them with Tailwind's data-* variants instead of conditional classes:

Common attributes:

The API Reference on each component page lists every attribute that part supports.

Enter and exit animations

Popups animate with data-starting-style and data-ending-style. They are set for one frame when the popup mounts and while it unmounts, so a CSS transition runs between them and the normal style. To change an animation, edit those classes:

Base UI waits for the transition to finish before removing the popup, so you don't need extra state.

Adding a variant

Components with variants, such as Button, Badge, Alert, Toggle and Group, define them with cva. Open the component file and add an entry:

components/ui/button.tsx

The variant prop type comes from VariantProps<typeof buttonVariants>, so TypeScript picks up the new value right away:

Sizes work the same way under size. To change what you get without a prop, edit defaultVariants.

Using variants on other elements

The variant functions are exported, so you can give any element a component's styles:

For another React component, prefer the render prop: <Button render={<Link href="/docs" />}>. It keeps the Button's props and behavior, not only its classes.

Changing defaults

Default props live in the component function, so you can change them in one place. For example, to open every popover above its trigger:

components/ui/popover.tsx

For behavior that isn't a prop yet, add one. Keep the rest of the props flowing through with ...props so nothing else breaks.

Wrapping components

When you use the same combination in many places, build a component on top instead of editing the original. Your changes then survive when you update the component.

components/submit-button.tsx
components/icon-button.tsx

Keep wrappers outside components/ui/. That folder stays a copy of the registry, which makes updates a clean overwrite.

Editing vs. wrapping

Before you update an edited component, run npx shadcn@latest add @cnippet/<name> --diff to see what changed upstream, then merge by hand or overwrite and re-apply your edit.