Color opacity modifier
How to dynamically set the opacity of a raw color or color token
Every color related style property can use the
color-mix
shortcut to apply opacity to a color.
Syntax
The general syntax is {color}/{opacity}
. For example: bgColor="page.surface.100/40"
.
Usage
1<Text bgColor="danger.bg.initial/40" color="danger.text.initial">2 Hello World3</Text>
This will generate something like this:
1.css-sxdf {2 --mix-background: color-mix(in srgb, var(--colors-danger-bg-initial) 40%, transparent);3 background-color: var(--mix-background, var(--colors-danger-bg-initial));4 color: var(--colors-danger-text-initial);5}
CSS Variables
This feature can be used in css variables as well. This is useful for creating one-off color token in a component.
The token reference syntax {}
is required for this to work.
1<Box css={{ "--bg": "{colors.danger.bg.initial/40}" }}>2 <Text>Hello World</Text>3 <Box bg="var(--bg)" />4</Box>
On this page