Skip to content

Fix CSS variables in gradients (#1515)#1544

Merged
ai merged 2 commits intopostcss:mainfrom
serger777:main
Feb 25, 2026
Merged

Fix CSS variables in gradients (#1515)#1544
ai merged 2 commits intopostcss:mainfrom
serger777:main

Conversation

@serger777
Copy link
Contributor

Fix CSS variables in gradients (#1515)

Problem

When CSS variables are present in linear gradients like linear-gradient(var(--config)),
autoprefixer generates invalid -webkit-gradient() syntax that breaks when the variable
contains comma-separated values.

Solution

Added detection for var() in gradient strings. When CSS variables are found,
skip old webkit gradient conversion and use only -webkit-linear-gradient().

Prevent generation of invalid -webkit-gradient() syntax when CSS variables
are present in linear gradients. When var() is detected, skip old webkit
gradient conversion and use only -webkit-linear-gradient() instead.

This fixes cases where linear-gradient(var(--config)) would generate
invalid CSS if the variable contains comma-separated values.
@ai
Copy link
Member

ai commented Feb 25, 2026

Can you show an example of input CSS, current output and output after the fix?

I am not sure that I understood the use case right.

Adds test case that verifies CSS variables in gradients skip old webkit
gradient conversion and use only -webkit-linear-gradient() syntax.

This ensures 100% test coverage for the new var() detection logic.
@serger777
Copy link
Contributor Author

serger777 commented Feb 25, 2026

Can you show an example of input CSS, current output and output after the fix?

I am not sure that I understood the use case right.

Input CSS:

   --colors: 45deg, red, blue, green;                                                                                                                                                                                                         
  .example { background: linear-gradient(var(--colors)); }   

Before Fix:

  background: -webkit-gradient(linear, left top, left bottom, from(var(--colors)));

When browser substitutes variable → Invalid CSS:

  -webkit-gradient(linear, left top, left bottom, from(45deg, red, blue, green))

from() only accepts one color, not multiple values.

After Fix:

  background: -webkit-linear-gradient(var(--colors));

When browser substitutes variable → Valid CSS:

  -webkit-linear-gradient(45deg, red, blue, green)

@ai ai merged commit 5239823 into postcss:main Feb 25, 2026
8 checks passed
@ai
Copy link
Member

ai commented Feb 25, 2026

Thanks. Released in 10.4.25.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants