Skip to main content

Configuration

base

Props that always apply, regardless of variants.
Any valid prop for the component works here: className, style, event handlers, ARIA attributes, etc.

variants

Define your variant options. Each variant is a named group with multiple options.

defaultVariants

Set which variant values apply when not specified.

compoundVariants

Apply styles when specific variant combinations occur.
When color="primary" AND variant="outline", the matching compound variant applies.

context

Connect to a shared context for variant propagation. See Context for details.

Props Merging

better-styled intelligently merges props from different sources.

Priority Order

From lowest to highest priority:
  1. πŸ₯‰ base
  2. πŸ₯ˆ variants
  3. πŸ₯ˆ compoundVariants
  4. πŸ₯‡ Props passed directly to the component

className

Classes are merged using tailwind-merge, which handles Tailwind conflicts intelligently.

style

Style objects are merged with Object.assign. Later values override earlier ones.

Event Handlers

Here’s something special: event handlers are composed, not overwritten.
This is powerful for analytics, logging, or any case where you want to add behavior without replacing it.

Works With Any Component

styled() works with HTML elements, React components, and React Native components.
The only requirement: the component must accept the props you define in your variants.

TypeScript

Types are fully inferred. No manual typing needed.

Next: Variants

Deep dive into the variant system