1
0
mirror of https://github.com/squidfunk/mkdocs-material.git synced 2024-11-12 10:00:52 +01:00
mkdocs-material/docs/guides/changing-the-fonts.md

99 lines
2.4 KiB
Markdown
Raw Normal View History

---
template: overrides/main.html
---
# Changing the fonts
2020-07-16 23:55:37 +02:00
Material for MkDocs makes it easy to change the typeface of your project
documentation, as it directly integrates with [Google Fonts][1]. Alternatively,
fonts can be custom-loaded if self-hosting is preferred or another destination
should be used.
[1]: https://fonts.google.com
## Configuration
2020-07-16 23:55:37 +02:00
### Regular font
[:octicons-file-code-24: Source][2] · :octicons-tools-24: Default: [`Roboto`][3]
2020-07-16 23:55:37 +02:00
The _regular font_ is used for all body copy, headlines, and essentially
everything that does not need to be proportionally spaced. It can be set to any
valid [Google Font][1] with:
``` yaml
theme:
font:
2020-07-16 23:55:37 +02:00
text: Roboto
```
2020-07-16 23:55:37 +02:00
The typeface will be loaded in 300, 400, *400i* and **700**.
[2]: https://github.com/squidfunk/mkdocs-material/blob/master/src/base.html#L120-L139
[3]: https://fonts.google.com/specimen/Roboto
### Proportional font
[:octicons-file-code-24: Source][2] · :octicons-tools-24: Default:
[`Roboto Mono`][4]
The _proportional font_ is used for code blocks and can be configured separately.
Just like the regular font, it can be set to any valid [Google Font][1] from
`mkdocs.yml` with:
``` yaml
theme:
2020-07-16 23:55:37 +02:00
font:
code: Roboto Mono
```
2020-07-16 23:55:37 +02:00
The typeface will be loaded in 400.
[4]: https://fonts.google.com/specimen/Roboto+Mono
## Customization
2020-07-16 23:55:37 +02:00
If you want to load fonts from other destinations or don't want to use Google
Fonts for [data privacy][5] reasons, e.g. _due to GDPR_, add the following lines
to `mkdocs.yml`:
``` yaml
theme:
font: false
```
This will prevent typefaces from being loaded from Google Fonts. As a fallback,
common system fonts will be used automatically. Additionally, if you want to
load a font from another destination, you can either [override the `fonts`
block][6] with a `style` tag, or use an [additional stylesheet][7] to add the
necessary `@font-face` definition:
``` css
@font-face {
font-family: "<font>";
src: "...";
}
```
The font can then be configured to be used as the regular or proportional font:
=== "Regular"
``` css
body, input {
font-family: "<font>", -apple-system, Helvetica, Arial, sans-serif;
}
```
=== "Proportional"
``` css
pre, code, kbd {
font-family: "<font>", SFMono-Regular, Consolas, Menlo, monospace;
}
```
[5]: ../getting-started/data-privacy.md
[6]: ../getting-started/customization.md#overriding-blocks
[7]: ../getting-started/customization.md#additional-stylesheets