Skip to content

Fix sign spacing for channel values in CSS relative color syntax#19286

Closed
LeSingh1 wants to merge 2 commits into
prettier:mainfrom
LeSingh1:fix/css-relative-color-sign
Closed

Fix sign spacing for channel values in CSS relative color syntax#19286
LeSingh1 wants to merge 2 commits into
prettier:mainfrom
LeSingh1:fix/css-relative-color-sign

Conversation

@LeSingh1

@LeSingh1 LeSingh1 commented Jun 4, 2026

Copy link
Copy Markdown

Fixes #18320

In the CSS relative color syntax, a leading + or - on a channel value is a sign, not a math operator. Prettier was inserting a space after it, which changes the meaning of the value because the sign makes the channel adjustment relative instead of absolute.

Before this change:

:root {
  --color-my-green: oklch(from rgb(255, 0, 0) l c +130);
}

was printed as:

:root {
  --color-my-green: oklch(from rgb(255, 0, 0) l c + 130);
}

The + 130 and +130 are not equivalent here, so the output was producing different CSS than the input.

The comma-separated value group printer now detects relative color function groups (the ones that start with the from keyword inside rgb, hsl, hwb, lab, lch, oklab, oklch, or color) and keeps a sign that is directly attached to a number attached, instead of treating it as a binary operator. A +/- that is separated from the number by whitespace, or one that appears inside calc(), is left untouched, so genuine math is still spaced normally.

I added a fixture under tests/format/css/color/relative-color-syntax.css covering each relative color function plus a calc() channel to confirm normal math spacing is preserved. The existing legacy color() adjuster snapshots are unchanged.

LeSingh1 added 2 commits June 3, 2026 22:52
In the CSS relative color syntax (e.g. `oklch(from red l c +130)`), a
leading `+`/`-` on a channel value is a sign rather than a math operator.
Printing a space after it (`+ 130`) changes the value, since the sign makes
the channel relative instead of absolute. Detect relative color function
groups (those starting with `from`) and keep the sign attached to the number.
@netlify

netlify Bot commented Jun 4, 2026

Copy link
Copy Markdown

Deploy Preview for prettier ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit f919ff0
🔍 Latest deploy log https://app.netlify.com/projects/prettier/deploys/6a2112b60306c20008738031
😎 Deploy Preview https://deploy-preview-19286--prettier.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Jun 4, 2026

Copy link
Copy Markdown

Deploy Preview for prettier ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 5d3779f
🔍 Latest deploy log https://app.netlify.com/projects/prettier/deploys/6a2112c40306c2000873868d
😎 Deploy Preview https://deploy-preview-19286--prettier.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@fisker fisker closed this Jun 4, 2026
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.

Broken relative formatting in css oklch(from ... +130)

2 participants