(and make it the default sans stack without breaking the zero‑config build?)
I created a new project with the sv create
wizard and chose Tailwind CSS.
The scaffold does not generate a tailwind.config.js
or postcss.config.cjs
.
src/app.css
looks like this (and everything renders correctly in the UI):
@import 'tailwindcss';
@plugin '@tailwindcss/typography';
Goal
Load Montserrat from Google Fonts and make it the default sans‑serif font (font-sans) for the whole site.
What I tried
import type { Config } from 'tailwindcss';
import defaultTheme from 'tailwindcss/defaultTheme';
export default {
content: ['./src/**/*.{svelte,html,js,ts}'],
theme: {
extend: {
fontFamily: {
sans: ['"Montserrat"', ...defaultTheme.fontFamily.sans]
}
}
},
plugins: []
} satisfies Config;
@tailwind base;
@tailwind components;
@tailwind utilities;
module.exports = {
plugins: {
'@tailwindcss/postcss': {},
autoprefixer: {}
}
};
After this, pnpm dev starts without errors, but Tailwind stops scanning my .svelte files—only the preflight styles remain and all utilities disappear.
Undo all your steps back to when it was working well, ala:
@import 'tailwindcss';
@plugin '@tailwindcss/typography';
The steps you followed are for v3 but you seem to be using v4, so we should configure Tailwind's theme variables in the v4 style.
After reverting everthing back, add the following to src/app.css
:
@theme {
--font-sans: 'Montserrat', ui-sans-serif, system-ui, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
}
So that your CSS file should look like:
@import 'tailwindcss';
@plugin '@tailwindcss/typography';
@theme {
--font-sans: 'Montserrat', ui-sans-serif, system-ui, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
}
See the documentation for details on customizing font families in v4.