Skip to content

Fix negation of theme() in arbitrary values#19928

Open
snaptopixel wants to merge 1 commit intotailwindlabs:v3from
snaptopixel:fix/negate-theme-arbitrary-value
Open

Fix negation of theme() in arbitrary values#19928
snaptopixel wants to merge 1 commit intotailwindlabs:v3from
snaptopixel:fix/negate-theme-arbitrary-value

Conversation

@snaptopixel
Copy link
Copy Markdown

Problem

Using a negative modifier with theme() inside an arbitrary value produces no CSS output.

  • ms-[theme(margin.1)] — works
  • -ms-[10px] — works
  • -ms-[theme(margin.1)] — no output

Cause

negateValue() in src/util/negateValue.js doesn't recognize theme() as a negatable function. It falls through all conditions and returns undefined, causing the utility to be silently dropped.

Fix

Added 'theme' to the numericFunctions list so theme() values get wrapped in calc(... * -1), which the PostCSS theme() resolver then processes downstream.

Tests

  • Unit test (negateValue.test.js): negateValue('theme(margin.1)') returns calc(theme(margin.1) * -1)
  • Integration test (arbitrary-values.test.js): -mt-[theme(spacing.1)] produces margin-top: -0.25rem

When using a negative modifier with theme() inside an arbitrary value
(e.g. `-ms-[theme(margin.1)]`), no CSS was generated because
`negateValue` did not recognize `theme()` as a negatable function.

Added `theme` to the list of numeric functions in `negateValue` so
that `theme()` values are wrapped in `calc(... * -1)` and then
resolved by the PostCSS theme() plugin downstream.
@snaptopixel snaptopixel requested a review from a team as a code owner April 13, 2026 18:12
@RobinMalfait
Copy link
Copy Markdown
Member

RobinMalfait commented Apr 13, 2026

Edit: This is for Tailwind CSS v3.

Hey! Thanks for the PR, but where do you see this issue? This should work as-is today already:
image
https://play.tailwindcss.com/bGXXIU9Wai

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.

2 participants