2020-07-16 23:31:39 +03:00
|
|
|
|
---
|
|
|
|
|
template: overrides/main.html
|
|
|
|
|
---
|
|
|
|
|
|
2020-07-21 17:01:22 +03:00
|
|
|
|
# Changing the colors
|
2020-07-16 23:31:39 +03:00
|
|
|
|
|
2020-07-26 15:46:09 +03:00
|
|
|
|
As any proper Material Design implementation, Material for MkDocs supports
|
2020-07-16 23:31:39 +03:00
|
|
|
|
Google's original [color palette][1], which can be easily configured through
|
2020-07-17 14:08:27 +03:00
|
|
|
|
`mkdocs.yml`. Furthermore, colors can be customized with a few lines of CSS to
|
2020-07-21 14:33:44 +03:00
|
|
|
|
fit your brand's identity by using [CSS variables][2].
|
2020-07-16 23:31:39 +03:00
|
|
|
|
|
|
|
|
|
[1]: http://www.materialui.co/colors
|
2020-07-21 19:39:27 +03:00
|
|
|
|
[2]: #custom-colors
|
2020-07-16 23:31:39 +03:00
|
|
|
|
|
|
|
|
|
## Configuration
|
|
|
|
|
|
2020-08-27 00:21:28 +03:00
|
|
|
|
### Color palette
|
|
|
|
|
|
|
|
|
|
#### Color scheme
|
2020-07-16 23:31:39 +03:00
|
|
|
|
|
2020-07-20 16:18:09 +03:00
|
|
|
|
[:octicons-file-code-24: Source][3] · :octicons-milestone-24: Default: `default`
|
2020-07-16 23:31:39 +03:00
|
|
|
|
|
|
|
|
|
Material for MkDocs supports two _color schemes_: a light mode, which is just
|
|
|
|
|
called `default`, and a dark mode, which is called `slate`. The color scheme
|
2020-07-23 14:17:50 +03:00
|
|
|
|
can be set via `mkdocs.yml`:
|
2020-07-16 23:31:39 +03:00
|
|
|
|
|
|
|
|
|
``` yaml
|
|
|
|
|
theme:
|
|
|
|
|
palette:
|
|
|
|
|
scheme: default
|
|
|
|
|
```
|
|
|
|
|
|
2020-07-26 15:46:09 +03:00
|
|
|
|
:material-cursor-default-click-outline: Click on a tile to change the color
|
2020-07-16 23:31:39 +03:00
|
|
|
|
scheme:
|
|
|
|
|
|
2020-07-19 23:23:26 +03:00
|
|
|
|
<div class="tx-switch">
|
|
|
|
|
<button data-md-color-scheme="default"><code>default</code></button>
|
|
|
|
|
<button data-md-color-scheme="slate"><code>slate</code></button>
|
|
|
|
|
</div>
|
2020-07-16 23:31:39 +03:00
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
var buttons = document.querySelectorAll("button[data-md-color-scheme]")
|
|
|
|
|
buttons.forEach(function(button) {
|
|
|
|
|
button.addEventListener("click", function() {
|
2020-07-17 14:08:27 +03:00
|
|
|
|
var attr = this.getAttribute("data-md-color-scheme")
|
|
|
|
|
document.body.setAttribute("data-md-color-scheme", attr)
|
2020-07-16 23:31:39 +03:00
|
|
|
|
var name = document.querySelector("#__code_0 code span:nth-child(7)")
|
2020-07-17 14:08:27 +03:00
|
|
|
|
name.textContent = attr
|
2020-07-16 23:31:39 +03:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
The _color scheme_ can also be set based on _user preference_, which makes use
|
2020-07-21 17:01:22 +03:00
|
|
|
|
of the `prefers-color-scheme` media query, by setting the value in `mkdocs.yml`
|
|
|
|
|
to `preference`:
|
2020-07-16 23:31:39 +03:00
|
|
|
|
|
|
|
|
|
``` yaml
|
|
|
|
|
theme:
|
|
|
|
|
palette:
|
|
|
|
|
scheme: preference
|
|
|
|
|
```
|
|
|
|
|
|
2020-07-17 00:05:57 +03:00
|
|
|
|
[3]: https://github.com/squidfunk/mkdocs-material/blob/master/src/assets/stylesheets/palette/_scheme.scss
|
|
|
|
|
|
2020-08-27 00:21:28 +03:00
|
|
|
|
#### Primary color
|
2020-07-16 23:31:39 +03:00
|
|
|
|
|
2020-07-20 16:18:09 +03:00
|
|
|
|
[:octicons-file-code-24: Source][4] · :octicons-milestone-24: Default: `indigo`
|
2020-07-16 23:31:39 +03:00
|
|
|
|
|
|
|
|
|
The _primary color_ is used for the header, the sidebar, text links and several
|
|
|
|
|
other components. In order to change the primary color, set the following value
|
|
|
|
|
in `mkdocs.yml` to a valid color name:
|
|
|
|
|
|
|
|
|
|
``` yaml
|
|
|
|
|
theme:
|
|
|
|
|
palette:
|
|
|
|
|
primary: indigo
|
|
|
|
|
```
|
|
|
|
|
|
2020-07-26 15:46:09 +03:00
|
|
|
|
:material-cursor-default-click-outline: Click on a tile to change the primary
|
2020-07-16 23:31:39 +03:00
|
|
|
|
color:
|
|
|
|
|
|
2020-07-19 23:23:26 +03:00
|
|
|
|
<div class="tx-switch">
|
|
|
|
|
<button data-md-color-primary="red"><code>red</code></button>
|
|
|
|
|
<button data-md-color-primary="pink"><code>pink</code></button>
|
|
|
|
|
<button data-md-color-primary="purple"><code>purple</code></button>
|
|
|
|
|
<button data-md-color-primary="deep-purple"><code>deep purple</code></button>
|
|
|
|
|
<button data-md-color-primary="indigo"><code>indigo</code></button>
|
|
|
|
|
<button data-md-color-primary="blue"><code>blue</code></button>
|
|
|
|
|
<button data-md-color-primary="light-blue"><code>light blue</code></button>
|
|
|
|
|
<button data-md-color-primary="cyan"><code>cyan</code></button>
|
|
|
|
|
<button data-md-color-primary="teal"><code>teal</code></button>
|
|
|
|
|
<button data-md-color-primary="green"><code>green</code></button>
|
|
|
|
|
<button data-md-color-primary="light-green"><code>light green</code></button>
|
|
|
|
|
<button data-md-color-primary="lime"><code>lime</code></button>
|
|
|
|
|
<button data-md-color-primary="yellow"><code>yellow</code></button>
|
|
|
|
|
<button data-md-color-primary="amber"><code>amber</code></button>
|
|
|
|
|
<button data-md-color-primary="orange"><code>orange</code></button>
|
|
|
|
|
<button data-md-color-primary="deep-orange"><code>deep orange</code></button>
|
|
|
|
|
<button data-md-color-primary="brown"><code>brown</code></button>
|
|
|
|
|
<button data-md-color-primary="grey"><code>grey</code></button>
|
|
|
|
|
<button data-md-color-primary="blue-grey"><code>blue grey</code></button>
|
|
|
|
|
<button data-md-color-primary="black"><code>black</code></button>
|
|
|
|
|
<button data-md-color-primary="white"><code>white</code></button>
|
|
|
|
|
</div>
|
2020-07-16 23:31:39 +03:00
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
var buttons = document.querySelectorAll("button[data-md-color-primary]")
|
|
|
|
|
buttons.forEach(function(button) {
|
|
|
|
|
button.addEventListener("click", function() {
|
2020-07-17 14:08:27 +03:00
|
|
|
|
var attr = this.getAttribute("data-md-color-primary")
|
|
|
|
|
document.body.setAttribute("data-md-color-primary", attr)
|
2020-07-16 23:31:39 +03:00
|
|
|
|
var name = document.querySelector("#__code_2 code span:nth-child(7)")
|
2020-07-17 14:08:27 +03:00
|
|
|
|
name.textContent = attr.replace("-", " ")
|
2020-07-16 23:31:39 +03:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
</script>
|
|
|
|
|
|
2020-07-17 00:05:57 +03:00
|
|
|
|
[4]: https://github.com/squidfunk/mkdocs-material/blob/master/src/assets/stylesheets/palette/_primary.scss
|
|
|
|
|
|
2020-08-27 00:21:28 +03:00
|
|
|
|
#### Accent color
|
2020-07-16 23:31:39 +03:00
|
|
|
|
|
2020-07-20 16:18:09 +03:00
|
|
|
|
[:octicons-file-code-24: Source][5] · :octicons-milestone-24: Default: `indigo`
|
2020-07-16 23:31:39 +03:00
|
|
|
|
|
|
|
|
|
The _accent color_ is used to denote elements that can be interacted with, e.g.
|
|
|
|
|
hovered links, buttons and scrollbars. It can be changed in `mkdocs.yml` by
|
2020-07-26 15:46:09 +03:00
|
|
|
|
choosing a valid color name:
|
2020-07-16 23:31:39 +03:00
|
|
|
|
|
|
|
|
|
``` yaml
|
|
|
|
|
theme:
|
|
|
|
|
palette:
|
|
|
|
|
accent: indigo
|
|
|
|
|
```
|
|
|
|
|
|
2020-07-26 15:46:09 +03:00
|
|
|
|
:material-cursor-default-click-outline: Click on a tile to change the accent
|
2020-07-16 23:31:39 +03:00
|
|
|
|
color:
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
.md-typeset button[data-md-color-accent] > code {
|
2020-07-19 23:23:26 +03:00
|
|
|
|
background-color: var(--md-code-bg-color);
|
2020-07-16 23:31:39 +03:00
|
|
|
|
color: var(--md-accent-fg-color);
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
|
2020-07-19 23:23:26 +03:00
|
|
|
|
<div class="tx-switch">
|
|
|
|
|
<button data-md-color-accent="red"><code>red</code></button>
|
|
|
|
|
<button data-md-color-accent="pink"><code>pink</code></button>
|
|
|
|
|
<button data-md-color-accent="purple"><code>purple</code></button>
|
|
|
|
|
<button data-md-color-accent="deep-purple"><code>deep purple</code></button>
|
|
|
|
|
<button data-md-color-accent="indigo"><code>indigo</code></button>
|
|
|
|
|
<button data-md-color-accent="blue"><code>blue</code></button>
|
|
|
|
|
<button data-md-color-accent="light-blue"><code>light blue</code></button>
|
|
|
|
|
<button data-md-color-accent="cyan"><code>cyan</code></button>
|
|
|
|
|
<button data-md-color-accent="teal"><code>teal</code></button>
|
|
|
|
|
<button data-md-color-accent="green"><code>green</code></button>
|
|
|
|
|
<button data-md-color-accent="light-green"><code>light green</code></button>
|
|
|
|
|
<button data-md-color-accent="lime"><code>lime</code></button>
|
|
|
|
|
<button data-md-color-accent="yellow"><code>yellow</code></button>
|
|
|
|
|
<button data-md-color-accent="amber"><code>amber</code></button>
|
|
|
|
|
<button data-md-color-accent="orange"><code>orange</code></button>
|
|
|
|
|
<button data-md-color-accent="deep-orange"><code>deep orange</code></button>
|
|
|
|
|
</div>
|
2020-07-16 23:31:39 +03:00
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
var buttons = document.querySelectorAll("button[data-md-color-accent]")
|
|
|
|
|
buttons.forEach(function(button) {
|
|
|
|
|
button.addEventListener("click", function() {
|
2020-07-17 14:08:27 +03:00
|
|
|
|
var attr = this.getAttribute("data-md-color-accent")
|
|
|
|
|
document.body.setAttribute("data-md-color-accent", attr)
|
2020-07-16 23:31:39 +03:00
|
|
|
|
var name = document.querySelector("#__code_3 code span:nth-child(7)")
|
2020-07-17 14:08:27 +03:00
|
|
|
|
name.textContent = attr.replace("-", " ")
|
2020-07-16 23:31:39 +03:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
</script>
|
|
|
|
|
|
2020-07-17 00:05:57 +03:00
|
|
|
|
[5]: https://github.com/squidfunk/mkdocs-material/blob/master/src/assets/stylesheets/palette/_accent.scss
|
|
|
|
|
|
2020-07-17 14:08:27 +03:00
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
!!! warning "Accessibility – not all color combinations work well"
|
|
|
|
|
|
|
|
|
|
With __2__ (color schemes) __x 21__ (primary colors) __x 17__ (accent color)
|
|
|
|
|
= __714__ combinations, it's impossible to ensure that all configurations
|
2020-07-26 15:46:09 +03:00
|
|
|
|
provide a good user experience (e.g. _yellow on light background_). Make
|
2020-07-17 14:08:27 +03:00
|
|
|
|
sure that the color combination of your choosing provides enough contrast
|
|
|
|
|
and tweak CSS variables where necessary.
|
|
|
|
|
|
2020-08-27 00:21:28 +03:00
|
|
|
|
### Color palette toggle
|
|
|
|
|
|
|
|
|
|
[:octicons-file-code-24: Source][6] ·
|
|
|
|
|
:octicons-beaker-24: Experimental ·
|
|
|
|
|
[:octicons-heart-fill-24:{: .tx-heart } Insiders only][6]{: .tx-insiders }
|
|
|
|
|
|
2020-08-30 12:49:05 +03:00
|
|
|
|
[Material for MkDocs Insiders][6] makes it possible to define multiple color
|
2020-08-27 00:21:28 +03:00
|
|
|
|
palettes, including a [scheme][7], [primary][8] and [accent][9] color each, and
|
|
|
|
|
let the user choose. Define them via `mkdocs.yml`:
|
|
|
|
|
|
|
|
|
|
``` yaml
|
|
|
|
|
theme:
|
|
|
|
|
palette:
|
|
|
|
|
- scheme: default
|
|
|
|
|
primary: indigo
|
|
|
|
|
accent: indigo
|
|
|
|
|
toggle:
|
|
|
|
|
icon: material/toggle-switch
|
|
|
|
|
name: Switch to light mode
|
|
|
|
|
- scheme: slate
|
|
|
|
|
primary: blue
|
|
|
|
|
accent: blue
|
|
|
|
|
toggle:
|
|
|
|
|
icon: material/toggle-switch-off-outline
|
|
|
|
|
name: Switch to dark mode
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
The `toggle` field allows to specify an `icon` and `name` for each palette. The
|
|
|
|
|
toggle is rendered next to the search bar and will cycle through all defined
|
|
|
|
|
color palettes:
|
|
|
|
|
|
|
|
|
|
`icon`{: #icon }
|
|
|
|
|
|
|
|
|
|
: :octicons-milestone-24: Default: _none_ · :octicons-alert-24: Required –
|
|
|
|
|
This field must point to a valid icon path referencing [any icon bundled
|
|
|
|
|
with the theme][10], or the build will not succeed. Some popular
|
|
|
|
|
combinations:
|
|
|
|
|
|
|
|
|
|
* :material-toggle-switch-off-outline: + :material-toggle-switch: – `material/toggle-switch-off-outline` + `material/toggle-switch`
|
|
|
|
|
* :material-weather-sunny: + :material-weather-night: – `material/weather-sunny` + `material/weather-night`
|
|
|
|
|
* :material-eye-outline: + :material-eye: – `material/eye-outline` + `material/eye`
|
|
|
|
|
* :material-lightbulb-outline: + :material-lightbulb: – `material/lightbulb-outline` + `material/lightbulb`
|
|
|
|
|
|
|
|
|
|
`name`{: #name }
|
|
|
|
|
|
|
|
|
|
: :octicons-milestone-24: Default: _none_ · :octicons-alert-24: Required –
|
|
|
|
|
This field is used as the toggle's `title` attribute and should be set to a
|
|
|
|
|
discernable name to improve accessibility.
|
|
|
|
|
|
2020-10-11 18:41:54 +03:00
|
|
|
|
[Try this feature][11]{: .md-button .md-button--primary }
|
|
|
|
|
|
|
|
|
|
_This feature is enabled on the [official documentation][11] built with
|
|
|
|
|
Insiders. Click the button to go to Material for MkDocs Insiders and give this
|
|
|
|
|
feature a try._
|
2020-08-27 00:21:28 +03:00
|
|
|
|
|
|
|
|
|
[6]: ../insiders.md
|
|
|
|
|
[7]: #color-scheme
|
|
|
|
|
[8]: #primary-color
|
|
|
|
|
[9]: #accent-color
|
|
|
|
|
[10]: https://github.com/squidfunk/mkdocs-material/tree/master/material/.icons
|
|
|
|
|
[11]: https://squidfunk.github.io/mkdocs-material-insiders/setup/changing-the-colors
|
|
|
|
|
|
2020-07-16 23:31:39 +03:00
|
|
|
|
## Customization
|
|
|
|
|
|
2020-07-21 19:39:27 +03:00
|
|
|
|
### Custom colors
|
2020-07-21 17:01:22 +03:00
|
|
|
|
|
2020-08-27 00:21:28 +03:00
|
|
|
|
[:octicons-file-code-24: Source][12] ·
|
2020-07-21 17:01:22 +03:00
|
|
|
|
:octicons-mortar-board-24: Difficulty: _easy_
|
2020-07-20 16:18:09 +03:00
|
|
|
|
|
2020-08-27 00:21:28 +03:00
|
|
|
|
Material for MkDocs implements colors using [CSS variables][13] (custom
|
2020-07-16 23:31:39 +03:00
|
|
|
|
properties). If you want to customize the colors beyond the palette (e.g. to
|
2020-08-27 00:21:28 +03:00
|
|
|
|
use your brand-specific colors), you can add an [additional stylesheet][14] and
|
2020-07-23 14:17:50 +03:00
|
|
|
|
tweak the values of the CSS variables.
|
|
|
|
|
|
|
|
|
|
Let's say you're :fontawesome-brands-youtube:{: style="color: #EE0F0F" }
|
2020-07-24 15:30:03 +03:00
|
|
|
|
__YouTube__, and want to set the primary color to your brand's palette. Just
|
2020-07-23 14:17:50 +03:00
|
|
|
|
add:
|
2020-07-16 23:31:39 +03:00
|
|
|
|
|
|
|
|
|
``` css
|
|
|
|
|
:root {
|
2020-07-23 14:17:50 +03:00
|
|
|
|
--md-primary-fg-color: #EE0F0F;
|
|
|
|
|
--md-primary-fg-color--light: #ECB7B7;
|
|
|
|
|
--md-primary-fg-color--dark: #90030C;
|
2020-07-16 23:31:39 +03:00
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2020-08-27 00:21:28 +03:00
|
|
|
|
See the file containing the [color definitions][12] for a list of all CSS
|
2020-07-23 14:17:50 +03:00
|
|
|
|
variables.
|
|
|
|
|
|
2020-08-27 00:21:28 +03:00
|
|
|
|
[12]: https://github.com/squidfunk/mkdocs-material/blob/master/src/assets/stylesheets/main/_colors.scss
|
|
|
|
|
[13]: https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties
|
2020-09-19 15:34:40 +03:00
|
|
|
|
[14]: ../customization.md#additional-css
|
2020-07-23 14:17:50 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### Custom color schemes
|
|
|
|
|
|
|
|
|
|
[:octicons-file-code-24: Source][3] ·
|
|
|
|
|
:octicons-mortar-board-24: Difficulty: _easy_
|
|
|
|
|
|
|
|
|
|
Besides overriding specific colors, you can create your own, named color scheme
|
2020-07-24 15:30:03 +03:00
|
|
|
|
by wrapping the definitions in the `#!css [data-md-color-scheme="..."]`
|
2020-08-27 00:21:28 +03:00
|
|
|
|
[attribute selector][15], which you can then set via `mkdocs.yml` as described
|
|
|
|
|
in the [color schemes][7] section:
|
2020-07-16 23:31:39 +03:00
|
|
|
|
|
|
|
|
|
``` css
|
2020-07-23 14:17:50 +03:00
|
|
|
|
[data-md-color-scheme="youtube"] {
|
|
|
|
|
--md-primary-fg-color: #EE0F0F;
|
|
|
|
|
--md-primary-fg-color--light: #ECB7B7;
|
|
|
|
|
--md-primary-fg-color--dark: #90030C;
|
2020-07-16 23:31:39 +03:00
|
|
|
|
}
|
2020-07-27 15:44:47 +03:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Additionally, the `slate` color scheme defines all of it's colors via `hsla`
|
|
|
|
|
color functions and deduces its colors from the `--md-hue` CSS variable. You
|
|
|
|
|
can tune the `slate` theme with:
|
|
|
|
|
|
|
|
|
|
``` css
|
|
|
|
|
[data-md-color-scheme="slate"] {
|
|
|
|
|
--md-hue: 210; /* [0, 360] */
|
|
|
|
|
}
|
2020-07-16 23:31:39 +03:00
|
|
|
|
```
|
|
|
|
|
|
2020-08-27 00:21:28 +03:00
|
|
|
|
[15]: https://www.w3.org/TR/selectors-4/#attribute-selectors
|