I'm using Tailwind CSS v4 with a custom theme that defines --muted using CSS variables. However, the utility class bg-muted does not seem to apply any background color when used in my components.
What I Have Tried:
tailwind.config.ts :
import type { Config } from "tailwindcss";
const config: Config = {
darkMode: "class",
content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"],
theme: {
extend: {
colors: {
muted: "hsl(var(--muted))",
"muted-foreground": "hsl(var(--muted-foreground))",
// other custom colors...
},
},
},
plugins: [],
};
export default config;
Global CSS (e.g. index.css or globals.css):
@import "tailwindcss";
@layer base {
:root {
--muted: 0 0% 96.1%;
--muted-foreground: 0 0% 45.1%;
}
.dark {
--muted: 0 0% 14.9%;
--muted-foreground: 0 0% 63.9%;
}
}
JSX Usage:
<div className="bg-muted p-4 text-black">Test</div>
Observed Behavior:
The class
bg-mutedshows up in the HTML.But it does not apply any visible background color.
No errors are thrown.
Things I’ve Checked:
Tailwind classes are being applied.
The custom property
--mutedis defined under:root.The file using
bg-mutedis insidesrc/and covered bycontent.Other Tailwind classes (e.g.
bg-red-500) work fine.Tried switching to
muted: { DEFAULT: "hsl(var(--muted))" }— no change.
Question:
Why is bg-muted not applying any color in this setup? Is there something I'm missing with CSS variables + Tailwind v4?