Skip to content

Reject bare color opacity modifiers above 100 - #20609

Open
otarampinelli wants to merge 6 commits into
tailwindlabs:mainfrom
otarampinelli:fix/color-opacity-modifier-above-100
Open

otarampinelli wants to merge 6 commits into
tailwindlabs:mainfrom
otarampinelli:fix/color-opacity-modifier-above-100

Conversation

@otarampinelli

Copy link
Copy Markdown
Contributor

Summary

Bare opacity modifiers only check if the value isn't negative or it's a multiple of 0.25, with none validation for values above 100for opacity, so bg-red-500/150 generates a bad value like color-mix(in oklab, var(--color-red-500) 150%, transparent), browser rejects color-mix() percentages above 100%, so the declaration is silently dropped

The solution is rejecting bare values above 100 in asColor() which also covers the shadow, inset-shadow, text-shadow and drop-shadow, the shared isValidOpacityValue is unchanged because opacity-150 or backdorp-opacity-150 are valid, browser clamps them

Tailwind play with some evidences

Captura de Tela 2026-10-22 às 15 12 25

Test plan

  • New test invalid bare color opacity modifiers: checks that /101, /150, /500, /100.25 and /2.3 on color and shadow utilities generate no css, it fails when running against main

  • added opacity-150 to the opacity test, checks that plain opacity still works above 100, opacity: 1.5, which the browser clamps

pnpm exec vitest run --project tailwindcss packages/tailwindcss/src/utilities.test.ts

@otarampinelli
otarampinelli requested a review from a team as a code owner October 22, 2026 18:18
@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

asColor and the drop-shadow, text-shadow, shadow, and inset-shadow utilities now reject bare opacity modifiers above 100. The compatibility plugin API also limits numeric color modifiers to 100. Tests cover these limits across the affected utilities. The opacity utility test confirms that opacity-150 generates opacity: 1.5.

Merge Risk: Minimal · up to 3680e

Bare color opacity modifiers above 100 will no longer generate CSS, while standalone opacity remains supported. No merge-blocking risk is established.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title describes rejecting bare color opacity modifiers above 100. It captures the main change, though it does not mention the related shadow utilities.
Description check Passed The description explains the invalid opacity values, the affected utilities, and the tests for the change.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c8ae2440-7362-4996-bc4d-97294d311468
Commits

Reviewing files that changed from the base of the PR and between 5777b33 and 3680ee0.

Files selected for processing: 5

  • .changelog/reject-bare-opacity-modifiers-above-100.md
  • packages/tailwindcss/src/compat/plugin-api.test.ts
  • packages/tailwindcss/src/compat/plugin-api.ts
  • packages/tailwindcss/src/utilities.test.ts
  • packages/tailwindcss/src/utilities.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@greptile-apps

greptile-apps Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] This PR appears safe to merge.

Reviews (5) · Last reviewed commit: "Add changelog fragment for #20609" · Reviewed by Greptile

@otarampinelli

otarampinelli commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor Author

The failing test it's caused by bun 1.4.4 release from Oct 22, the upgrades half-upgraded v3 project to v4 (bun) test installs "bun": "^1.0.0", so it now gets 1.4.4, that version copies the overrides from pnpm-workspace.yaml into package.json, the pnpm-style keys (@tailwindcss/node>tailwindcss) then break the next npx call

`npm error Override without name: @tailwindcss/node>tailwindcss`

I checked locally with the same pnpm-workspace.yaml, bun 1.4.3 leaves package.json untouched and 1.4.4 adds the overrides field

@otarampinelli

otarampinelli commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor Author

I have a PR fixing that bun version CI failure for now, but is should pass for newer version later, this is pinning the version of the test to use 1.4.3, this will work to make CI pass, but later we need to investigate this better because seems a bun regression caused by the newer version

#20616

@otarampinelli

Copy link
Copy Markdown
Contributor Author

CI test failures solved on #20650

otarampinelli and others added 5 commits November 3, 2026 15:54
…ng utility tests

Each utility test already has a list of invalid candidates. The cases
for `bg`, `text`, `border-*`, `shadow`, `inset-shadow`, `text-shadow`
and `drop-shadow` now live there, with `--color-red-500` in the theme so
that they are dropped because of the modifier, not because of an unknown
color.
The size form of `shadow-*`, `inset-shadow-*`, `text-shadow-*` and
`drop-shadow-*` computed its own alpha, outside of `asColor(…)`. So
`shadow-lg/150` still generated `--tw-shadow-alpha: 150%`. Together with
a shadow color, this resolves to `color-mix(…, 150%, …)`, which makes the
whole `box-shadow` invalid.

The rule now lives in one `bareAlpha(…)` helper, which `asColor(…)` and
the 4 shadow utilities use.
`matchUtilities(…, { type: 'color' })` doesn't use `asColor(…)`, and
turned any number into a percentage. So `plugin-red-500/150` still
generated `color-mix(…, 150%, …)`.
`main` now collects changelog entries as fragments in `.changelog/`, so the entry goes there instead of in `CHANGELOG.md`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants