返回 slidev
config-fonts.md
根目录 / docs / custom / config-fonts.md
1 # Configure Fonts
2
3 While you can use HTML and CSS to customize the fonts and style for your slides as you want, Slidev also provides a convenient way to use them effortlessly.
4
5 In your frontmatter, configure as the following:
6
7 ```yaml
8 ---
9 fonts:
10 # basically the text
11 sans: Robot
12 # use with `font-serif` css class from UnoCSS
13 serif: Robot Slab
14 # for code blocks, inline code, etc.
15 mono: Fira Code
16 ---
17 ```
18
19 And that's all.
20
21 Fonts will be **imported automatically from a provider via CDN, by default it is [Google Fonts](https://fonts.google.com/)**. That means you can use any fonts available on Google Fonts directly.
22
23 ## Body Font
24
25 - Options: `sans` | `serif` | `mono`
26 - Default: `sans`
27
28 By default, the base text of your slides uses the `sans` font. Set `fonts.body` to choose which font role the base text uses instead:
29
30 ```yaml
31 ---
32 fonts:
33 # use the serif font for the base text
34 body: serif
35 serif: Robot Slab
36 ---
37 ```
38
39 This only changes the base text. The `font-sans`, `font-serif` and `font-mono` utility classes keep using their own fonts.
40
41 ## Local Fonts
42
43 By default, Slidev assumes all the fonts specified via `fonts` configurations come from Google Fonts. If you want to use local fonts, specify the `fonts.local` to opt-out the auto-importing.
44
45 ```yaml
46 ---
47 fonts:
48 # like font-family in css, you can use `,` to separate multiple fonts for fallback
49 sans: 'Helvetica Neue,Robot'
50 # mark 'Helvetica Neue' as local font
51 local: Helvetica Neue
52 ---
53 ```
54
55 ## Weights & Italic
56
57 By default, Slidev imports three weights `200`,`400`,`600` for each font. You can configure them by:
58
59 ```yaml
60 ---
61 fonts:
62 sans: Robot
63 # default
64 weights: '200,400,600'
65 # import italic fonts, default `false`
66 italic: false
67 ---
68 ```
69
70 This configuration applies to all web fonts. For more fine-grained controls of each font's weights, you will need to manually import them with [HTML](/custom/directory-structure.html#index-html) and CSS.
71
72 ## Fallback Fonts
73
74 For most of the scenarios, you only need to specify the "special font" and Slidev will append the fallback fonts for you, for example:
75
76 ```yaml
77 ---
78 fonts:
79 sans: Robot
80 serif: Robot Slab
81 mono: Fira Code
82 ---
83 ```
84
85 will result in
86
87 <!-- eslint-skip -->
88
89 ```css
90 .font-sans {
91 font-family: "Robot",ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";
92 }
93 .font-serif {
94 font-family: "Robot Slab",ui-serif,Georgia,Cambria,"Times New Roman",Times,serif;
95 }
96 .font-mono {
97 font-family: "Fira Code",ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;
98 }
99 ```
100
101 If you want to disable the fallback fonts, configure as the following:
102
103 ```yaml
104 ---
105 fonts:
106 mono: 'Fira Code, monospace'
107 fallbacks: false
108 ---
109 ```
110
111 ## Providers
112
113 - Options: `google` | `coollabs` | `none`
114 - Default: `google`
115
116 Currently, only [Google Fonts](https://fonts.google.com/) and [coolLabs](https://fonts.coollabs.io/) supported, we are planning to add more providers in the future. Specify to `none` will disable the auto-importing feature entirely and treat all the fonts locally.
117
118 ```yaml
119 ---
120 fonts:
121 provider: none
122 ---
123 ```
124
124 lines MARKDOWN