Skip to main content
Equinusocio
Jun 22, 2023 8:10 AM UTC

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

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:

    159 replies

    Alice_Holm
    Active Member
    Jun 30, 2023 10:42 AM UTC

    Need this!

    Florian_Joergensen
    Jun 30, 2023 3:51 PM UTC

    +1 we need this

    Michael61
    Jun 30, 2023 8:56 PM UTC

    +1 Badly need this!

    Jul 5, 2023 2:06 AM UTC

    +1 Need this badly

    Amirfarhad
    Jul 11, 2023 9:37 AM UTC

    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
    Jul 20, 2023 2:36 PM UTC

    +1 Miss this feature too

    jjcm
    Figmate
    Figmate
    Jul 25, 2023 3:33 PM UTC

    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
    Jul 25, 2023 3:49 PM UTC

    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
    Jul 25, 2023 3:51 PM UTC

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

    Equinusocio
    Jul 25, 2023 3:59 PM UTC

    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.