You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<!--
Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change that you're making:
-->
Update the next fonts API reference to match the latest changes from
[beta.nextjs.org](https://beta.nextjs.org/docs/api-reference/components/font)
## Bug
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`
## Feature
- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [x] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see `contributing.md`
## Documentation / Examples
- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
Copy file name to clipboardexpand all lines: docs/api-reference/next/font.md
+92-77
Original file line number
Diff line number
Diff line change
@@ -13,157 +13,172 @@ description: Optimizing loading web fonts with the built-in `@next/font` loaders
13
13
14
14
</details>
15
15
16
-
This API reference will help you understand how to use [`@next/font/google`](#nextfontgoogle) and [`@next/font/local`](#nextfontlocal). For features and usage, please see the [Optimizing Fonts](/docs/basic-features/font-optimization.md) page.
17
-
18
-
## @next/font/google
16
+
This API reference will help you understand how to use `@next/font/google` and `@next/font/local`. For features and usage, please see the [Optimizing Fonts](/docs/basic-features/font-optimization.md) page.
19
17
20
18
### Font function arguments
21
19
22
-
For usage, review [Google Fonts](/docs/basic-features/font-optimization.md#google-fonts).
20
+
For usage, review [Google Fonts](/docs/basic-features/font-optimization.md#google-fonts) and [Local Fonts](/docs/basic-features/font-optimization#local-fonts).
21
+
22
+
| Key |`font/google`|`font/local`| Data type | Required |
The path of the font file as a string or an array of objects (with type `Array<{path: string, weight?: string, style?: string}>`) relative to the directory where the font loader function is called.
37
39
38
-
The font [`weight`](https://fonts.google.com/knowledge/glossary/weight) represented as a string with possible values of the weights available for the specific font. For example, for the font [`Inter`](https://fonts.google.com/specimen/Inter?query=inter), the possible values are `'100'`, `'200'`, `'300'`, `'400'`, `'500'`, `'600'`, `'700'`, `'800'`, `'900'` or `'variable'` (`'variable'` is the default in this case).
40
+
Used in `@next/font/local`
39
41
40
-
- Required if the font being used is **not**[variable](https://fonts.google.com/variablefonts)
41
-
42
-
### `style`
42
+
- Required
43
43
44
-
The font [`style`](https://developer.mozilla.org/en-US/docs/Web/CSS/font-style) with possible string [values](https://developer.mozilla.org/en-US/docs/Web/CSS/font-style#values) of `'normal'` or `'italic'` with default value of `'normal'`.
44
+
Examples:
45
45
46
-
- Optional
46
+
-`src:'./fonts/my-font.woff2'` where `my-font.woff2` is placed in a directory named `fonts` inside the `app` directory
- if the font loader function is called in `app/page.tsx` using `src:'../styles/fonts/my-font.ttf'`, then `my-font.ttf` is placed in `styles/fonts` at the root of the project
47
49
48
-
### `subsets`
50
+
### `weight`
49
51
50
-
The font [`subsets`](https://fonts.google.com/knowledge/glossary/subsetting) defined by an Array of string values with the names of each subset you would like to be [preloaded](/docs/basic-features/font-optimization.md#specifying-a-subset). Fonts specified via `subsets` will have a link preload tag injected into the head when the [`preload`](#preload) option is true, which is the default.
52
+
The font [`weight`](https://fonts.google.com/knowledge/glossary/weight)with the following possibilities:
51
53
52
-
- Optional
54
+
- A string with possible values of the weights available for the specific font or a range of values if it's a [variable](https://fonts.google.com/variablefonts) font
55
+
- An array of weight values if the font is not a [variable google font](https://fonts.google.com/variablefonts). It applies to `@next/font/google` only.
53
56
54
-
### `axes`
57
+
Used in `@next/font/google` and `@next/font/local`
55
58
56
-
Some variable fonts have extra `axes` that can be included. By default, only the font weight is included to keep the file size down. The possible values of `axes` depend on the specific font. For example, the `Inter` variable font has `slnt` as additional `axes` as shown [here](https://fonts.google.com/variablefonts?vfquery=inter#font-families). You can find the possible `axes` values for your font by using the filter on the [Google variable fonts page](https://fonts.google.com/variablefonts#font-families) and looking for axes other than `wght`.
59
+
- Required if the font being used is **not**[variable](https://fonts.google.com/variablefonts)
57
60
58
-
- Optional
61
+
Examples:
59
62
60
-
### `display`
63
+
-`weight: '400'`: A string for a single weight value - for the font [`Inter`](https://fonts.google.com/specimen/Inter?query=inter), the possible values are `'100'`, `'200'`, `'300'`, `'400'`, `'500'`, `'600'`, `'700'`, `'800'`, `'900'` or `'variable'` where `'variable'` is the default)
64
+
-`weight: '100 900'`: A string for the range between `100` and `900` for a variable font
65
+
-`weight: ['100','400','900']`: An array of 3 possible values for a non variable font
61
66
62
-
The font [`display`](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-display) with possible string [values](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-display#values) of `'auto'`, `'block'`, `'swap'`, `'fallback'` or `'optional'` with default value of `'optional'`.
67
+
### `style`
63
68
64
-
- Optional
69
+
The font [`style`](https://developer.mozilla.org/en-US/docs/Web/CSS/font-style) with the following possibilities:
65
70
66
-
### `preload`
71
+
- A string [value](https://developer.mozilla.org/en-US/docs/Web/CSS/font-style#values) with default value of `'normal'`
72
+
- An array of style values if the font is not a [variable google font](https://fonts.google.com/variablefonts). It applies to `@next/font/google` only.
67
73
68
-
A boolean value that specifies whether the font should be [preloaded](/docs/basic-features/font-optimization.md#preloading) or not. The default is `true`.
74
+
Used in `@next/font/google` and `@next/font/local`
69
75
70
76
- Optional
71
77
72
-
### `fallback`
78
+
Examples:
73
79
74
-
The fallback font to use if the font cannot be loaded. An array of strings of fallback fonts such as `['system-ui', 'arial']` with no default.
80
+
-`style: 'italic'`: A string - it can be `normal` or `italic` for `@next/font/google`
81
+
-`style: 'oblique'`: A string - it can take any value for `@next/font/local` but is expected to come from [standard font styles](https://developer.mozilla.org/en-US/docs/Web/CSS/font-style)
82
+
-`style: ['italic','normal']`: An array of 2 values for `@next/font/google` - the values are from `normal` and `italic`
75
83
76
-
- Optional
84
+
### `subsets`
77
85
78
-
### `adjustFontFallback`
86
+
The font [`subsets`](https://fonts.google.com/knowledge/glossary/subsetting) defined by an array of string values with the names of each subset you would like to be [preloaded](/docs/optimizing/fonts.md#specifying-a-subset). Fonts specified via `subsets` will have a link preload tag injected into the head when the [`preload`](/docs/api-reference/components/font.md#preload) option is true, which is the default.
79
87
80
-
A boolean value that sets whether an automatic fallback font should be used to reduce [Cumulative Layout Shift](https://web.dev/cls/). The default is `true`.
88
+
Used in `@next/font/google`
81
89
82
90
- Optional
83
91
84
-
### `variable`
92
+
Examples:
85
93
86
-
A string value to define the CSS variable name to be used if the style is applied with the [CSS variable method](#css-variables).
94
+
-`subsets: ['latin']`: An array with the subset `latin`
87
95
88
-
- Optional
96
+
### `axes`
89
97
90
-
## @next/font/local
98
+
Some variable fonts have extra `axes` that can be included. By default, only the font weight is included to keep the file size down. The possible values of `axes` depend on the specific font.
91
99
92
-
### Font function arguments
100
+
Used in `@next/font/google`
93
101
94
-
For usage, review [Local Fonts](/docs/basic-features/font-optimization.md#local-fonts).
-`axes: ['slnt']`: An array with value `slnt` for the `Inter` variable font which has `slnt` as additional `axes` as shown [here](https://fonts.google.com/variablefonts?vfquery=inter#font-families). You can find the possible `axes` values for your font by using the filter on the [Google variable fonts page](https://fonts.google.com/variablefonts#font-families) and looking for axes other than `wght`
109
107
110
-
The path of the font file as a string relative to the directory where the font loader function is called or to the `pages` directory.
108
+
### `display`
111
109
112
-
- Required
110
+
The font [`display`](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-display) with possible string [values](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-display#values) of `'auto'`, `'block'`, `'swap'`, `'fallback'` or `'optional'` with default value of `'optional'`.
113
111
114
-
Examples are:
112
+
Used in `@next/font/google` and `@next/font/local`
115
113
116
-
-`'./fonts/my-font.woff2'` where `my-font.woff2` is placed in a directory named `fonts` inside the `pages` directory
117
-
- if the font loader function is called in `pages/index.js` using `'../styles/fonts/my-font.ttf'`, then `my-font.ttf` is placed in `styles/fonts` at the root of the project
114
+
- Optional
118
115
119
-
### `weight`
116
+
Examples:
120
117
121
-
The font [`weight`](https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight) either as a specific weight string value such as `'400'` or a range of values if it's a variable font such as `'100 900'`.
118
+
-`display: 'swap'`: A string assigned to the `swap` value
122
119
123
-
- Optional
120
+
### `preload`
124
121
125
-
### `style`
122
+
A boolean value that specifies whether the font should be [preloaded](/docs/optimizing/fonts#preloading) or not. The default is `true`.
126
123
127
-
The font [`style`](https://developer.mozilla.org/en-US/docs/Web/CSS/font-style) with possible string [values](https://developer.mozilla.org/en-US/docs/Web/CSS/font-style#values) of `'normal'`, `'italic'` or `'oblique'` with default value of `'normal'`.
124
+
Used in `@next/font/google` and `@next/font/local`
128
125
129
126
- Optional
130
127
131
-
### `display`
128
+
Examples:
132
129
133
-
The font [`display`](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-display) with possible string [values](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-display#values) of `'auto'`, `'block'`, `'swap'`, `'fallback'` or `'optional'` with default value of `'optional'`.
134
-
135
-
- Optional
130
+
-`preload: false`
136
131
137
-
### `preload`
132
+
### `fallback`
138
133
139
-
A boolean value that specifies whether the font should be [preloaded](/docs/basic-features/font-optimization.md#preloading) or not. The default is `true`.
134
+
The fallback font to use if the font cannot be loaded. An array of strings of fallback fonts with no default.
140
135
141
136
- Optional
142
137
143
-
### `fallback`
138
+
Used in `@next/font/google` and `@next/font/local`
144
139
145
-
The fallback font to use if the font cannot be loaded. An array of strings of fallback fonts such as `['system-ui', 'arial']` with no default.
140
+
Examples:
146
141
147
-
-Optional
142
+
-`fallback: ['system-ui', 'arial']`: An array setting the fallback fonts to `system-ui` or `arial`
148
143
149
144
### `adjustFontFallback`
150
145
151
-
A string or boolean `false` value that sets whether an automatic fallback font should be used to reduce [Cumulative Layout Shift](https://web.dev/cls/). The possible values are `'Arial'`, `'Times New Roman'` or `false`. The default is `'Arial'`.
146
+
- For `@next/font/google`: A boolean value that sets whether an automatic fallback font should be used to reduce [Cumulative Layout Shift](https://web.dev/cls/). The default is `true`.
147
+
- For `@next/font/local`: A string or boolean `false` value that sets whether an automatic fallback font should be used to reduce [Cumulative Layout Shift](https://web.dev/cls/). The possible values are `'Arial'`, `'Times New Roman'` or `false`. The default is `'Arial'`.
148
+
149
+
Used in `@next/font/google` and `@next/font/local`
152
150
153
151
- Optional
154
152
153
+
Examples:
154
+
155
+
-`adjustFontFallback: false`: for ``@next/font/google`
156
+
-`adjustFontFallback: 'Times New Roman'`: for `@next/font/local`
157
+
155
158
### `variable`
156
159
157
160
A string value to define the CSS variable name to be used if the style is applied with the [CSS variable method](#css-variables).
158
161
162
+
Used in `@next/font/google` and `@next/font/local`
163
+
159
164
- Optional
160
165
166
+
Examples:
167
+
168
+
-`variable: '--my-font'`: The CSS variable `--my-font` is declared
169
+
161
170
### `declarations`
162
171
163
-
An array of font face [descriptor](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face#descriptors) key-value pairs that define the generated `@font-face` further such as `{ prop: 'ascent-override', value: '90%' }`.
172
+
An array of font face [descriptor](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face#descriptors) key-value pairs that define the generated `@font-face` further.
View the [Font API Reference](/docs/api-reference/next/font.md#nextfontlocal) for more information.
160
160
161
+
## With Tailwind CSS
162
+
163
+
`@next/font` can be used with Tailwind CSS through a [CSS variable](/docs/api-reference/next/font#css-variables).
164
+
165
+
In the example below, we use the font `Inter` from `@next/font/google` (You can use any font from Google or Local Fonts). Load your font with the `variable` option to define your CSS variable name and assign it to `inter`. Then, use `inter.variable` to add the CSS variable to your HTML document.
You can now use the `font-sans` utility class to apply the font to your elements.
205
+
161
206
## Preloading
162
207
163
208
When a font function is called on a page of your site, it is not globally available and preloaded on all routes. Rather, the font is only preloaded on the related route/s based on the type of file where it is used:
0 commit comments