Skip to content

Commit a51b214

Browse files
authored
Use more modern --alpha(color / 50%) syntax (#15665)
This PR changes the syntax for the `--alpha(…)` function to look like more modern CSS. The arguments to apply an alpha to a color is using the `/` syntax instead of the comma syntax. ```diff - --alpha(color, 50%) + --alpha(color / 50%) ``` This syntax is now similar to modern `rgb(0 0 0 / 50%)` syntax in CSS.
1 parent f93c42f commit a51b214

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818
- Write to `stdout` when `--output -` flag is used for `@tailwindcss/cli` ([#15656](https://github.com/tailwindlabs/tailwindcss/pull/15656))
1919
- _Upgrade (experimental)_: Pretty print `--spacing(…)` to prevent ambiguity ([#15596](https://github.com/tailwindlabs/tailwindcss/pull/15596))
2020

21+
### Changed
22+
23+
- Use more modern `--alpha(color / 50%)` syntax instead of `--alpha(color, 50%)` ([#15665](https://github.com/tailwindlabs/tailwindcss/pull/15665))
24+
2125
## [4.0.0-beta.9] - 2025-01-09
2226

2327
### Added

packages/tailwindcss/src/css-functions.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('--alpha(…)', () => {
1212
expect(
1313
await compileCss(css`
1414
.foo {
15-
margin: --alpha(red, 50%);
15+
margin: --alpha(red / 50%);
1616
}
1717
`),
1818
).toMatchInlineSnapshot(`
@@ -30,7 +30,7 @@ describe('--alpha(…)', () => {
3030
}
3131
`),
3232
).rejects.toThrowErrorMatchingInlineSnapshot(
33-
`[Error: The --alpha(…) function requires two arguments, e.g.: \`--alpha(var(--my-color), 50%)\`]`,
33+
`[Error: The --alpha(…) function requires a color and an alpha value, e.g.: \`--alpha(var(--my-color) / 50%)\`]`,
3434
)
3535
})
3636

@@ -42,19 +42,19 @@ describe('--alpha(…)', () => {
4242
}
4343
`),
4444
).rejects.toThrowErrorMatchingInlineSnapshot(
45-
`[Error: The --alpha(…) function requires two arguments, e.g.: \`--alpha(red, 50%)\`]`,
45+
`[Error: The --alpha(…) function requires a color and an alpha value, e.g.: \`--alpha(red / 50%)\`]`,
4646
)
4747
})
4848

4949
test('--alpha(…) errors multiple arguments are used', async () => {
5050
expect(() =>
5151
compileCss(css`
5252
.foo {
53-
margin: --alpha(red, 50%, blue);
53+
margin: --alpha(red / 50%, blue);
5454
}
5555
`),
5656
).rejects.toThrowErrorMatchingInlineSnapshot(
57-
`[Error: The --alpha(…) function only accepts two arguments, e.g.: \`--alpha(red, 50%)\`]`,
57+
`[Error: The --alpha(…) function only accepts one argument, e.g.: \`--alpha(red / 50%)\`]`,
5858
)
5959
})
6060
})

packages/tailwindcss/src/css-functions.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,22 @@ const functions: Record<string, (designSystem: DesignSystem, ...args: string[])
1212
theme: legacyTheme,
1313
}
1414

15-
function alpha(_designSystem: DesignSystem, value: string, alpha: string, ...rest: string[]) {
16-
if (!value || !alpha) {
15+
function alpha(_designSystem: DesignSystem, value: string, ...rest: string[]) {
16+
let [color, alpha] = segment(value, '/').map((v) => v.trim())
17+
18+
if (!color || !alpha) {
1719
throw new Error(
18-
`The --alpha(…) function requires two arguments, e.g.: \`--alpha(${value || 'var(--my-color)'}, ${alpha || '50%'})\``,
20+
`The --alpha(…) function requires a color and an alpha value, e.g.: \`--alpha(${color || 'var(--my-color)'} / ${alpha || '50%'})\``,
1921
)
2022
}
2123

2224
if (rest.length > 0) {
2325
throw new Error(
24-
`The --alpha(…) function only accepts two arguments, e.g.: \`--alpha(${value || 'var(--my-color)'}, ${alpha || '50%'})\``,
26+
`The --alpha(…) function only accepts one argument, e.g.: \`--alpha(${color || 'var(--my-color)'} / ${alpha || '50%'})\``,
2527
)
2628
}
2729

28-
return withAlpha(value, alpha)
30+
return withAlpha(color, alpha)
2931
}
3032

3133
function spacing(designSystem: DesignSystem, value: string, ...rest: string[]) {

0 commit comments

Comments
 (0)