Skip to content
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Oxide: drop invalid UTF-8 candidates ([#20389](https://github.com/tailwindlabs/tailwindcss/pull/20389))
- `@tailwindcss/vite` no longer forces a full page reload for external files (e.g.: `.php` files) ([#20414](https://github.com/tailwindlabs/tailwindcss/issues/20414))
- Canonicalization: don't merge utilities that reference different theme variables set to CSS-wide keywords like `unset` ([#20417](https://github.com/tailwindlabs/tailwindcss/pull/20417))
- Don't space out `and`, `or`, and `not` inside function calls like `selector(a:not(.foo))` in `supports-[…]` variants ([#20420](https://github.com/tailwindlabs/tailwindcss/pull/20420))

## [4.3.3] - 2026-07-16

Expand Down
37 changes: 37 additions & 0 deletions packages/tailwindcss/src/variants.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1424,6 +1424,43 @@ test('sorting `min` and `max` should sort by unit, then by value, then alphabeti
`)
})

test('supports: `and`, `or`, and `not` inside function calls are not spaced out', async () => {
expect(
await run([
'supports-[selector(a:not(.foo))]:flex',
'supports-[selector(a:is(.and,.or))]:flex',
'supports-[(display:grid)or(display:flex)]:grid',
'supports-[not(display:grid)]:flex',
]),
).toMatchInlineSnapshot(`
"
@supports (display: grid) or (display: flex) {
.supports-\\[\\(display\\:grid\\)or\\(display\\:flex\\)\\]\\:grid {
display: grid;
}
}

@supports not (display: grid) {
.supports-\\[not\\(display\\:grid\\)\\]\\:flex {
display: flex;
}
}

@supports selector(a:is(.and,.or)) {
.supports-\\[selector\\(a\\:is\\(\\.and\\,\\.or\\)\\)\\]\\:flex {
display: flex;
}
}

@supports selector(a:not(.foo)) {
.supports-\\[selector\\(a\\:not\\(\\.foo\\)\\)\\]\\:flex {
display: flex;
}
}
"
`)
})

test('supports', async () => {
expect(
await run([
Expand Down
20 changes: 18 additions & 2 deletions packages/tailwindcss/src/variants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -937,8 +937,24 @@ export function createVariants(theme: Theme): Variants {
// other functions, we can use the value as-is.
if (/^[\w-]*\s*\(/.test(value)) {
// Chrome has a bug where `(condition1)or(condition2)` is not valid, but
// `(condition1) or (condition2)` is supported.
let query = value.replace(/\b(and|or|not)\b/g, ' $1 ')
// `(condition1) or (condition2)` is supported. Only space out keywords
// in the condition itself, not inside function calls like
// `selector(a:not(.foo))` where `not` is part of a selector.
let parens: boolean[] = []
let inFunction = 0
let query = value.replace(/[()]|\b(?:and|or|not)\b/g, (match, offset: number) => {
if (match === '(') {
let head = value.slice(0, offset)
let isFunction = /[\w-]$/.test(head) && !/(?:^|[^\w-])(?:and|or|not)$/.test(head)
parens.push(isFunction)
if (isFunction) inFunction++
} else if (match === ')') {
if (parens.pop()) inFunction--
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
} else if (inFunction === 0) {
return ` ${match} `
}
return match
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
})

ruleNode.nodes = [atRule('@supports', query, ruleNode.nodes)]
return
Expand Down