@@ -97,7 +97,7 @@ _Click on a tile to change the primary color_:
97
97
button.addEventListener("click", function() {
98
98
var attr = this.getAttribute("data-md-color-primary")
99
99
document.body.setAttribute("data-md-color-primary", attr)
100
- var name = document.querySelector("#__code_2 code span:nth-child(7)")
100
+ var name = document.querySelector("#__code_1 code span:nth-child(7)")
101
101
name.textContent = attr.replace("-", " ")
102
102
})
103
103
})
@@ -153,85 +153,42 @@ _Click on a tile to change the accent color_:
153
153
button.addEventListener("click", function() {
154
154
var attr = this.getAttribute("data-md-color-accent")
155
155
document.body.setAttribute("data-md-color-accent", attr)
156
- var name = document.querySelector("#__code_3 code span:nth-child(7)")
156
+ var name = document.querySelector("#__code_2 code span:nth-child(7)")
157
157
name.textContent = attr.replace("-", " ")
158
158
})
159
159
})
160
160
</script>
161
161
162
162
[5] : https://github.com/squidfunk/mkdocs-material/blob/master/src/assets/stylesheets/palette/_accent.scss
163
163
164
- ---
165
-
166
- !!! warning "Accessibility – not all color combinations work well"
167
-
168
- With __2__ (color schemes) __x 21__ (primary colors) __x 17__ (accent color)
169
- = __714__ combinations, it's impossible to ensure that all configurations
170
- provide a good user experience (e.g. _yellow on light background_). Make
171
- sure that the color combination of your choosing provides enough contrast
172
- and tweak CSS variables where necessary.
173
-
174
164
# ## Color palette toggle
175
165
176
- It's also possible to add multiple color palettes, including a [scheme][8],
177
- [primary][9] and [accent][10] color each, and let the user choose. A color
178
- palette toggle can be added via `mkdocs.yml` :
166
+ [:octicons-file-code-24 : Source][6] · :octicons-milestone-24: Default: _none_
179
167
180
- ` ` ` yaml
168
+ It's also possible to offer a list of color palettes to the user, each of which
169
+ can include a [`scheme`][7], [`primary`][8] and [`accent`][9] color each. The
170
+ user can toggle between those color palettes :
171
+
172
+ ` ` ` yaml hl_lines="4-6 8-10"
181
173
theme:
182
174
palette:
183
-
184
- # Light mode
185
- - media: "(prefers-color-scheme: light)"
186
- scheme: default
187
- primary: indigo
188
- accent: indigo
175
+ - scheme: default
189
176
toggle:
190
177
icon: material/toggle-switch-off-outline
191
178
name: Switch to dark mode
192
-
193
- # Dark mode
194
- - media: "(prefers-color-scheme: dark)"
195
- scheme: slate
196
- primary: blue
197
- accent: blue
179
+ - scheme: slate
198
180
toggle:
199
181
icon: material/toggle-switch
200
182
name: Switch to light mode
201
183
` ` `
202
184
203
- In order to set a default theme based on user preference, add a valid media
204
- query to the `media` attribute. This will render a color palette toggle in the
205
- header next to the search bar :
206
-
207
-
208
- <figure markdown="1">
209
-
210
- === "Light mode"
211
-
212
- [![Light mode][11]][11]
213
-
214
- === "Dark mode"
215
-
216
- [![Dark mode][12]][12]
217
-
218
- <figcaption markdown="1" style="margin-top : -2.0rem">
219
-
220
- A demo is worth a thousand words — check it out at
221
- [squidfunk.github.io/mkdocs-material-insiders][7]
222
-
223
- </figcaption>
224
- </figure>
225
-
226
- The `toggle` field allows to specify an `icon` and `name` for each palette. The
227
- toggle is rendered next to the search bar and will cycle through all defined
228
- color palettes :
185
+ The following fields must be set for each toggle :
229
186
230
187
` icon` { # icon }
231
188
232
189
: :octicons-milestone-24 : Default: _none_ · :octicons-alert-24: Required –
233
190
This field must point to a valid icon path referencing [any icon bundled
234
- with the theme][13 ], or the build will not succeed. Some popular
191
+ with the theme][10 ], or the build will not succeed. Some popular
235
192
combinations :
236
193
237
194
* :material-toggle-switch-off-outline: + :material-toggle-switch: – `material/toggle-switch-off-outline` + `material/toggle-switch`
@@ -245,25 +202,57 @@ color palettes:
245
202
This field is used as the toggle's `title` attribute and should be set to a
246
203
discernable name to improve accessibility.
247
204
248
- [6] : ../insiders/index.md
249
- [7] : https://squidfunk.github.io/mkdocs-material-insiders/setup/changing-the-colors
250
- [8] : # color-scheme
251
- [9] : # primary-color
252
- [10] : # accent-color
253
- [11] : ../assets/screenshots/palette-toggle-default.png
254
- [12] : ../assets/screenshots/palette-toggle-slate.png
255
- [13] : https://github.com/squidfunk/mkdocs-material/tree/master/material/.icons
205
+ [6] : https://github.com/squidfunk/mkdocs-material/blob/master/src/partials/header.html
206
+ [7] : # color-scheme
207
+ [8] : # primary-color
208
+ [9] : # accent-color
209
+ [10] : https://github.com/squidfunk/mkdocs-material/tree/master/material/.icons
210
+
211
+ # ## System preference
212
+
213
+ [:octicons-file-code-24 : Source][6] · :octicons-milestone-24: Default: _none_
214
+
215
+ In order to automatically set the color palette to the user's system preference,
216
+ a media query can be set as part of the `media` field next to the toggle
217
+ definition in `mkdocs.yml` :
218
+
219
+ ` ` ` yaml hl_lines="3 8"
220
+ theme:
221
+ palette:
222
+ - media: "(prefers-color-scheme: light)"
223
+ scheme: default
224
+ toggle:
225
+ icon: material/toggle-switch-off-outline
226
+ name: Switch to dark mode
227
+ - media: "(prefers-color-scheme: dark)"
228
+ scheme: slate
229
+ toggle:
230
+ icon: material/toggle-switch
231
+ name: Switch to light mode
232
+ ` ` `
233
+
234
+ When the user first visits your site, the media queries are evaluated in the
235
+ order of their definition. The first media query that matches selects the
236
+ default color palette.
237
+
238
+ !!! warning "Accessibility – not all color combinations work well"
239
+
240
+ With __2__ (color schemes) __x 21__ (primary colors) __x 17__ (accent color)
241
+ = __714__ combinations, it's impossible to ensure that all configurations
242
+ provide a good user experience (e.g. _yellow on light background_). Make
243
+ sure that the color combination of your choosing provides enough contrast
244
+ and tweak CSS variables where necessary.
256
245
257
246
# # Customization
258
247
259
248
# ## Custom colors
260
249
261
- [:octicons-file-code-24 : Source][14 ] ·
250
+ [:octicons-file-code-24 : Source][11 ] ·
262
251
:octicons-mortar-board-24 : Difficulty: _easy_
263
252
264
- Material for MkDocs implements colors using [CSS variables][15 ] (custom
253
+ Material for MkDocs implements colors using [CSS variables][12 ] (custom
265
254
properties). If you want to customize the colors beyond the palette (e.g. to
266
- use your brand-specific colors), you can add an [additional stylesheet][16 ] and
255
+ use your brand-specific colors), you can add an [additional stylesheet][13 ] and
267
256
tweak the values of the CSS variables.
268
257
269
258
Let's say you're :fontawesome-brands-youtube:{ style="color : # EE0F0F" }
@@ -278,23 +267,23 @@ add:
278
267
}
279
268
` ` `
280
269
281
- See the file containing the [color definitions][14 ] for a list of all CSS
270
+ See the file containing the [color definitions][11 ] for a list of all CSS
282
271
variables.
283
272
284
- [14 ] : https://github.com/squidfunk/mkdocs-material/blob/master/src/assets/stylesheets/main/_colors.scss
285
- [15 ] : https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties
286
- [16 ] : ../customization.md#additional-css
273
+ [11 ] : https://github.com/squidfunk/mkdocs-material/blob/master/src/assets/stylesheets/main/_colors.scss
274
+ [12 ] : https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties
275
+ [13 ] : ../customization.md#additional-css
287
276
288
277
289
278
# ## Custom color schemes
290
279
291
- [:octicons-file-code-24 : Source][14 ] ·
280
+ [:octicons-file-code-24 : Source][11 ] ·
292
281
:octicons-mortar-board-24 : Difficulty: _easy_
293
282
294
283
Besides overriding specific colors, you can create your own, named color scheme
295
284
by wrapping the definitions in the `#!css [data-md-color-scheme="..."]`
296
- [attribute selector][17 ], which you can then set via `mkdocs.yml` as described
297
- in the [color schemes][8 ] section :
285
+ [attribute selector][14 ], which you can then set via `mkdocs.yml` as described
286
+
62D8
in the [color schemes][7 ] section :
298
287
299
288
` ` ` css
300
289
[data-md-color-scheme="youtube"] {
@@ -314,4 +303,4 @@ can tune the `slate` theme with:
314
303
}
315
304
` ` `
316
305
317
- [17 ] : https://www.w3.org/TR/selectors-4/#attribute-selectors
306
+ [14 ] : https://www.w3.org/TR/selectors-4/#attribute-selectors
0 commit comments