--- template: overrides/main.html --- # Customization Project documentation is as diverse as the projects themselves and Material for MkDocs is a good starting point for making it look great. However, as you write your documentation, you may reach a point where some small adjustments are necessary to preserve your brand's style. ## Adding assets [MkDocs][1] provides several ways to customize a theme. In order to make a few tweaks to an existing theme, you can just add your stylesheets and JavaScript files to the `docs` directory. [1]: https://www.mkdocs.org ### Additional stylesheets If you want to tweak some colors or change the spacing of certain elements, you can do this in a separate stylesheet. The easiest way is by creating a new stylesheet file in the `docs` directory: ``` mkdir docs/stylesheets touch docs/stylesheets/extra.css ``` Then, add the following line to `mkdocs.yml`: ``` yaml extra_css: - stylesheets/extra.css ``` Spin up the [live preview server][2] and start typing your changes in your additional stylesheet file – you should see them almost instantly after saving. [2]: creating-your-site.md#previewing-as-you-write ### Additional JavaScript The same is true for additional JavaScript. If you want to integrate another syntax highlighter or add some custom logic to your theme, create a new JavaScript file in the `docs` directory: ``` mkdir docs/javascripts touch docs/javascripts/extra.js ``` Then, add the following line to `mkdocs.yml`: ``` yaml extra_javascript: - javascripts/extra.js ``` Further assistance can be found in the [MkDocs documentation][3]. [3]: https://www.mkdocs.org/user-guide/styling-your-docs/#customizing-a-theme ## Extending the theme If you want to alter the HTML source (e.g. add or remove some part), you can extend the theme. MkDocs supports [theme extension][4], an easy way to override parts of a theme without forking and changing the main theme. [4]: https://www.mkdocs.org/user-guide/styling-your-docs/#using-the-theme-custom_dir ### Setup and theme structure Reference the original theme as usual in `mkdocs.yml`, and create a new folder for `overrides` which you reference using `custom_dir`: ``` yaml theme: name: material custom_dir: overrides ``` !!! warning "Theme extension prerequisites" As the `custom_dir` variable is used for the theme extension process, Material for MkDocs needs to be installed via `pip` and referenced with the `name` parameter in `mkdocs.yml`. It will not work when cloning from `git`. The structure in the `overrides` directory must mirror the directory structure of the original theme, as any file in the `overrides` directory will replace the file with the same name which is part of the original theme. Besides, further assets may also be put in the `overrides` directory. The directory layout of the theme is as follows: ``` sh . ├─ .icons/ # Bundled icon sets ├─ assets/ │ ├─ images/ # Images and icons │ ├─ javascripts/ # JavaScript │ └─ stylesheets/ # Stylesheets ├─ partials/ │ ├─ integrations/ # Third-party integrations │ │ ├─ analytics.html # - Google Analytics │ │ └─ disqus.html # - Disqus │ ├─ language/ # Localized languages │ ├─ footer.html # Footer bar │ ├─ header.html # Header bar │ ├─ hero.html # Hero teaser │ ├─ language.html # Localized labels │ ├─ logo.html # Logo in header and sidebar │ ├─ nav.html # Main navigation │ ├─ nav-item.html # Main navigation item │ ├─ palette.html # Color palette │ ├─ search.html # Search box │ ├─ social.html # Social links │ ├─ source.html # Repository information │ ├─ source-date.html # Last updated date │ ├─ source-link.html # Link to source file │ ├─ tabs.html # Tabs navigation │ ├─ tabs-item.html # Tabs navigation item │ ├─ toc.html # Table of contents │ └─ toc-item.html # Table of contents item ├─ 404.html # 404 error page ├─ base.html # Base template └─ main.html # Default page ``` ### Overriding partials In order to override the footer, we can replace the `footer.html` partial with our own partial. To do this, create the file `partials/footer.html` in the `overrides` directory. MkDocs will now use the new partial when rendering the theme. This can be done with any file. ### Overriding blocks Besides overriding partials, it's also possible to override (and extend) so called _blocks_, which are defined inside the templates and wrap specific features. To override a block, create a `main.html` inside the `overrides` directory and define the block, e.g.: ``` html {% extends "base.html" %} {% block htmltitle %}