diff --git a/src/docs/font-family.mdx b/src/docs/font-family.mdx index 9af802b5..e0501805 100644 --- a/src/docs/font-family.mdx +++ b/src/docs/font-family.mdx @@ -116,4 +116,32 @@ If you're loading a font from a service like [Google Fonts](https://fonts.google Browsers require that `@import` statements come before any other rules, so URL imports need to be above imports like `@import "tailwindcss"` which are inlined in the compiled CSS. +### The default font family + +The above setup still requires you to apply the font-family using a utility class. + +To set a font family as the core default without needing to specify it on every element by using a utility class, set the `default-font-family` variable to the font-family of your choice: + +```css +@import url("https://fonts.googleapis.com/css2?family=Roboto&display=swap"); +@import "tailwindcss"; + +@theme { + --font-roboto: "Roboto", sans-serif; + --default-font-family: var(--font-roboto); /* [!code highlight] */ +} +``` + +Initially, [`default-font-family` is set to `font-sans`](https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/theme.css#L494) in Tailwind CSS, so it may be a good thing to include this value as a fallback in case the new default font fails to load: + +```css +@import url("https://fonts.googleapis.com/css2?family=Roboto&display=swap"); +@import "tailwindcss"; + +@theme { + --font-roboto: "Roboto", sans-serif; + --default-font-family: var(--font-roboto, var(--font-sans, initial)); /* [!code highlight] */ +} +``` + diff --git a/src/docs/theme.mdx b/src/docs/theme.mdx index ab46e738..0576fe96 100644 --- a/src/docs/theme.mdx +++ b/src/docs/theme.mdx @@ -407,6 +407,37 @@ When you do this, all of the default utilities that use that namespace _(like `b Learn more about how theme variables map to different utility classes and variants in the [theme variable namespaces](#theme-variable-namespaces) documentation. +### Overriding the default values + +There are several variables that allow to define a global default for a small set of values, bypassing the need to use a utility class for the corresponding properties: + +- `--default-font-family` +- `--default-mono-font-family` +- `--default-transition-duration` +- `--default-transition-timing-function` + +For example, to customize the default `font-family`, simply set the `--default-font-family` variable: + +```css +/* [!code filename:app.css] */ +@import "tailwindcss"; + +@theme { + --font-poppins: Poppins, sans-serif; + /* [!code highlight:2] */ + --default-font-family: var(--font-poppins, initial); +} +``` + +No need for a font-family utility class anymore: + +```html + +