| 1 |
Fonts and FontAwesome |
| 2 |
===================== |
| 3 |
|
| 4 |
The theme includes the `FontAwesome 6 Free <https://fontawesome.com/icons?m=free>`__ |
| 5 |
icon font (the ``.fa-solid, .fa-regular, .fa-brands`` styles, which are used for |
| 6 |
:ref:`icon links <icon-links>` and admonitions). |
| 7 |
This is the only *vendored* font, and otherwise, the theme by default relies on |
| 8 |
available system fonts for normal body text and headers. |
| 9 |
|
| 10 |
For more details on the PyData Sphinx Theme typography and text styles, see the |
| 11 |
:doc:`../community/design-system` section. |
| 12 |
|
| 13 |
The default body and header fonts can be changed as follows: |
| 14 |
|
| 15 |
- Using :ref:`custom-css`, you can specify which fonts to use for the body, header, |
| 16 |
and monospaced text. For example, the following can be added to a custom |
| 17 |
CSS file: |
| 18 |
|
| 19 |
.. code-block:: css |
| 20 |
|
| 21 |
html { |
| 22 |
--pst-font-family-base: Verdana, var(--pst-font-family-base-system); |
| 23 |
--pst-font-family-heading: Cambria, Georgia, Times, var(--pst-font-family-base-system); |
| 24 |
--pst-font-family-monospace: Courier, var(--pst-font-family-monospace-system); |
| 25 |
} |
| 26 |
|
| 27 |
The ``*-system`` variables are available to use as a fallback to the default fonts. |
| 28 |
|
| 29 |
- If the font you want to specify in the section above is not generally available |
| 30 |
by default, you will additionally need to ensure the font is loaded. |
| 31 |
For example, you could download and vendor the font in the ``_static`` directory |
| 32 |
of your Sphinx site, and then update the base template to load the font resources: |
| 33 |
|
| 34 |
- Configure the `template_path <https://www.sphinx-doc.org/en/master/development/theming.html#templating>`__ |
| 35 |
in your ``conf.py`` |
| 36 |
- Create a custom ``layout.html`` Jinja2 template which overloads the ``fonts`` block |
| 37 |
(example for loading the Lato font that is included in the ``_static/vendor`` directory): |
| 38 |
|
| 39 |
.. code-block:: html+jinja |
| 40 |
|
| 41 |
{% extends "pydata_sphinx_theme/layout.html" %} |
| 42 |
|
| 43 |
{% block fonts %} |
| 44 |
<!-- add `style` or `link` tags with your CSS `@font-face` declarations here --> |
| 45 |
<!-- ... and optionally preload the `woff2` for snappier page loads --> |
| 46 |
<link rel="stylesheet" href="{{ pathto('_static/vendor/lato_latin-ext/1.44.1/index.css', 1) }}"> |
| 47 |
|
| 48 |
{% endblock %} |
| 49 |
|
| 50 |
Your text may quickly show up as "unstyled" before the fonts are loaded. To reduce this, you may wish to explore options for |
| 51 |
`preloading content <https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Attributes/rel/preload>`__, |
| 52 |
specifically the binary font files. This ensures the files will be loaded |
| 53 |
before the CSS is parsed, but should be used with care. |
| 54 |
|
| 55 |
.. _pydata-css-variables: https://github.com/pydata/pydata-sphinx-theme/tree/main/src/pydata_sphinx_theme/assets/styles/variables |
| 56 |
.. _pydata-css-colors: https://github.com/pydata/pydata-sphinx-theme/blob/main/src/pydata_sphinx_theme/assets/styles/variables/_color.scss |
| 57 |
.. _css-variable-help: https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties |