Utility strings
Write a utility string with the Tailwind CSS classes you know.
style ( " rounded-control px-4 py-2 " ) JavaScript conditions
Combine utilities with JavaScript conditions. A false condition contributes no classes.
style ( " rounded-control px-4 py-2 " , emphasized && " shadow-sm " ) Arrays
Compose strings and conditional values in arrays. Keep related inputs together.
style ( [ " rounded-control px-4 py-2 " , emphasized && " shadow-sm " ] ) CSS states
Use an attribute to select CSS rules. Toggling aria-pressed updates the button while its class name stays the same.
style (
[ " rounded-control px-4 py-2 " , emphasized && " shadow-sm " ] ,
{ " aria-pressed : " : " bg-action text-action-foreground " } ,
) Save emphasized = true
aria-pressed="true"
Toggle the button state.
Variant groups
Group strings and arrays under one variant. The aria-pressed state applies the grouped rules together.
style (
[ " rounded-control px-4 py-2 " , emphasized && " shadow-sm " ] ,
{
" aria-pressed : " : [ " bg-action text-action-foreground " , " font-medium " ] ,
} ,
) Save emphasized = true
aria-pressed="true"
Toggle the button state.
Nested variants
Nest variants to describe conditions that apply together. Hover styles only apply while the button is pressed.
style (
[ " rounded-control px-4 py-2 " , emphasized && " shadow-sm " ] ,
{
" aria-pressed : " : [
" bg-action text-action-foreground font-medium " ,
{ " hover : " : " bg-action-hover " } ,
] ,
} ,
) Save emphasized = true
aria-pressed="true"
Toggle the button state. Hover to preview.
CSS custom properties
Pass a value through a CSS custom property and reference it from utilities. CSS can use the value across different rules.
style (
[ " rounded-control px-4 py-2 " , emphasized && " shadow-sm " ] ,
{
" --accent " : accent ,
" aria-pressed : " : [
" bg-(--accent) text-action-foreground font-medium " ,
{ " hover : " : " brightness-110 " } ,
] ,
} ,
) Save emphasized = true
aria-pressed="true"
accent = var(--color-action-hover)
Toggle the button state. Hover to preview.