2020-07-16 22:31:39 +02:00
|
|
|
---
|
|
|
|
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,
|
2020-07-20 19:28:13 +02:00
|
|
|
fonts can be custom-loaded if self-hosting is preferred for data privacy reasons
|
|
|
|
or another destination should be used.
|
2020-07-16 23:55:37 +02:00
|
|
|
|
|
|
|
[1]: https://fonts.google.com
|
|
|
|
|
2020-07-16 22:31:39 +02:00
|
|
|
## Configuration
|
|
|
|
|
2020-07-16 23:55:37 +02:00
|
|
|
### Regular font
|
|
|
|
|
2020-07-20 15:18:09 +02:00
|
|
|
[:octicons-file-code-24: Source][2] ·
|
|
|
|
:octicons-milestone-24: Default: [`Roboto`][3]
|
2020-07-16 22:31:39 +02:00
|
|
|
|
2020-07-16 23:55:37 +02:00
|
|
|
The _regular font_ is used for all body copy, headlines, and essentially
|
2021-02-19 14:57:40 +01:00
|
|
|
everything that does not need to be monospaced. It can be set to any
|
2020-07-16 23:55:37 +02:00
|
|
|
valid [Google Font][1] with:
|
2020-07-16 22:31:39 +02:00
|
|
|
|
|
|
|
``` yaml
|
|
|
|
theme:
|
|
|
|
font:
|
2020-07-16 23:55:37 +02:00
|
|
|
text: Roboto
|
2020-07-16 22:31:39 +02:00
|
|
|
```
|
|
|
|
|
2020-07-17 13:08:27 +02:00
|
|
|
The typeface will be loaded in 300, 400, _400i_ and __700__.
|
2020-07-16 23:55:37 +02:00
|
|
|
|
2020-12-21 17:38:58 +01:00
|
|
|
[2]: https://github.com/squidfunk/mkdocs-material/blob/master/src/base.html
|
2020-07-16 23:55:37 +02:00
|
|
|
[3]: https://fonts.google.com/specimen/Roboto
|
|
|
|
|
2021-02-19 14:57:40 +01:00
|
|
|
### Monospaced font
|
2020-07-16 23:55:37 +02:00
|
|
|
|
2020-07-20 15:18:09 +02:00
|
|
|
[:octicons-file-code-24: Source][2] ·
|
|
|
|
:octicons-milestone-24: Default: [`Roboto Mono`][4]
|
2020-07-16 23:55:37 +02:00
|
|
|
|
2021-02-19 14:57:40 +01:00
|
|
|
The _monospaced font_ is used for code blocks and can be configured separately.
|
2020-07-23 13:17:50 +02:00
|
|
|
Just like the regular font, it can be set to any valid [Google Font][1] via
|
2020-07-16 23:55:37 +02:00
|
|
|
`mkdocs.yml` with:
|
2020-07-16 22:31:39 +02:00
|
|
|
|
|
|
|
``` yaml
|
|
|
|
theme:
|
2020-07-16 23:55:37 +02:00
|
|
|
font:
|
|
|
|
code: Roboto Mono
|
2020-07-16 22:31:39 +02:00
|
|
|
```
|
|
|
|
|
2020-07-16 23:55:37 +02:00
|
|
|
The typeface will be loaded in 400.
|
|
|
|
|
|
|
|
[4]: https://fonts.google.com/specimen/Roboto+Mono
|
2020-07-16 22:31:39 +02:00
|
|
|
|
|
|
|
## Customization
|
|
|
|
|
2020-07-21 16:01:22 +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_, you may customize
|
|
|
|
font loading as described below.
|
|
|
|
|
2020-07-21 18:39:27 +02:00
|
|
|
### Disabling font loading
|
2020-07-21 16:01:22 +02:00
|
|
|
|
2020-07-20 15:18:09 +02:00
|
|
|
[:octicons-file-code-24: Source][2] ·
|
2020-07-21 18:39:27 +02:00
|
|
|
:octicons-mortar-board-24: Difficulty: _easy_
|
2020-07-20 15:18:09 +02:00
|
|
|
|
2020-07-21 16:01:22 +02:00
|
|
|
If you want to prevent typefaces from being loaded from Google Fonts and fall
|
|
|
|
back to system fonts, add the following lines to `mkdocs.yml`:
|
2020-07-16 23:55:37 +02:00
|
|
|
|
|
|
|
``` yaml
|
|
|
|
theme:
|
|
|
|
font: false
|
|
|
|
```
|
|
|
|
|
2020-07-21 16:01:22 +02:00
|
|
|
### Additional fonts
|
|
|
|
|
|
|
|
[:octicons-file-code-24: Source][2] ·
|
|
|
|
:octicons-mortar-board-24: Difficulty: _easy_
|
|
|
|
|
2020-07-26 14:46:09 +02:00
|
|
|
If you want to load an (additional) font from another or override
|
2020-07-21 16:01:22 +02:00
|
|
|
the fallback font, you can use an [additional stylesheet][8] to add the
|
|
|
|
corresponding `@font-face` definition:
|
2020-07-16 23:55:37 +02:00
|
|
|
|
|
|
|
``` css
|
|
|
|
@font-face {
|
|
|
|
font-family: "<font>";
|
|
|
|
src: "...";
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2020-07-21 18:39:27 +02:00
|
|
|
The font can then be applied to specific elements, e.g. only headlines, or
|
2021-03-21 17:14:32 +01:00
|
|
|
globally to be used as the site-wide regular or monospaced font (with fallback
|
|
|
|
fonts being added automatically):
|
2020-07-16 23:55:37 +02:00
|
|
|
|
2020-07-21 18:39:27 +02:00
|
|
|
=== "Regular font"
|
2020-07-16 23:55:37 +02:00
|
|
|
|
|
|
|
``` css
|
2021-03-21 17:14:32 +01:00
|
|
|
:root {
|
|
|
|
--md-text-font-family: "<font>";
|
2020-07-16 23:55:37 +02:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2021-02-19 14:57:40 +01:00
|
|
|
=== "Monospaced font"
|
2020-07-16 23:55:37 +02:00
|
|
|
|
|
|
|
``` css
|
2021-03-21 17:14:32 +01:00
|
|
|
:root {
|
|
|
|
--md-code-font-family: "<font>";
|
2020-07-16 23:55:37 +02:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2020-07-17 13:08:27 +02:00
|
|
|
[5]: ../data-privacy.md
|
2020-07-17 16:50:57 +02:00
|
|
|
[6]: ../customization.md#extending-the-theme
|
2020-07-17 14:33:52 +02:00
|
|
|
[7]: ../customization.md#overriding-blocks
|
|
|
|
[8]: ../customization.md#additional-stylesheets
|