Getting Started with MkDocs
An introductory tutorial!
To install MkDocs, run the following command from the command line:
pip install mkdocs
For more details, see the Installation Guide.
Creating a new project
Getting started is super easy. To create a new project, run the following command from the command line:
mkdocs new my-project cd my-project
Take a moment to review the initial project that has been created for you.
There’s a single configuration file named
mkdocs.yml, and a folder named
docs that will contain your documentation source files (
the default value for the docs_dir configuration setting). Right now the
folder just contains a single documentation page, named
MkDocs comes with a built-in dev-server that lets you preview your documentation
as you work on it. Make sure you’re in the same directory as the
configuration file, and then start the server by running the
$ mkdocs serve INFO - Building documentation... INFO - Cleaning site directory [I 160402 15:50:43 server:271] Serving on http://127.0.0.1:8000 [I 160402 15:50:43 handlers:58] Start watching changes [I 160402 15:50:43 handlers:60] Start detecting changes
http://127.0.0.1:8000/ in your browser, and you’ll see the default
home page being displayed:
The dev-server also supports auto-reloading, and will rebuild your documentation whenever anything in the configuration file, documentation directory, or theme directory changes.
docs/index.md document in your text editor of choice, change the
initial heading to
MkLorum, and save your changes. Your browser will
auto-reload and you should see your updated documentation immediately.
Now try editing the configuration file:
mkdocs.yml. Change the
site_name setting to
MkLorum and save the file.
site_name: MkLorum site_url: https://example.com/
Your browser should immediately reload, and you’ll see your new site name take effect.
The [`site_name`][site_name] and [`site_url`][site_url] configuration options are the only two required options in your configuration file. When you create a new project, the `site_url` option is assigned the placeholder value: `https://example.com`. If the final location is known, you can change the setting now to point to it. Or you may choose to leave it alone for now. Just be sure to edit it before you deploy your site to a production server.
Now add a second page to your documentation:
curl 'https://jaspervdj.be/lorem-markdownum/markdown.txt' > docs/about.md
As our documentation site will include some navigation headers, you may want to
edit the configuration file and add some information about the order, title, and
nesting of each page in the navigation header by adding a
site_name: MkLorum site_url: https://example.com/ nav: - Home: index.md - About: about.md
Save your changes and you’ll now see a navigation bar with
items on the left as well as
Next items on the
Try the menu items and navigate back and forth between pages. Then click on
Search. A search dialog will appear, allowing you to search for any text on
any page. Notice that the search results include every occurrence of the search
term on the site and links directly to the section of the page in which the
search term appears. You get all of that with no effort or configuration on your
Theming our documentation
Now change the configuration file to alter how the documentation is displayed by
changing the theme. Edit the
mkdocs.yml file and add a
site_name: MkLorum site_url: https://example.com/ nav: - Home: index.md - About: about.md theme: readthedocs
Save your changes, and you’ll see the ReadTheDocs theme being used.
Changing the Favicon Icon
By default, MkDocs uses the MkDocs favicon icon. To use a different icon, create
img subdirectory in the
docs directory and copy your custom
file to that directory. MkDocs will automatically detect and use that file as your
Building the site
That’s looking good. You’re ready to deploy the first pass of your
documentation. First build the documentation:
This will create a new directory, named
site. Take a look inside the
$ ls site about fonts index.html license search.html css img js mkdocs sitemap.xml
Notice that your source documentation has been output as two HTML files named
about/index.html. You also have various other media that’s
been copied into the
site directory as part of the documentation theme. You
even have a
sitemap.xml file and
If you’re using source code control such as
git you probably don’t want to
check your documentation builds into the repository. Add a line containing
site/ to your
echo "site/" >> .gitignore
If you’re using another source code control tool you’ll want to check its documentation on how to ignore specific directories.
Other Commands and Options
There are various other commands and options available. For a complete list of
commands, use the
To view a list of options available on a given command, use the
with that command. For example, to get a list of all options available for the
build command run the following:
mkdocs build --help
The documentation site that you just built only uses static files so you’ll be
able to host it from pretty much anywhere. Simply upload the contents of the
site directory to wherever you’re hosting your website from and
you’re done. For specific instructions on a number of common hosts, see the
Deploying your Docs page.
See the User Guide for more complete documentation of all of MkDocs’ features.