Signature
Parameters
The base component to style. Can be:
- HTML element string:
"button","div","span" - React component:
Link,Pressable - Another styled component
Configuration object with the following properties:
Config Properties
Props that always apply, regardless of variants.
Variant definitions. Each key is a variant name, each value is an object mapping option names to props.
When using
context, variants defined here but not in createStyledContext() become local variants. They work on this component but don’t propagate to children. See Local Variants.Default values for variants when not specified.
Array of compound variant definitions. Each applies when all conditions match.
Context for variant propagation between parent and child components.
Returns
A React component with:- All props from the base component
- Variant props based on your config
- Automatic type inference
Examples
Basic
With Context
With React Native
⚠️ Use
isDisabled instead of disabled to avoid shadowing Pressable’s native prop.Boolean Variants
You only need to define
true. The false case uses base styles by default.Compound Variants
Props Merging Behavior
| Prop Type | Merge Behavior |
|---|---|
className | 🔀 Merged with tailwind-merge |
style | 🔀 Object merged with Object.assign |
Functions (onClick, etc.) | ⛓️ Composed (all execute) |
| Other props | ⬆️ Later values override |
- 🥉
base - 🥈
variants - 🥈
compoundVariants - 🥇 Direct props
See Also
- styledConfig() — Share a config between multiple components
- styled() Concept Guide
- Variants
- Context