-
I have a newly created project with SvelteKit and Vite, and have upgraded to the NEWEST Tailwind version (v4 alpha). But I'm wondering how you would add a custom font (let's say font.woff2). I have tried setting it with the |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments 21 replies
-
Can you share an example project? What you've described sounds right to me, you just do it the same way you do with regular CSS. |
Beta Was this translation helpful? Give feedback.
-
@gu5e Make sure you're adding something like the following to generate/update the classes and custom properties. @theme {
--font-family-sans: "font", sans-serif;
} |
Beta Was this translation helpful? Give feedback.
-
Hello, it doesn't work when I upgrade to the following version |
Beta Was this translation helpful? Give feedback.
-
There I'm doing this way to customizing fonts, using google fonts and override it tailwind's default fonts: //override default fonts // custom fonts( to be safe I imported it from Google fonts) If need how I did this, here is a video |
Beta Was this translation helpful? Give feedback.
-
if its not broke dont fix it what a fking shambles |
Beta Was this translation helpful? Give feedback.
-
really sorry to bother, i've tried all i can think about and followed the instruction you gave, still does not work. please help. |
Beta Was this translation helpful? Give feedback.
-
This is how you'd change default @theme {
--default-font-family: 'Inter', var(--font-sans);
} Enjoy! |
Beta Was this translation helpful? Give feedback.
-
For anyone finding this thread, I've collated it into a short blog post: custom fonts in Tailwind v4 & v3. At a guess though: you're probably missing a line like this (goes after @theme {
--font-[name]: "your font name", sans-serif;
} ie:
|
Beta Was this translation helpful? Give feedback.
-
If anyone else stumbles onto the issue of font-weights not taking effect check whether you have the Not working: @layer base {
@font-face {
font-family: "Bw Gradual";
src: url("./assets/fonts/Bw-Gradual-Regular/BwGradual-Regular.woff2")
format("woff2"),
url("./assets/fonts/Bw-Gradual-Regular/BwGradual-Regular.woff")
format("woff");
font-weight: 400 600;
font-style: normal;
}
@font-face {
font-family: "Bw Gradual";
src: url("./assets/fonts/Bw-Gradual-Regular-Italic/BwGradual-RegularItalic.woff2")
format("woff2"),
url("./assets/fonts/Bw-Gradual-Regular-Italic/BwGradual-RegularItalic.woff")
format("woff");
font-weight: 400 600;
font-style: italic;
}
@font-face {
font-family: "Bw Gradual";
src: url("./assets/fonts/Bw-Gradual-Medium/BwGradual-Medium.woff2")
format("woff2"),
url("./assets/fonts/Bw-Gradual-Medium/BwGradual-Medium.woff")
format("woff");
font-weight: 700 800;
font-style: normal;
}
@font-face {
font-family: "Bw Gradual";
src: url("./assets/fonts/Bw-Gradual-Medium-Italic/BwGradual-MediumItalic.woff2")
format("woff2"),
url("./assets/fonts/Bw-Gradual-Medium-Italic/BwGradual-MediumItalic.woff")
format("woff");
font-weight: 700 800;
font-style: italic;
}
@font-face {
font-family: "Bw Gradual";
src: url("./assets/fonts/Bw-Gradual-Black/BwGradual-Black.woff2")
format("woff2"),
url("./assets/fonts/Bw-Gradual-Black/BwGradual-Black.woff") format("woff");
font-weight: 900;
font-style: normal;
}
@font-face {
font-family: "Bw Gradual";
src: url("./assets/fonts/Bw-Gradual-Light/BwGradual-Light.woff2")
format("woff2"),
url("./assets/fonts/Bw-Gradual-Light/BwGradual-Light.woff") format("woff");
font-weight: 100 300;
font-style: normal;
}
} Working: @font-face {
font-family: "Bw Gradual";
src: url("./assets/fonts/Bw-Gradual-Regular/BwGradual-Regular.woff2")
format("woff2"),
url("./assets/fonts/Bw-Gradual-Regular/BwGradual-Regular.woff")
format("woff");
font-weight: 400;
font-style: normal;
}
@font-face {
font-family: "Bw Gradual";
src: url("./assets/fonts/Bw-Gradual-Regular-Italic/BwGradual-RegularItalic.woff2")
format("woff2"),
url("./assets/fonts/Bw-Gradual-Regular-Italic/BwGradual-RegularItalic.woff")
format("woff");
font-weight: 400;
font-style: italic;
}
@font-face {
font-family: "Bw Gradual";
src: url("./assets/fonts/Bw-Gradual-Medium/BwGradual-Medium.woff2")
format("woff2"),
url("./assets/fonts/Bw-Gradual-Medium/BwGradual-Medium.woff") format("woff");
font-weight: 700;
font-style: normal;
}
@font-face {
font-family: "Bw Gradual";
src: url("./assets/fonts/Bw-Gradual-Medium-Italic/BwGradual-MediumItalic.woff2")
format("woff2"),
url("./assets/fonts/Bw-Gradual-Medium-Italic/BwGradual-MediumItalic.woff")
format("woff");
font-weight: 700;
font-style: italic;
}
@font-face {
font-family: "Bw Gradual";
src: url("./assets/fonts/Bw-Gradual-Black/BwGradual-Black.woff2")
format("woff2"),
url("./assets/fonts/Bw-Gradual-Black/BwGradual-Black.woff") format("woff");
font-weight: 900;
font-style: normal;
}
@font-face {
font-family: "Bw Gradual";
src: url("./assets/fonts/Bw-Gradual-Light/BwGradual-Light.woff2")
format("woff2"),
url("./assets/fonts/Bw-Gradual-Light/BwGradual-Light.woff") format("woff");
font-weight: 100;
font-style: normal;
} |
Beta Was this translation helpful? Give feedback.
I think your answer should be updated to