Fix CSS variables in gradients (#1515)#1544
Merged
ai merged 2 commits intopostcss:mainfrom Feb 25, 2026
Merged
Conversation
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.
Member
|
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.
Contributor
Author
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) |
Member
|
Thanks. Released in 10.4.25. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 variablecontains 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().