Skip to content

Prefix background-clip: text when it is one of several layers - #1581

Open
JohanesPeterV wants to merge 1 commit into
postcss:mainfrom
JohanesPeterV:fix/background-clip-text-layers
Open

JohanesPeterV wants to merge 1 commit into
postcss:mainfrom
JohanesPeterV:fix/background-clip-text-layers

Conversation

@JohanesPeterV

Copy link
Copy Markdown

background-clip: text gets -webkit-background-clip, but the same keyword in a list of layers doesn't. A list like text, border-box is how you put gradient text on a solid background with one element. BackgroundClip#check() compares the whole value with text, so text, border-box never matches. Browsers that still need the prefix (Chrome before 120, which the default Browserslist still includes as Chrome 109) drop the unprefixed declaration, so the gradient fills the whole box instead of the letters.

Input CSS

.hero-title {
  background-image: linear-gradient(90deg, #ff6a00, #ee0979), linear-gradient(#111, #111);
  background-clip: text, border-box;
  color: transparent;
}

Current output CSS

Same as the input. No -webkit-background-clip.

Output after the fix

.hero-title {
  background-image: linear-gradient(90deg, #ff6a00, #ee0979), linear-gradient(#111, #111);
  -webkit-background-clip: text, border-box;
          background-clip: text, border-box;
  color: transparent;
}

check() now splits the value with list.comma() and prefixes when any layer is text.

Behavior change: only background-clip lists with a text layer. text inside a function like var(--clip, text) is still left alone, and Chrome 120+ gets no prefix, same as the single keyword.

Autoprefixer 10.7.1, default Browserslist.

Before (main):

before.mp4

After:

after.mp4

Tests: added an h1 case to test/cases/background-clip.css and .out.css. On main that case fails (288 of 289 pass). With the fix, pnpm test passes: 289 tests, 100% line coverage, oxlint and size-limit. oxfmt --check is clean on the changed file.

Found and fixed with AI help (GPT-6.2 Astra in Codex, Claude Opus 5.5 in Claude Code).

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.

1 participant