# Writing your docs How to layout and write your Markdown source files. --- ## File layout Your documentation source should be written as regular Markdown files (see [Writing with Markdown](#writing-with-markdown) below), and placed in the [documentation directory](configuration.md#docs_dir). By default, this directory will be named `docs` and will exist at the top level of your project, alongside the `mkdocs.yml` configuration file. The simplest project you can create will look something like this: ```text mkdocs.yml docs/ index.md ``` By convention your project homepage should be named `index.md` (see [Index pages](#index-pages) below for details). Any of the following file extensions may be used for your Markdown source files: `markdown`, `mdown`, `mkdn`, `mkd`, `md`. All Markdown files included in your documentation directory will be rendered in the built site regardless of any settings. NOTE: Files and directories with names which begin with a dot (for example: `.foo.md` or `.bar/baz.md`) are ignored by MkDocs. This can be overridden with the [`exclude_docs` config](configuration.md#exclude_docs). You can also create multi-page documentation, by creating several Markdown files: ```text mkdocs.yml docs/ index.md about.md license.md ``` The file layout you use determines the URLs that are used for the generated pages. Given the above layout, pages would be generated for the following URLs: ```text / /about/ /license/ ``` You can also include your Markdown files in nested directories if that better suits your documentation layout. ```text docs/ index.md user-guide/getting-started.md user-guide/configuration-options.md license.md ``` Source files inside nested directories will cause pages to be generated with nested URLs, like so: ```text / /user-guide/getting-started/ /user-guide/configuration-options/ /license/ ``` Any files which are not identified as Markdown files (by their file extension) within the [documentation directory](configuration.md#docs_dir) are copied by MkDocs to the built site unaltered. See [how to link to images and media](#linking-to-images-and-media) below for details. ### Index pages When a directory is requested, by default, most web servers will return an index file (usually named `index.html`) contained within that directory if one exists. For that reason, the homepage in all of the examples above has been named `index.md`, which MkDocs will render to `index.html` when building the site. Many repository hosting sites provide special treatment for README files by displaying the contents of the README file when browsing the contents of a directory. Therefore, MkDocs will allow you to name your index pages as `README.md` instead of `index.md`. In that way, when users are browsing your source code, the repository host can display the index page of that directory as it is a README file. However, when MkDocs renders your site, the file will be renamed to `index.html` so that the server will serve it as a proper index file. If both an `index.md` file and a `README.md` file are found in the same directory, then the `index.md` file is used and the `README.md` file is ignored. ### Configure Pages and Navigation The [nav](configuration.md#nav) configuration setting in your `mkdocs.yml` file defines which pages are included in the global site navigation menu as well as the structure of that menu. If not provided, the navigation will be automatically created by discovering all the Markdown files in the [documentation directory](configuration.md#docs_dir). An automatically created navigation configuration will always be sorted alphanumerically by file name (except that index files will always be listed first within a sub-section). You will need to manually define your navigation configuration if you would like your navigation menu sorted differently. A minimal navigation configuration could look like this: ```yaml nav: - index.md - about.md ``` All paths in the navigation configuration must be relative to the `docs_dir` configuration option. If that option is set to the default value, `docs`, the source files for the above configuration would be located at `docs/index.md` and `docs/about.md`. The above example will result in two navigation items being created at the top level and with their titles inferred from the contents of the Markdown file or, if no title is defined within the file, of the file name. To override the title in the `nav` setting add a title right before the filename. ```yaml nav: - Home: index.md - About: about.md ``` Note that if a title is defined for a page in the navigation, that title will be used throughout the site for that page and will override any title defined within the page itself. Navigation sub-sections can be created by listing related pages together under a section title. For example: ```yaml nav: - Home: index.md - User Guide: - Writing your docs: writing-your-docs.md - Styling your docs: styling-your-docs.md - About: - License: license.md - Release Notes: release-notes.md ``` With the above configuration we have three top level items: "Home", "User Guide" and "About." "Home" is a link to the homepage for the site. Under the "User Guide" section two pages are listed: "Writing your docs" and "Styling your docs." Under the "About" section two more pages are listed: "License" and "Release Notes." Note that a section cannot have a page assigned to it. Sections are only containers for child pages and sub-sections. You may nest sections as deeply as you like. However, be careful that you don't make it too difficult for your users to navigate through the site navigation by over-complicating the nesting. While sections may mirror your directory structure, they do not have to. Any pages not listed in your navigation configuration will still be rendered and included with the built site, however, they will not be linked from the global navigation and will not be included in the `previous` and `next` links. Such pages will be "hidden" unless linked to directly. ## Writing with Markdown MkDocs pages must be authored in [Markdown][md], a lightweight markup language which results in easy-to-read, easy-to-write plain text documents that can be converted to valid HTML documents in a predictable manner. MkDocs uses the [Python-Markdown] library to render Markdown documents to HTML. Python-Markdown is almost completely compliant with the [reference implementation][md], although there are a few very minor [differences]. In addition to the base Markdown [syntax] which is common across all Markdown implementations, MkDocs includes support for extending the Markdown syntax with Python-Markdown [extensions]. See the MkDocs' [markdown_extensions] configuration setting for details on how to enable extensions. MkDocs includes some extensions by default, which are highlighted below. [Python-Markdown]: https://python-markdown.github.io/ [md]: https://daringfireball.net/projects/markdown/ [differences]: https://python-markdown.github.io/#differences [syntax]: https://daringfireball.net/projects/markdown/syntax [extensions]: https://python-markdown.github.io/extensions/ [markdown_extensions]: configuration.md#markdown_extensions ### Internal links MkDocs allows you to interlink your documentation by using regular Markdown [links]. However, there are a few additional benefits to formatting those links specifically for MkDocs as outlined below. [links]: https://daringfireball.net/projects/markdown/syntax#link #### Linking to pages When linking between pages in the documentation you can simply use the regular Markdown [linking][links] syntax, including the *relative path* to the Markdown document you wish to link to. ```markdown Please see the [project license](license.md) for further details. ``` When the MkDocs build runs, these Markdown links will automatically be transformed into an HTML hyperlink to the appropriate HTML page. WARNING: Using absolute paths with links is not officially supported. Relative paths are adjusted by MkDocs to ensure they are always relative to the page. Absolute paths are not modified at all. This means that your links using absolute paths might work fine in your local environment but they might break once you deploy them to your production server. If the target documentation file is in another directory you'll need to make sure to include any relative directory path in the link. ```markdown Please see the [project license](../about/license.md) for further details. ``` The [toc] extension is used by MkDocs to generate an ID for every header in your Markdown documents. You can use that ID to link to a section within a target document by using an anchor link. The generated HTML will correctly transform the path portion of the link, and leave the anchor portion intact. ```markdown Please see the [project license](about.md#license) for further details. ``` Note that IDs are created from the text of a header. All text is converted to lowercase and any disallowed characters, including white-space, are converted to dashes. Consecutive dashes are then reduced to a single dash. There are a few configuration settings provided by the toc extension which you can set in your `mkdocs.yml` configuration file to alter the default behavior: * **`permalink`** Generate permanent links at the end of each header. Default: `False`. When set to True the paragraph symbol (¶ or `¶`) is used as the link text. When set to a string, the provided string is used as the link text. For example, to use the hash symbol (`#`) instead, do: ```yaml markdown_extensions: - toc: permalink: "#" ``` * **`baselevel`** Base level for headers. Default: `1`. This setting allows the header levels to be automatically adjusted to fit within the hierarchy of your HTML templates. For example, if the Markdown text for a page should not contain any headers higher than level 2 (`