Prepend to Default Theme Variable #19820
Replies: 3 comments
-
|
You could consider adding the raw default value into the definition manually: @theme {
--font-sans: "Space Grotesk", ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
} |
Beta Was this translation helpful? Give feedback.
-
|
I don’t think there’s a built-in way to prepend to the existing The straightforward Tailwind v4 approach is to redefine @import "tailwindcss";
@theme {
--font-sans: "Space Grotesk", ui-sans-serif, system-ui, sans-serif,
"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
} |
Beta Was this translation helpful? Give feedback.
-
|
You're right that you can't self-reference a CSS custom property — that's a spec limitation, not a Tailwind one. The trick in Tailwind v4 is to use @theme inline {
--font-sans: "Space Grotesk", ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
}This effectively prepends your font to the sans stack. The If you want to keep it DRY and avoid duplicating the fallback stack, another approach is to define a separate variable for the fallback: @theme {
--font-sans-fallback: ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
--font-sans: "Space Grotesk", var(--font-sans-fallback);
}This avoids the cyclic dependency because |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey there,
I'm trying to use a custom font. I'd like to use the value of
font-sansas the fallback and I don't want to create a separate utility class (likefont-main). I know I can't doas that creates a cyclic dependency --
Is there any way I can prepend the name of my custom font to
font-sans?Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions