-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
oklch color definitions don't work with color/opacity syntax — classes missing or incomplete #14499
Comments
Getting the same issue v3.4.14 |
They seem to have removed How can you allow for OKLCH to get the opacity modifier without it? I have this working with it: /* globals.css */
@layer base {
:root {
/* ... */
--color-copperfield-500: 58.08% 0.1679 34.86; /* #d86237 */
/* ... */
}
} And in config // tailwind.config.ts
const config = {
theme: {
extend: {
colors: {
copperfield: {
// ...
500: "oklch(var(--color-copperfield-500) / <alpha-value>)",
// ...
},
},
},
} edit: now also found this comment #9143 (comment) |
I ended up defining the base, no-alpha colors in a separate module that I export: // palette.ts
const palette = {
ocean: {
100: "oklch(91.65% 0.047 237)",
// ...
}
} Then in my Tailwind config I pass them through a closure to add the // tailwind.config.ts
import { palette } from 'palette';
const addAlphaChannelForTailwind = (color: string) => {
const chars = Array.from(color);
// insert the placeholder just before closing ')'
chars.splice( chars.lastIndexOf(')'), 0, '/ <alpha-value>' );
return chars.join('');
}
export default {
theme: {
colors: {
ocean: {
100: addAlphaChannelForTailwind(palette.ocean['100']),
// ...
}
}
}
} (actual code uses a second function to loop through the defined shades and add all of them at once to the Tailwind object, for less repetition). The reason to avoid a custom property in the Tailwind definition is that postcss-preset-env (or the like) cannot create I also don't like using custom properties for the contents of a color function and not the actual color — it makes for bad transitions and animations, and doesn't work with the CSS Properties and Values API. And the hack using The way I've done it, all the classes work, I can refer to the colors from my own CSS in the usual ways (for instance making custom properties there: |
it seams like v3 only parse Line 47 in 6069a81
it would be nice to add support for oklch
|
What version of Tailwind CSS are you using?
v3.4.13
What build tool (or framework if it abstracts the build tool) are you using?
Tested with Bud.js 6.23.3 (using postcss 8.4.24) and Tailwind Playground.
What version of Node.js are you using?
v20.16.0
What browser are you using?
N/A
What operating system are you using?
macOS Sonoma 14.7
Reproduction URL
https://play.tailwindcss.com/dDmsole8X3
Describe your issue
When colors are added to a Tailwind config using the standard
oklch()
function, the resulting color classes do not work with Tailwind's methods of controlling opacity. For a color likeprimary: "oklch(68% 0.15 237.33)"
, these two issues appear:var(--tw-bg-opacity)
andvar(--tw-text-opacity)
— it seems that Tailwind just copies the value directly.bg-primary/50
.The same problems occur if I explicitly declare an opacity in the color definition:
primary: "oklch(68% 0.15 237.33 / 1)"
.Classes ARE generated correctly if I use the
<alpha-value>
placeholder in color definitions:primary: "oklch(68% 0.15 237.33 / <alpha-value>)"
. However, this magic is not explained anywhere in Tailwind's color documentation: https://tailwindcss.com/docs/customizing-colorsThe playground link shows both issues and contrasts the correct behavior of colors defined using
rgb(r g b / a)
notation.The text was updated successfully, but these errors were encountered: