Changing the look and feel
The appearance of your website is set in one file: mkdocs.yml, in the root of your repository. This page shows the changes students ask for most. Make them with the local preview running, so you see the result straight away.
mkdocs.yml is strict about indentation
The file is written in YAML. Indent with spaces, not tabs, and keep the indentation exactly as in the examples. One misplaced space breaks the build of the whole website, for your entire team. If the preview stops, the terminal tells you on which line the problem is.
Name your website
The first lines of mkdocs.yml hold the name that is shown in the header and in the browser tab. Replace the template text with your own:
1 2 3 4 | |
Colours and dark mode
Add a palette to the theme section. The simplest version picks a primary colour (header and links) and an accent colour (hover and highlights):
1 2 3 4 5 6 7 8 | |
You can choose from the colour names of the Material theme, such as red, pink, purple, deep purple, indigo, blue, teal, green, amber, deep orange, brown, blue grey, black and white. The colour documentation shows them all.
To let visitors switch between a light and a dark version, define two palettes with a toggle:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | |
Fonts
Any font from Google Fonts works. Add this inside the theme section, at the same depth as palette:
1 2 3 | |
Logo and favicon
Put the image files in docs/, for example in docs/images/, and point to them from the theme section. The paths are relative to the docs/ folder:
1 2 | |
Only use images you made yourself or are allowed to use.
Navigation
The features list switches parts of the theme on and off. Some useful ones:
| Feature | What it does |
|---|---|
navigation.tabs |
Shows the top-level sections as tabs in the header. Good when every student has their own folder. |
navigation.sections |
Shows sections as groups in the sidebar. Already on. |
navigation.expand |
Opens all sections in the sidebar by default. |
navigation.top |
Adds a "back to top" button. |
toc.integrate |
Moves the table of contents of a page into the left sidebar. |
content.code.copy |
Adds a copy button to code blocks. |
Add the ones you want as extra lines under features::
1 2 3 4 5 | |
The order and titles of the pages themselves are not set here but in .pages files. See Writing documentation.
Your own CSS
For everything the settings above cannot do, add your own stylesheet.
- Create the file
docs/stylesheets/extra.css. -
Tell MkDocs to load it. Add this to
mkdocs.yml, at the far left, not insidetheme:1 2
extra_css: - stylesheets/extra.css -
Write your CSS. The theme uses CSS variables, so a custom brand colour takes only a few lines:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
:root { --md-primary-fg-color: #bb0013; /* header and links */ --md-primary-fg-color--light: #e0334a; --md-primary-fg-color--dark: #8a000e; --md-accent-fg-color: #ff8a00; /* hover */ } /* Wider text column */ .md-grid { max-width: 1400px; } /* Rounded screenshots with a soft shadow */ .md-typeset img { border-radius: 8px; box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15); }
To find out which CSS class an element has, right-click it in your browser and choose Inspect.
Keep it readable
Check your colours in both light and dark mode, and make sure text has enough contrast with its background. A website that people cannot read does not explain anything.
A complete example
This is the theme part of mkdocs.yml with everything from this page combined. Leave the plugins and markdown_extensions sections below it as they are.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |
Going further
The Material for MkDocs documentation describes every setting. The look of the slide deck is separate and is covered in The slide deck.