From 3399e46959a1e1d96c298f934db8c845d3c32a20 Mon Sep 17 00:00:00 2001 From: Mateus Werneck <87713168+Mwrnk@users.noreply.github.com> Date: Fri, 13 Nov 2026 14:22:56 -0300 Subject: [PATCH 1/2] =?UTF-8?q?Recognize=20`abs(=E2=80=A6)`=20and=20`sign(?= =?UTF-8?q?=E2=80=A6)`=20as=20math=20functions=20in=20arbitrary=20values?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changelog/abs-sign-math-functions.md | 3 +++ packages/tailwindcss/src/utilities.test.ts | 5 +++++ .../tailwindcss/src/utils/decode-arbitrary-value.test.ts | 6 ++++++ packages/tailwindcss/src/utils/math-operators.ts | 2 ++ 4 files changed, 16 insertions(+) create mode 100644 .changelog/abs-sign-math-functions.md diff --git a/.changelog/abs-sign-math-functions.md b/.changelog/abs-sign-math-functions.md new file mode 100644 index 000000000000..597c67c10ce0 --- /dev/null +++ b/.changelog/abs-sign-math-functions.md @@ -0,0 +1,3 @@ +### Fixed + +- Add whitespace around math operators in `abs(…)` and `sign(…)`, and infer them as a length (e.g. `text-[abs(var(--size))]` generates `font-size` instead of `color`) diff --git a/packages/tailwindcss/src/utilities.test.ts b/packages/tailwindcss/src/utilities.test.ts index ca6d87f5a422..45b8290760e9 100644 --- a/packages/tailwindcss/src/utilities.test.ts +++ b/packages/tailwindcss/src/utilities.test.ts @@ -26597,6 +26597,7 @@ test('text', async () => { 'text-[clamp(1rem,2rem,3rem)]', 'text-[clamp(1rem,var(--size),3rem)]', 'text-[clamp(1rem,var(--size),3rem)]/9', + 'text-[abs(var(--size))]', 'text-[--spacing(2)]', 'text-[1cap]', 'text-[1ic]', @@ -26789,6 +26790,10 @@ test('text', async () => { font-size: 50%; } + .text-\\[abs\\(var\\(--size\\)\\)\\] { + font-size: abs(var(--size)); + } + .text-\\[absolute-size\\:var\\(--my-size\\)\\] { font-size: var(--my-size); } diff --git a/packages/tailwindcss/src/utils/decode-arbitrary-value.test.ts b/packages/tailwindcss/src/utils/decode-arbitrary-value.test.ts index 5727c58cc92d..8175194584ba 100644 --- a/packages/tailwindcss/src/utils/decode-arbitrary-value.test.ts +++ b/packages/tailwindcss/src/utils/decode-arbitrary-value.test.ts @@ -152,6 +152,12 @@ describe('adds spaces around math operators', () => { ['round(1+2,1+3)', 'round(1 + 2, 1 + 3)'], ['round(to-zero,1+2,1+3)', 'round(to-zero, 1 + 2, 1 + 3)'], + // abs(…) and sign(…) functions + ['abs(20%-100px)', 'abs(20% - 100px)'], + ['sign(10px-20px)', 'sign(10px - 20px)'], + ['calc(abs(1rem-2rem)*2)', 'calc(abs(1rem - 2rem) * 2)'], + ['calc(1px*sign(var(--x)-50%))', 'calc(1px * sign(var(--x) - 50%))'], + // Nested parens in non-math functions don't format their contents ['env((safe-area-inset-bottom))', 'env((safe-area-inset-bottom))'], diff --git a/packages/tailwindcss/src/utils/math-operators.ts b/packages/tailwindcss/src/utils/math-operators.ts index 6ec4e329c7d6..dd0df66d5cc4 100644 --- a/packages/tailwindcss/src/utils/math-operators.ts +++ b/packages/tailwindcss/src/utils/math-operators.ts @@ -37,6 +37,8 @@ const MATH_FUNCTIONS = [ 'log', 'exp', 'round', + 'abs', + 'sign', ] const MATH_FUNCTIONS_SET = new Set(MATH_FUNCTIONS) From 51f94f9e206c44bdac9a76be32d59caa5459e68e Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Wed, 18 Nov 2026 17:55:22 +0100 Subject: [PATCH 2/2] Sort the list of math functions alphabetically The order has no effect: the list is only used for lookups. --- .../tailwindcss/src/utils/math-operators.ts | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/tailwindcss/src/utils/math-operators.ts b/packages/tailwindcss/src/utils/math-operators.ts index dd0df66d5cc4..d097553f9a9c 100644 --- a/packages/tailwindcss/src/utils/math-operators.ts +++ b/packages/tailwindcss/src/utils/math-operators.ts @@ -18,27 +18,27 @@ const PERCENT = 0x25 const UNDERSCORE = 0x5f const MATH_FUNCTIONS = [ - 'calc', - 'min', - 'max', - 'clamp', - 'mod', - 'rem', - 'sin', - 'cos', - 'tan', - 'asin', + 'abs', 'acos', + 'asin', 'atan', 'atan2', - 'pow', - 'sqrt', + 'calc', + 'clamp', + 'cos', + 'exp', 'hypot', 'log', - 'exp', + 'max', + 'min', + 'mod', + 'pow', + 'rem', 'round', - 'abs', 'sign', + 'sin', + 'sqrt', + 'tan', ] const MATH_FUNCTIONS_SET = new Set(MATH_FUNCTIONS)