Skip to content

Customization¤

It is possible to customize the output of the generated documentation with CSS and/or by overriding templates.

CSS classes¤

Our templates add CSS classes to many HTML elements to make it possible for users to customize the resulting look and feel.

To add CSS rules and style mkdocstrings' output, put them in a CSS file in your docs folder, for example in docs/css/mkdocstrings.css, and reference this file in MkDocs' extra_css configuration option:

mkdocs.yml
extra_css:
- css/mkdocstrings.css

Symbol types¤

Colors¤

You can customize the colors of the symbol types (see show_symbol_type_heading and show_symbol_type_toc) by overriding the values of our CSS variables, for example:

docs/css/mkdocstrings.css
[data-md-color-scheme="default"] {
  --doc-symbol-sh-function-fg-color: #8250df;
  --doc-symbol-sh-script-fg-color: #0550ae;

  --doc-symbol-sh-function-bg-color: #8250df1a;
  --doc-symbol-sh-script-bg-color: #0550ae1a;
}

[data-md-color-scheme="slate"] {
  --doc-symbol-sh-function-fg-color: #d2a8ff;
  --doc-symbol-sh-script-fg-color: #79c0ff;

  --doc-symbol-sh-function-bg-color: #d2a8ff1a;
  --doc-symbol-sh-script-bg-color: #79c0ff1a;
}

The [data-md-color-scheme="*"] selectors work with the [Material for MkDocs] theme. If you are using another theme, adapt the selectors to this theme if it supports light and dark themes, otherwise just override the variables at root level:

docs/css/mkdocstrings.css
:root {
  --doc-symbol-sh-function-fg-color: #d1b619;
  --doc-symbol-sh-function-bg-color: #d1b6191a;
}

Preview

Try cycling through the themes to see the colors for each theme:

Names¤

You can also change the actual symbol names. For example, to use single letters instead of truncated types:

docs/css/mkdocstrings.css
.doc-symbol-sh-function::after {
  content: "F";
}
.doc-symbol-sh-script::after {
  content: "S";
}

Preview

  • Function:
  • Script:

Templates¤

Templates are organized into the following tree:

📁 theme/
├──  function.html.jinja
└──  script.html.jinja

See them in the repository. See the general mkdocstrings documentation to learn how to override them: https://mkdocstrings.github.io/theming/#templates.

Each one of these templates extends a base version in theme/_base. Example:

theme/script.html.jinja
{% extends "_base/script.html.jinja" %}

Some of these templates define Jinja blocks. allowing to customize only parts of a template without having to fully copy-paste it into your project:

templates/theme/script.html
{% extends "_base/script.html" %}
{% block contents scoped %}
  {{ block.super }}
  Additional contents
{% endblock contents %}