| 1 |
# Theme |
| 2 |
|
| 3 |
The default renderer uses a [handlebars](https://handlebarsjs.com) template to |
| 4 |
render your markdown files and comes with a default theme included in the mdBook |
| 5 |
binary. |
| 6 |
|
| 7 |
The theme is totally customizable, you can selectively replace every file from |
| 8 |
the theme by your own by adding a `theme` directory next to `src` folder in your |
| 9 |
project root. Create a new file with the name of the file you want to override |
| 10 |
and now that file will be used instead of the default file. |
| 11 |
|
| 12 |
Here are the files you can override: |
| 13 |
|
| 14 |
- **_index.hbs_** is the handlebars template. |
| 15 |
- **_head.hbs_** is appended to the HTML `<head>` section. |
| 16 |
- **_header.hbs_** content is appended on top of every book page. |
| 17 |
- **_css/_** contains the CSS files for styling the book. |
| 18 |
- **_css/chrome.css_** is for UI elements. |
| 19 |
- **_css/general.css_** is the base styles. |
| 20 |
- **_css/print.css_** is the style for printer output. |
| 21 |
- **_css/variables.css_** contains variables used in other CSS files. |
| 22 |
- **_book.js_** is mostly used to add client side functionality, like hiding / |
| 23 |
un-hiding the sidebar, changing the theme, ... |
| 24 |
- **_highlight.js_** is the JavaScript that is used to highlight code snippets, |
| 25 |
you should not need to modify this. |
| 26 |
- **_highlight.css_** is the theme used for the code highlighting. |
| 27 |
- **_favicon.svg_** and **_favicon.png_** the favicon that will be used. The SVG |
| 28 |
version is used by [newer browsers]. |
| 29 |
- **fonts/fonts.css** contains the definition of which fonts to load. |
| 30 |
Custom fonts can be included in the `fonts` directory. |
| 31 |
|
| 32 |
Generally, when you want to tweak the theme, you don't need to override all the |
| 33 |
files. If you only need changes in the stylesheet, there is no point in |
| 34 |
overriding all the other files. Because custom files take precedence over |
| 35 |
built-in ones, they will not get updated with new fixes / features. |
| 36 |
|
| 37 |
**Note:** When you override a file, it is possible that you break some |
| 38 |
functionality. Therefore I recommend to use the file from the default theme as |
| 39 |
template and only add / modify what you need. You can copy the default theme |
| 40 |
into your source directory automatically by using `mdbook init --theme` and just |
| 41 |
remove the files you don't want to override. |
| 42 |
|
| 43 |
`mdbook init --theme` will not create every file listed above. |
| 44 |
Some files, such as `head.hbs`, do not have built-in equivalents. |
| 45 |
Just create the file if you need it. |
| 46 |
|
| 47 |
If you completely replace all built-in themes, be sure to also set |
| 48 |
[`output.html.preferred-dark-theme`] in the config, which defaults to the |
| 49 |
built-in `navy` theme. |
| 50 |
|
| 51 |
[`output.html.preferred-dark-theme`]: ../configuration/renderers.md#html-renderer-options |
| 52 |
[newer browsers]: https://caniuse.com/#feat=link-icon-svg |