1
0
mirror of https://github.com/squidfunk/mkdocs-material.git synced 2024-09-24 19:38:27 +02:00
mkdocs-material/docs/setup/changing-the-fonts.md
2020-07-26 14:46:09 +02:00

2.7 KiB

template
overrides/main.html

Changing the fonts

Material for MkDocs makes it easy to change the typeface of your project documentation, as it directly integrates with Google Fonts. Alternatively, fonts can be custom-loaded if self-hosting is preferred for data privacy reasons or another destination should be used.

Configuration

Regular font

:octicons-file-code-24: Source · :octicons-milestone-24: Default: Roboto

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 with:

theme:
  font:
    text: Roboto

The typeface will be loaded in 300, 400, 400i and 700.

Proportional font

:octicons-file-code-24: Source · :octicons-milestone-24: Default: Roboto Mono

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 via mkdocs.yml with:

theme:
  font:
    code: Roboto Mono

The typeface will be loaded in 400.

Customization

If you want to load fonts from other destinations or don't want to use Google Fonts for data privacy reasons, e.g. due to GDPR, you may customize font loading as described below.

Disabling font loading

:octicons-file-code-24: Source · :octicons-mortar-board-24: Difficulty: easy

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:

theme:
  font: false

Additional fonts

:octicons-file-code-24: Source · :octicons-mortar-board-24: Difficulty: easy

If you want to load an (additional) font from another or override the fallback font, you can use an additional stylesheet to add the corresponding @font-face definition:

@font-face {
  font-family: "<font>";
  src: "...";
}

The font can then be applied to specific elements, e.g. only headlines, or globally to be used as the site-wide regular or proportional font:

=== "Regular font"

``` css
body, input {
  font-family: "<font>", -apple-system, Helvetica, Arial, sans-serif;
}
```

=== "Proportional font"

``` css
pre, code, kbd {
  font-family: "<font>", SFMono-Regular, Consolas, Menlo, monospace;
}
```