Skip to main content
Equinusocio
June 22, 2023

Add way to change opacity for color variables alias, fills, strokes, etc

  • June 22, 2023
  • 158 replies
  • 17886 views

When aliasing a color variable to another (img 1), or using it directly on an element (img 2), we should be able to override the opacity without the need to create a variable for each transparency variation:

Cant override opacity in the alias:

CleanShot 2023-06-22 at 10.09.00

Example 2

Cant override the fill opacity:

158 replies

Alice_Holm
Active Member
June 30, 2023

Need this!

Florian_Joergensen
June 30, 2023

+1 we need this

Michael61
June 30, 2023

+1 Badly need this!

July 5, 2023

+1 Need this badly

Amirfarhad
July 11, 2023

It’s virtually impossible to have a solid emphasis-level management for colors right now since it doesn’t make sense to add opacity to your “first tier tokens” and palettes in order to have variations on your aliased ones. Hopefully it gets added.

Oleg_Stepanov1
New Participant
July 20, 2023

+1 Miss this feature too

jjcm
Figmate
Figmate
July 25, 2023

Hey all! PM for the variables stream here. Would love to understand more as we’ve seen this request a lot. In the example above where @Equinusocio has brand/40 as a variable, if it were set to 50% opacity, how would you represent that in code? What would the equivalent of this be in css or on whatever platform you’re outputting to?

I want to make sure we’re approaching this in the right way, so any info here would help.

Chris_Leckie
New Member
July 25, 2023

We’re hitting this same issue. We’re setting semantic usage of Primary, secondary and tertiary labels which are percentages of solid at the primitive level.

Chris_Leckie
New Member
July 25, 2023

We can set a layer percentage fill transparency but that is a very messy workaround.

Equinusocio
July 25, 2023

Let’s say we have color-red and background variables where background is an alias of color-red but 20% transparent. If we output to CSS we have a couple of ways.

1. Using color-mix (well supported)

 --color-red: #ff0000;
 --background: color-mix(in oklch, transparent, var(--color-red) 80%);

The colorspace can be any of the supported ones by Figma (HSL, RGB, etc…). Unfortunately, the color space is mandatory in color-mix() function. Returns a --color-red fill with 80% opacity (or 20% transparency).

2. Using relative colors (less supported)

 --color-red: #ff0000;
 --background: rgb(from var(--color-red) r g b / 20%);

This is more intuitive and produces a red 20% without doing mental calc. If using different color spaces, the returned channels are different. Eg.

 --color-red: #ff0000;
 --background: oklch(from var(--color-red) l c h / 20%);

With this new function, we can also perform calculations on the channels.

 --color-red: #ff0000;
 --background: rgb(from var(--color-red) r calc(g - 50) b / 20%);

The above solutions keep the variables dynamic preventing their values from becoming fixed. If we change color-red, also background will change

There is also a third option, using HEX colors with alpha channels, which is supported everywhere but requires values to be in any RGB color space and static values, losin aliases.