MkDocs Setup Summary
What is MkDocs?
MkDocs is a static site generator that converts Markdown files into a documentation website. It uses a YAML configuration file (mkdocs.yml) and outputs plain HTML/CSS/JS.
Setup Workflow (Mac)
1. Create Virtual Environment
2. Install MkDocs
3. Initialize Project
This creates:
- mkdocs.yml — configuration file (lives in project root)
- docs/ — folder for Markdown source files
4. Preview Locally
Visithttp://127.0.0.1:8000 — includes live reload for most changes.
5. Build Static Site
Outputs tosite/ folder for deployment.
Basic Configuration (mkdocs.yml)
site_name: My Documentation
docs_dir: docs
site_dir: site
theme:
name: material
palette:
primary: teal
accent: orange
font:
text: Roboto
code: Roboto Mono
nav:
- Home: index.md
- Getting Started: getting-started.md
- Reference: reference.md
Available Theme Colors
Primary colors: red, pink, purple, deep purple, indigo, blue, light blue, cyan, teal, green, light green, lime, yellow, amber, orange, deep orange, brown, grey, blue grey, black, white
Accent colors: red, pink, purple, deep purple, indigo, blue, light blue, cyan, teal, green, light green, lime, yellow, amber, orange, deep orange
Schemes:
- default — light mode
- slate — dark mode
Dark/Light Toggle
theme:
name: material
palette:
- scheme: default
primary: blue
toggle:
icon: material/brightness-7
name: Switch to dark mode
- scheme: slate
primary: blue
toggle:
icon: material/brightness-4
name: Switch to light mode
Custom Hex Colors
In docs/stylesheets/extra.css:
Markdown Basics
Headers
Text Formatting
Links and Images
Lists
Code Blocks
Tables
Blockquotes
Converting HTML to Markdown
Using Pandoc (recommended)
Online Tools
- codebeautify.org/html-to-markdown
- markdownify.net
After Conversion
Issues and Resolutions
| Issue | Cause | Resolution |
|---|---|---|
config file 'mkdocs.yml' does not exist |
Project not initialized | Run mkdocs new . before mkdocs serve |
| YAML nav changes not showing in browser | Live reload doesn't always catch YAML changes | Manually refresh browser or restart server with Ctrl+C then mkdocs serve |
pandoc: command not found after pip install |
pip installs Python wrapper, not the binary | Install via Homebrew: brew install pandoc |
| Virtual environment commands not working | Wrong OS syntax | Mac/Linux: source mkdocs-env/bin/activate / Windows: mkdocs-env\Scripts\activate |
Key Commands Reference
| Command | Purpose |
|---|---|
python -m venv mkdocs-env |
Create virtual environment |
source mkdocs-env/bin/activate |
Activate venv (Mac/Linux) |
deactivate |
Exit virtual environment |
pip install mkdocs mkdocs-material |
Install MkDocs |
mkdocs new . |
Initialize project in current directory |
mkdocs serve |
Run local dev server with live reload |
mkdocs build |
Generate static site to site/ folder |
Project Structure
your-project/
├── mkdocs.yml # config file
├── docs/ # markdown source
│ ├── index.md
│ ├── stylesheets/
│ │ └── extra.css
│ └── images/
└── site/ # generated output (after build)
Tips
- Run
mkdocs new .in the project root, not inpublic/ordocs/ - The virtual environment only affects where packages install — files are created in your actual project directory
mkdocs serveis for development preview;mkdocs buildcreates files for deployment- You can embed raw HTML inside Markdown files if needed
- Any Google Font can be used in the
font:config