add zoom-* utilities (#20020)

This PR adds new `zoom-*` utilities.

The `zoom-*` utilities accept bare values that are transformed into `%`
based values, and arbitrary values:

| Class | CSS |
| -- | -- |
| `zoom-50` | `zoom: 50%;` |
| `zoom-[1.1]` | `zoom: 1.1;` |
| `zoom-(--value)` | `zoom: var(--value);` |


This also adds the `zoom` property after the `transform` related
properties. Initially I added it right after `scale`, because logically
they are close together. But then `zoom-*` would sit between `scale` and
other tranfsorm related properties which is a bit weird. Instead, I
moved it after `transform`.

## Test plan

1. Added new zoom based tests
2. All other tests still pass
This commit is contained in:
Robin Malfait 2026-05-08 21:15:59 +02:00 • committed by GitHub
parent 2e1ccf7f11
commit 90a2373620
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 56 additions and 0 deletions

View file

@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Allow using `@variant` with stacked variants (e.g. `@variant hover:focus { … }`) ([#19996](https://github.com/tailwindlabs/tailwindcss/pull/19996))
- Allow using `@variant` with compound variants (e.g. `@variant hover, focus { … }`) ([#19996](https://github.com/tailwindlabs/tailwindcss/pull/19996))
- Support `--default(…)` in `--value(…)` and `--modifier(…)` for functional `@utility` definitions ([#19989](https://github.com/tailwindlabs/tailwindcss/pull/19989))
- Add `zoom-*` utilities ([#20020](https://github.com/tailwindlabs/tailwindcss/pull/20020))
- Add `scrollbar-gutter-*` utilities ([#20018](https://github.com/tailwindlabs/tailwindcss/pull/20018))
### Fixed

View file

@ -12247,6 +12247,16 @@ exports[`getClassList 1`] = `
"z-40",
"z-50",
"z-auto",
"zoom-50",
"zoom-75",
"zoom-90",
"zoom-95",
"zoom-100",
"zoom-105",
"zoom-110",
"zoom-125",
"zoom-150",
"zoom-200",
]
`;

View file

@ -92,6 +92,8 @@ export default [
'--tw-skew-y',
'transform',
'zoom',
'animation',
'cursor',

View file

@ -6899,6 +6899,34 @@ test('transform', async () => {
).toEqual('')
})
test('zoom', async () => {
expect(
await compileCss(
css`
@tailwind utilities;
`,
['zoom-50', 'zoom-100', 'zoom-[var(--zoom)]'],
),
).toMatchInlineSnapshot(`
"
.zoom-50 {
zoom: 50%;
}
.zoom-100 {
zoom: 100%;
}
.zoom-\\[var\\(--zoom\\)\\] {
zoom: var(--zoom);
}
"
`)
expect(
await run(['zoom', '-zoom-50', 'zoom--50', 'zoom-1.5', 'zoom-unknown', 'zoom-50/foo']),
).toEqual('')
})
test('perspective', async () => {
expect(
await compileCss(

View file

@ -1706,6 +1706,21 @@ export function createUtilities(theme: Theme) {
staticUtility('transform-none', [['transform', 'none']])
}
/**
* @css `zoom`
*/
functionalUtility('zoom', {
handleBareValue: ({ value }) => {
if (!isPositiveInteger(value)) return null
return `${value}%`
},
handle: (value) => [decl('zoom', value)],
})
suggest('zoom', () => [
{ values: ['50', '75', '90', '95', '100', '105', '110', '125', '150', '200'] },
])
/**
* @css `transform-style`
*/