Short answer: name a primary and an accent in mkdocs.yml, or set custom and use CSS variables
How to change Material for MkDocs colors
In Material for MkDocs 9.8.1, you name a primary and an accent color under theme.palette in mkdocs.yml, or set them to custom and give --md-primary-fg-color and --md-accent-fg-color your own hex codes in an extra stylesheet. To preview a palette on your published docs first, load the site in Recolor (recolor.page) and press Space. You can test your site directly in the Recolor app.
Last updated
| Setting | Where | What it colors |
|---|---|---|
primary | theme.palette in mkdocs.yml | The header, the sidebar, text links and several other components |
accent | theme.palette in mkdocs.yml | What can be interacted with, such as hovered links, buttons and scrollbars |
scheme | theme.palette in mkdocs.yml | default, the light mode, or slate, the dark mode |
custom | primary or accent, plus extra_css | Your own values in --md-primary-fg-color and --md-accent-fg-color |
--md-hue | [data-md-color-scheme="slate"] in your stylesheet | The hue slate deduces its dark colors from |
| Your own scheme | [data-md-color-scheme="..."], then scheme set to its name | Every variable you put in that block |
Named colors in mkdocs.yml
Material for MkDocs' Changing the colors docs give two schemes: default for light mode and slate for dark
mode. The primary color applies to the header, the sidebar, text links and several other components. The
accent marks interactive elements, such as hovered links, buttons and scrollbars.
Both settings default to indigo and accept a name from Material Design's palette, such as teal or deep orange. The accent setting has no brown, grey, blue grey, black or white. With a palette toggle
configured in mkdocs.yml, each scheme entry can set its own primary and accent.
Your own colors with custom
For a custom brand hex code, Material for MkDocs' Changing the colors docs say Material implements its colors
as CSS variables. To use custom values, set primary or accent to custom and list a stylesheet under
extra_css:
theme:
palette:
primary: custom
accent: custom
extra_css:
- stylesheets/extra.cssThen set the variables in docs/stylesheets/extra.css using the selector from the docs:
:root > * {
--md-primary-fg-color: #264653;
--md-accent-fg-color: #e76f51;
}The example in the docs also sets --md-primary-fg-color--light and --md-primary-fg-color--dark, which
Material for MkDocs' colors file starts at indigo. Give them a lighter and a darker version of your primary,
since Recolor does not generate shades automatically. The same file also provides
--md-accent-fg-color--transparent for the accent at 0.1 opacity, and --md-primary-bg-color, which defaults
to white, for text placed on the primary color.
Slate deduces its dark colors from --md-hue, a hue value from 0 to 360. For example, 197 is the hue of
#264653:
[data-md-color-scheme="slate"] {
--md-hue: 197;
}A project in maintenance mode
Material for MkDocs' changelog says Material for MkDocs is in maintenance mode, gets no new features, and reaches end of life on May 5, 2027, with critical fixes and security updates until then. Material for MkDocs' changelog names Zensical as its maintained successor.
Try the palette on your live docs first
You can test color combinations on your documentation before updating files. Load the published site by its address in Recolor, press Space until a palette fits, and lock the colors you want to keep.
Each swatch shows its contrast with black and white text, evaluated
for 4.5:1 contrast. For instance, #264653 reads 10.08:1 with white text, which works well for
the header. In comparison, #e76f51 reads 3.09:1 on white, which is too low for a hovered link. A
localhost address is refused; upload a saved page instead.
When you copy the palette, Recolor provides CSS variables named --color-1 through --color-5 along with
--color-primary, --color-secondary and --color-accent. You can paste these into extra.css, but
Material reads none of those default names. Check the export formats to inspect the output,
then copy the hex codes into --md-primary-fg-color and --md-accent-fg-color by hand. You can find more
details in the guide to recoloring with CSS variables.
Common questions
Can I use any hex code as the primary color?
Yes. Set primary: custom in your mkdocs.yml file and assign your hex code to --md-primary-fg-color in your extra stylesheet.
Can light and dark mode have different colors?
Yes. Each palette definition in the toggle list can declare its own primary and accent color values.
Can I paste Recolor's CSS export as it is?
No. Material for MkDocs reads --md-primary-fg-color rather than --color-1, so you must assign the hex codes to Material's variable names manually.
Is Material for MkDocs still getting new features?
No. The project is in maintenance mode until its end of life on May 5, 2027, receiving only critical fixes and security updates.
Is Recolor free?
Yes. Loading a web page, generating color palettes and using every export format are free without an account.
Sources
- Material for MkDocs' Changing the colors docs squidfunk.github.io
- Material for MkDocs' changelog squidfunk.github.io
- Material for MkDocs' colors file, _colors.scss github.com