@@ -4,21 +4,22 @@ How to style and theme your documentation.
4
4
5
5
---
6
6
7
- MkDocs includes a number of different [ built-in themes] ( #built-in-themes ) and
8
- [ external themes] ( #bootstrap-and-bootswatch-themes ) which can easily be
9
- [ customised with extra CSS or JavaScript] ( #customising-a-theme ) or you can
10
- create a [ custom theme] ( /user-guide/custom-themes.md ) for your documentation.
7
+ MkDocs includes a couple [ built-in themes] as well as various [ third party
8
+ themes] , all of which can easily be customized with [ extra CSS or
9
+ JavaScript] [ docs_dir ] or overridden from the [ theme directory] [ theme_dir ] . You
10
+ can also create your own [ custom theme] from the grown up for your
11
+ documentation.
11
12
12
13
To use a theme that is included in MkDocs, simply add this to your
13
14
` mkdocs.yml ` config file.
14
15
15
16
theme: readthedocs
16
17
17
- Replace [ ` readthedocs ` ] ( #readthedocs ) with any of the [ built-in themes] (#built-
18
- in-themes) listed below.
18
+ Replace [ ` readthedocs ` ] ( #readthedocs ) with any of the [ built-in themes] listed below.
19
19
20
- To create a new custom theme or more heavily customise an existing theme, see
21
- the [ custom themes] ( #custom-themes ) section below.
20
+ To create a new custom theme see the [ Custom Themes] [ custom theme ] page, or to
21
+ more heavily customize an existing theme, see
22
+ the [ Customizing a Theme] [ customize ] section below.
22
23
23
24
## Built-in themes
24
25
@@ -32,13 +33,21 @@ the [custom themes](#custom-themes) section below.
32
33
33
34
### Third Party Themes
34
35
35
- Third party themes can be found in the MkDocs [ community wiki] (
36
- https://github.com/mkdocs/mkdocs/wiki/MkDocs-Themes ) .
36
+ A list of third party themes can be found in the MkDocs [ community wiki] . If you
37
+ have created your own, please feel free to add it to the list .
37
38
38
- ## Customising a Theme
39
+ ## Customizing a Theme
40
+
41
+ If you would like to make a few tweaks to an existing theme, there is no need to
42
+ create your own theme from scratch. For minor tweaks which only require some CSS
43
+ and/or JavaScript, you can use the [ docs_dir] . However, for more complex
44
+ customizations, including overriding templates, you will need to use the
45
+ [ theme_dir] .
46
+
47
+ ### Using the docs_dir
39
48
40
49
The [ extra_css] and [ extra_javascript] configuration options can be used to
41
- make tweaks and customisations to existing themes. To use these, you simply
50
+ make tweaks and customizations to existing themes. To use these, you simply
42
51
need to include either CSS or JavaScript files within your [ documentation
43
52
directory] .
44
53
@@ -64,7 +73,98 @@ After making these changes, they should be visible when you run
64
73
` mkdocs serve ` - if you already had this running, you should see that the CSS
65
74
changes were automatically picked up and the documentation will be updated.
66
75
76
+ !!! note
77
+
78
+ Any extra CSS or JavaScript files will be added to the generated HTML
79
+ document after the page content. If you desire to include a JavaScript
80
+ library, you may have better sucess including the library by using the
81
+ [theme_dir].
82
+
83
+ ### Using the theme_dir
84
+
85
+ The [ theme_dir] configuration option can be used to point to a directory of
86
+ files which override the files in the theme set on the [ theme] configuration
87
+ option. Any file in the ` theme_dir ` with the same name as a file in the ` theme `
88
+ will replace the file of the same name in the ` theme ` . Any additional files in
89
+ the ` theme_dir ` will be added to the ` theme ` . The contents of the ` theme_dir `
90
+ should mirror the directory structure of the ` theme ` . You may include templates,
91
+ JavaScript files, CSS files, images, fonts, or any other media included in a
92
+ theme.
93
+
94
+ For example, the [ mkdocs] theme ([ browse source] ), contains the following
95
+ directory structure (in part):
96
+
97
+ ``` nohighlight
98
+ - css\
99
+ - fonts\
100
+ - img\
101
+ - favicon.ico
102
+ - grid.png
103
+ - js\
104
+ - 404.html
105
+ - base.html
106
+ - content.html
107
+ - nav-sub.html
108
+ - nav.html
109
+ - toc.html
110
+ ```
111
+
112
+ To override any of the files contained in that theme, create a new directory
113
+ next to your ` docs_dir ` :
114
+
115
+ ``` bash
116
+ mkdir custom_theme
117
+ ```
118
+
119
+ And then point your ` mkdocs.yml ` configuration file at the new directory:
120
+
121
+ ``` yaml
122
+ theme_dir : custom_theme
123
+ ` ` `
124
+
125
+ To override the 404 error page ("file not found"), add a new template file named
126
+ ` 404.html` to the `custom_theme` directory. For information on what can be
127
+ included in a template, review the documentation for building a [custom theme].
128
+
129
+ To override the favicon, you can add a new icon file at
130
+ ` custom_theme/img/favicon.ico` .
131
+
132
+ To include a JavaScript library, copy the library to the `custom_theme/js/`
133
+ directory.
134
+
135
+ Your directory structure should now look like this :
136
+
137
+ ` ` ` nohighlight
138
+ - docs/
139
+ - index.html
140
+ - custom_theme/
141
+ - img/
142
+ - favicon.ico
143
+ - js/
144
+ - somelib.js
145
+ - 404.html
146
+ - config.yml
147
+ ` ` `
148
+
149
+ !!! Note
150
+
151
+ Any files included in the `theme` but not included in the `theme_dir` will
152
+ still be utilized. The `theme_dir` will only override/replace files in the
153
+ ` theme` . If you want to remove files, or build a theme from scratch, then
154
+ you should review the documentation for building a [custom theme].
155
+
156
+ [built-in themes] : # built-in-themes
157
+ [third party themes] : # third-party-themes
158
+ [docs_dir] : # using-the-docs_dir
159
+ [theme_dir] : # using-the-theme_dir
160
+ [customize] : # customizing-a-theme
161
+ [custom theme] : ./custom-themes.md
67
162
[ReadTheDocs] : ./deploying-your-docs.md#readthedocs
68
- [ documentation directory ] : /user-guide/configuration/#docs_dir
69
- [ extra_css ] : /user-guide/configuration.md#extra_css
70
- [ extra_javascript ] : /user-guide/configuration.md#extra_javascript
163
+ [community wiki] : https://github.com/mkdocs/mkdocs/wiki/MkDocs-Themes
164
+ [documentation directory] : ./configuration/#docs_dir
165
+ [extra_css] : ./configuration.md#extra_css
166
+ [extra_javascript] : ./configuration.md#extra_javascript
167
+ [theme_dir] : ./configuration/#theme_dir
168
+ [theme] : ./configuration/#theme
169
+ [mkdocs] : # mkdocs
170
+ [browse source] : https://github.com/mkdocs/mkdocs/tree/master/mkdocs/themes/mkdocs
0 commit comments