Skip to content

Skip color-mix(…) when opacity is 100% #17815

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Upgrade: Bump all Tailwind CSS related dependencies during upgrade ([#17763](https://github.com/tailwindlabs/tailwindcss/pull/17763))
- PostCSS: Ensure that errors in stylesheet dependencies are recoverable ([#17754](https://github.com/tailwindlabs/tailwindcss/pull/17754))
- Upgrade: Correctly print variants starting with `@` ([#17814](https://github.com/tailwindlabs/tailwindcss/pull/17814))
- Skip `color-mix(…)` when opacity is `100%` ([#17815](https://github.com/tailwindlabs/tailwindcss/pull/17815))

## [4.1.4] - 2025-04-14

Expand Down
10 changes: 10 additions & 0 deletions packages/tailwindcss/src/utilities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10695,6 +10695,8 @@ test('bg', async () => {
'bg-red-500/2.75',
'bg-red-500/[0.5]',
'bg-red-500/[50%]',
'bg-red-500/100',
'bg-red-500/[100%]',
'bg-blue-500',
'bg-current',
'bg-current/50',
Expand Down Expand Up @@ -10992,6 +10994,10 @@ test('bg', async () => {
}
}

.bg-red-500\\/100 {
background-color: var(--color-red-500);
}

.bg-red-500\\/\\[0\\.5\\] {
background-color: #ef444480;
}
Expand All @@ -11012,6 +11018,10 @@ test('bg', async () => {
}
}

.bg-red-500\\/\\[100\\%\\] {
background-color: var(--color-red-500);
}

.bg-transparent {
background-color: #0000;
}
Expand Down
5 changes: 5 additions & 0 deletions packages/tailwindcss/src/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ export function withAlpha(value: string, alpha: string): string {
alpha = `${alphaAsNumber * 100}%`
}

// No need for `color-mix` if the alpha is `100%`
if (alpha === '100%') {
return value
}

return `color-mix(in oklab, ${value} ${alpha}, transparent)`
}

Expand Down