Create Documentation Website with MkDocs
This guide will show you how to create a develop environment for a documentation website using MkDocs.
Problem
You want to create a documentation website with MkDocs for documenting projects, APIs, or any other content.
Background
MkDocs generates websites from markdown files and can be accessed locally for rapid development and deployed to a web server (ex: GitHub Pages). It prevents the need to write HTML, CSS, and JS, and let developer focuses on only the documentation.
Solution
Step 1. Setup MkDocs
- Install Python and pip.
- In Windows, download Python from Python official website.
- In Linux, use corresponding package manager to install Python. Following is an example for Debian-based systems.
- (optional, recommended) Create and activate a virtual environment.
- In Windows, open Command Prompt, PowerShell, or PowerShell 7 and run the following command. You need to replace
Python312
with your installed version, andcd
into your project directory before execution. - In Linux, open Terminal and run the following command. You need to replace
python3.12
with your installed version, andcd
into your project directory before execution.
- In Windows, open Command Prompt, PowerShell, or PowerShell 7 and run the following command. You need to replace
- Install MkDocs.
- (optional) Install MkDocs plugins like mkdocs-nav-weight
- Initialize MkDocs project.
- Serve website locally for development. You can access the website at
127.0.0.1:8000
with default settings in your browser. - After development, deploy your website to a web server.
After project initialized, you can edit mkdocs.yml
for configuration, and edit markdown files in docs
directory for content. Markdown files will be pages, directory with index.md
can hold subpages.
Step 2. Development Routine
- Serve website locally. You need to
cd
into your project directory before execution. - Edit markdown files in
docs
directory. MkDocs will automatically reload the website when files are modified.
Reference
- https://www.mkdocs.org/
- https://squidfunk.github.io/mkdocs-material/
- YouTube - James Willett - How to Create STUNNING Code Documentation With MkDocs Material Theme
Error Correction
If you find any mistakes in the document, please create an Issue or a Pull request or leave a message in Discussions or send me a mail directly with the mail icon at the bottom right. Thank you!