Debian Codegraph @

docs/user-guide/choosing-your-theme.md

raw
1 # Choosing your Theme
2
3 Selecting and configuring a theme.
4
5 ---
6
7 MkDocs includes two built-in themes ([mkdocs](#mkdocs) and
8 [readthedocs](#readthedocs)), as documented below. However, many [third party
9 themes] are available to choose from as well.
10
11 To choose a theme, set the [theme] configuration option in your `mkdocs.yml`
12 config file.
13
14 ```yaml
15 theme:
16 name: readthedocs
17 ```
18
19 ## mkdocs
20
21 The default theme, which was built as a custom [Bootstrap] theme, supports almost
22 every feature of MkDocs.
23
24 <div id="mkdocs-theme-images" class="carousel slide carousel-fade" data-bs-ride="carousel">
25 <div class="carousel-inner">
26 <div class="carousel-item active">
27 <img src="../../img/mkdocs_theme_light_mode.png" class="d-block w-100" alt="MkDocs theme in light mode">
28 </div>
29 <div class="carousel-item">
30 <img src="../../img/mkdocs_theme_dark_mode.png" class="d-block w-100" alt="MkDocs theme in dark mode">
31 </div>
32 </div>
33 </div>
34
35 In addition to the default [theme configuration options][theme], the `mkdocs` theme
36 supports the following options:
37
38 * **`color_mode`**: Set the default color mode for the theme to one of `light`,
39 `dark`, or `auto`. The `auto` mode will switch to `light` or `dark` based on
40 the system configuration of the user's device. Default: `light`.
41
42 * **`user_color_mode_toggle`**: Enable a toggle menu in the navigation bar
43 which allows users to select their preferred `color_mode` (light, dark, auto)
44 from within the browser and save their preference for future page loads. The
45 default selection of the toggle menu on first page load is the value set to
46 `color_mode`. Default: `false`.
47
48 ![color mode toggle menu](../img/color_mode_toggle_menu.png)
49
50 * **`nav_style`**: Adjust the visual style of the top navigation bar. Set to
51 one of `primary`, `dark` or `light`. Default: `primary`. This option is
52 independent of the `color_mode` option and must be defined separately.
53
54 * **`highlightjs`**: Enables highlighting of source code in code blocks using
55 the [highlight.js] JavaScript library. Default: `True`.
56
57 * **`hljs_style`**: The highlight.js library provides many different [styles]
58 (color variations) for highlighting source code in code blocks. Set this to
59 the name of the desired style when in `light` mode. Default: `github`.
60
61 * **`hljs_style_dark`**: Set this to the name of the desired highlight.js
62 style when in `dark` mode. Default: `github_dark`.
63
64 * **`hljs_languages`**: By default, highlight.js only supports 23 common
65 languages. List additional languages here to include support for them.
66
67 ```yaml
68 theme:
69 name: mkdocs
70 highlightjs: true
71 hljs_languages:
72 - yaml
73 - rust
74 ```
75
76 * **`analytics`**: Defines configuration options for an analytics service.
77 Currently, only Google Analytics v4 is supported via the `gtag` option.
78
79 * **`gtag`**: To enable Google Analytics, set to a Google Analytics v4
80 tracking ID, which uses the `G-` format. See Google's documentation to
81 [Set up Analytics for a website and/or app (GA4)][setup-GA4] or to
82 [Upgrade to a Google Analytics 4 property][upgrade-GA4].
83
84 ```yaml
85 theme:
86 name: mkdocs
87 analytics:
88 gtag: G-ABC123
89 ```
90
91 When set to the default (`null`) Google Analytics is disabled for the
92 site.
93
94 * **`shortcuts`**: Defines keyboard shortcut keys.
95
96 ```yaml
97 theme:
98 name: mkdocs
99 shortcuts:
100 help: 191 # ?
101 next: 78 # n
102 previous: 80 # p
103 search: 83 # s
104 ```
105
106 All values must be numeric key codes. It is best to use keys that are
107 available on all keyboards. You may use <https://keycode.info/> to determine
108 the key code for a given key.
109
110 * **`help`**: Display a help modal that lists the keyboard shortcuts.
111 Default: `191` (&quest;)
112
113 * **`next`**: Navigate to the "next" page. Default: `78` (n)
114
115 * **`previous`**: Navigate to the "previous" page. Default: `80` (p)
116
117 * **`search`**: Display the search modal. Default: `83` (s)
118
119 * **`navigation_depth`**: The maximum depth of the navigation tree in the
120 sidebar. Default: `2`.
121
122 * **`locale`**{ #mkdocs-locale }: The locale (language/location) used to
123 build the theme. If your locale is not yet supported, it will fall back
124 to the default.
125
126 The following locales are supported by this theme:
127
128 * `en`: English (default)
129 * (see the list of existing directories `mkdocs/themes/mkdocs/locales/*/`)
130
131 See the guide on [localizing your theme] for more information.
132
133 ## readthedocs
134
135 A clone of the default theme used by the [Read the Docs] service, which offers
136 the same restricted feature set as its parent theme. Like its parent theme, only
137 two levels of navigation are supported.
138
139 ![ReadTheDocs](../img/readthedocs.png)
140
141 In addition to the default [theme configuration options][theme], the `readthedocs`
142 theme supports the following options:
143
144 * **`highlightjs`**: Enables highlighting of source code in code blocks using
145 the [highlight.js] JavaScript library. Default: `True`.
146
147 * **`hljs_languages`**: By default, highlight.js only supports 23 common
148 languages. List additional languages here to include support for them.
149
150 ```yaml
151 theme:
152 name: readthedocs
153 highlightjs: true
154 hljs_languages:
155 - yaml
156 - rust
157 ```
158
159 * **`analytics`**: Defines configuration options for an analytics service.
160
161 * **`gtag`**: To enable Google Analytics, set to a Google Analytics v4
162 tracking ID, which uses the `G-` format. See Google's documentation to
163 [Set up Analytics for a website and/or app (GA4)][setup-GA4] or to
164 [Upgrade to a Google Analytics 4 property][upgrade-GA4].
165
166 ```yaml
167 theme:
168 name: readthedocs
169 analytics:
170 gtag: G-ABC123
171 ```
172
173 When set to the default (`null`) Google Analytics is disabled for the
174
175 * **`anonymize_ip`**: To enable anonymous IP address for Google Analytics,
176 set this to `True`. Default: `False`.
177
178 * **`include_homepage_in_sidebar`**: Lists the homepage in the sidebar menu. As
179 MkDocs requires that the homepage be listed in the `nav` configuration
180 option, this setting allows the homepage to be included or excluded from
181 the sidebar. Note that the site name/logo always links to the homepage.
182 Default: `True`.
183
184 * **`prev_next_buttons_location`**: One of `bottom`, `top`, `both` , or `none`.
185 Displays the “Next” and “Previous” buttons accordingly. Default: `bottom`.
186
187 * **`navigation_depth`**: The maximum depth of the navigation tree in the
188 sidebar. Default: `4`.
189
190 * **`collapse_navigation`**: Only include the page section headers in the
191 sidebar for the current page. Default: `True`.
192
193 * **`titles_only`**: Only include page titles in the sidebar, excluding all
194 section headers for all pages. Default: `False`.
195
196 * **`sticky_navigation`**: If True, causes the sidebar to scroll with the main
197 page content as you scroll the page. Default: `True`.
198
199 * **`locale`**{ #readthedocs-locale }: The locale (language/location) used to
200 build the theme. If your locale is not yet supported, it will fall back
201 to the default.
202
203 The following locales are supported by this theme:
204
205 * `en`: English (default)
206 * (see the list of existing directories `mkdocs/themes/readthedocs/locales/*/`)
207
208 See the guide on [localizing your theme] for more information.
209
210 * **`logo`**: To set a logo on your project instead of the plain text
211 `site_name`, set this variable to be the location of your image. Default: `null`.
212
213 ## Third Party Themes
214
215 A list of third party themes can be found at the [community wiki] page and [the ranked catalog][catalog]. If you have created your own, please add them there.
216
217 WARNING: Installing an MkDocs theme means installing a Python package and executing any code that the author has put in there. So, exercise the usual caution; there's no attempt at sandboxing.
218
219 [third party themes]: #third-party-themes
220 [theme]: configuration.md#theme
221 [Bootstrap]: https://getbootstrap.com/
222 [highlight.js]: https://highlightjs.org/
223 [styles]: https://highlightjs.org/static/demo/
224 [setup-GA4]: https://support.google.com/analytics/answer/9304153?hl=en&ref_topic=9303319
225 [upgrade-GA4]: https://support.google.com/analytics/answer/9744165?hl=en&ref_topic=9303319
226 [Read the Docs]: https://readthedocs.org/
227 [community wiki]: https://github.com/mkdocs/mkdocs/wiki/MkDocs-Themes
228 [catalog]: https://github.com/mkdocs/catalog#-theming
229 [localizing your theme]: localizing-your-theme.md