This is a Draft for reference MkDocs
This page was Created: 2024-08-16
This page was last updated: 2024-11-28
Hello, I'm Opeyemi Okuboyejo
MarkDown Basic Syntax¶
Image Handling¶
Watch this YouTube Video
Nice Video
Embed a YouTube Video on page¶
This is image positioning¶
Centred image with caption and alt text
Centred image with caption and alt text
Clickable Centred image with caption and alt text
Usage¶
Image alignment¶
When Attribute Lists is enabled, images can be aligned by adding the
respective alignment directions via the align
attribute, i.e. align=left
or
align=right
:
Image, aligned to left | |
---|---|
Image, aligned to right | |
---|---|
If there's insufficient space to render the text next to the image, the image will stretch to the full width of the viewport, e.g. on mobile viewports.
Why is there no centered alignment?
The align
attribute doesn't allow for centered alignment, which
is why this option is not supported by Material for MkDocs.1 Instead,
the image captions syntax can be used, as captions are optional.
Image captions¶
Sadly, the Markdown syntax doesn't provide native support for image captions,
but it's always possible to use the [Markdown in HTML] extension with literal
figure
and figcaption
tags:
Image with caption | |
---|---|
Image lazy-loading¶
Modern browsers provide native support for lazy-loading images
through the loading=lazy
directive, which degrades to eager-loading in
browsers without support:
Image, lazy-loaded | |
---|---|
Warning
This is a warning block
Warning
This is a warning block expanded by default
Attention
This is an attention block
Info
This is an attention block
Console
This is an attention block
Integrate with site navigation
Add the following to your mkdocs.yml
to see how the Blog plugin can
integrate the blog navigation with the overall navigation structure.
Note that the only thing you need to specify at this point is the
index page for the blog and its path must match the blog_dir
setting,
which is blog
by default:
You will notice that "Blog" is duplicated in the navigation structure. To
avoid this, you can use the navigation.indexes
feature to make the blog
index the seciton index page for the blog:
Stand-alone blog
If what you need is a stand-alone blog instead of one that is integrated with
a larger site, this can be done by using the blog_dir
configuration option.
To see how this is done, see setting up a blog.
The rest of the tutorial assumes that you are integrating the blog with
a wider site.
Adding pages
You can add additional pages to the blog section by putting them into
docs/blog
(and adding them to the navigation). The blog archive will be
added to the navigation after these pages.
How to visualize the collected feedback ratings?
To visualize feedback ratings you'll need to create a custom report with [Google Analytics] that will quickly show you the worst- and best-rated pages of your project documentation.
-
Go to your Google Analytics dashboard
-
Go to the configure page on the left hand menu, then select custom definitions
-
Click the custom metrics tab and then create custom metrics, enter the following values:
- Metric name: Page helpful
- Description: Was this page helpful?
- Event parameter:
data
- Unit of measurement: Standard
-
Go to the explore page on the left hand menu, create a new blank exploration
-
Configure the report as follows:
- Dimensions: Add
Event name
andPage location
- Metrics: Add
Event count
andPage helpful
(the custom metric created in step 3) - Rows:
Page location
- Values: Drag in both
Event count
andPage helpful
- Filters: Add a new filter for
Event name / exactly matches / feedback
- Dimensions: Add
Delay in data availability
The report may take 24 hours or longer to begin displaying data
Now, after you've saved the report and collected some feedback ratings, you'll have a list of all pages with the total number of ratings, and an average rating per page. This should help you identify pages that need to be improved:
Google Analytics 4 does not support average values
To our knowledge, Google Analytics 4 has currently no feature that allows to define a custom calculated metric to compute the average rating of a page. See #5740.
[![feedback report]][feedback report]
Getting started¶
Material for MkDocs is a powerful documentation framework on top of MkDocs,
a static site generator for project documentation.1 If you're familiar with
Python, you can install Material for MkDocs with pip
, the Python
package manager. If not, we recommend using docker
.
Installation¶
with pip recommended¶
Material for MkDocs is published as a Python package and can be installed with
pip
, ideally by using a virtual environment. Open up a terminal and install
Material for MkDocs with:
-
Material for MkDocs uses semantic versioning2, which is why it's a good idea to limit upgrades to the current major version.
This will make sure that you don't accidentally upgrade to the next major version, which may include breaking changes that silently corrupt your site. Additionally, you can use
pip freeze
to create a lockfile, so builds are reproducible at all times:Now, the lockfile can be used for installation:
This will automatically install compatible versions of all dependencies: MkDocs, Markdown, Pygments and Python Markdown Extensions. Material for MkDocs always strives to support the latest versions, so there's no need to install those packages separately.
How to set up Material for MkDocs by @james-willett – 15m – Learn how to create and host a documentation site using Material for MkDocs on GitHub Pages in a step-by-step guide.
Tip
If you don't have prior experience with Python, we recommend reading Using Python's pip to Manage Your Projects' Dependencies, which is a really good introduction on the mechanics of Python package management and helps you troubleshoot if you run into errors.
with docker¶
The official Docker image is a great way to get up and running in a few minutes, as it comes with all dependencies pre-installed. Open up a terminal and pull the image with:
The mkdocs
executable is provided as an entry point and serve
is the
default command. If you're not familiar with Docker don't worry, we have you
covered in the following sections.
The following plugins are bundled with the Docker image:
Green Bar colapsed
this is sample text
How to add plugins to the Docker image?
Material for MkDocs only bundles selected plugins in order to keep the size of the official image small. If the plugin you want to use is not included, you can add them easily:
Create a Dockerfile
and extend the official image:
Next, build the image with the following command:
The new image will have additional packages installed and can be used exactly like the official image.
with git¶
Material for MkDocs can be directly used from GitHub by cloning the repository into a subfolder of your project root which might be useful if you want to use the very latest version:
Next, install the theme and its dependencies with:
icon: simple/terraform¶
Terraform Page¶
Terraform AWS¶
This is page 2 contents
This is an annotation (1)
Lorem ipsum dolor sit amet, (2) consectetur adipiscing elit. Nulla et euismod nulla. Curabitur feugiat, tortor non consequat finibus, justo purus auctor massa, nec semper lorem quam in massa.
- I'm an annotation!
- I'm an annotation as well!
Code Annotation Examples¶
Codeblocks¶
Some code
goes here.
Plain codeblock¶
A plain codeblock:
Code for a specific language¶
Some more code with the py
at the start:
With a title¶
bubble_sort.py | |
---|---|
With line numbers¶
Annotated Text¶
This is annotated text (1) Click the annotation to see more details
{ .annotate}
1. ### This text has been annotated as you can see
2. This is line 2 of the annotation def myfunction()
3.
``` tf
resource "aws_instance" "Server" {
ami = "ami-0b8b44ec9a8f90422"
instance_type = var.instance_type
# key_name = "OpeyemiTechPro-KeyPair.ppk" user_data = file("./userdata.sh")
key_name = var.key_pair_name
tags = { Name = "Server" } }
Icons and Emojis¶
icon: material/button-cursor¶
Buttons¶
Material for MkDocs provides dedicated styles for primary and secondary buttons
that can be added to any link, label
or button
element. This is especially
useful for documents or landing pages with dedicated call-to-actions.
Configuration¶
This configuration allows to add attributes to all inline- and block-level
elements with a simple syntax, turning any link into a button. Add the
following lines to mkdocs.yml
:
See additional configuration options:
Usage¶
Adding buttons¶
In order to render a link as a button, suffix it with curly braces and add the
.md-button
class selector to it. The button will receive the selected
primary color and accent color if active.
Button | |
---|---|
Adding primary buttons¶
If you want to display a filled, primary button (like on the landing page
of Material for MkDocs), add both, the .md-button
and .md-button--primary
CSS class selectors.
Button, primary | |
---|---|
Adding icon buttons¶
Of course, icons can be added to all types of buttons by using the icon syntax together with any valid icon shortcode, which can be easily found with a few keystrokes through our icon search.
Button with icon | |
---|---|
icon: simple/amazonwebservices¶
AWS Projects¶
Warning
This is a warning block
Attention
This is an attention block
Integrate with site navigation
Add the following to your mkdocs.yml
to see how the Blog plugin can
integrate the blog navigation with the overall navigation structure.
Note that the only thing you need to specify at this point is the
index page for the blog and its path must match the blog_dir
setting,
which is blog
by default:
You will notice that "Blog" is duplicated in the navigation structure. To
avoid this, you can use the navigation.indexes
feature to make the blog
index the seciton index page for the blog:
Stand-alone blog
If what you need is a stand-alone blog instead of one that is integrated with
a larger site, this can be done by using the blog_dir
configuration option.
To see how this is done, see setting up a blog.
The rest of the tutorial assumes that you are integrating the blog with
a wider site.
Adding pages
You can add additional pages to the blog section by putting them into
docs/blog
(and adding them to the navigation). The blog archive will be
added to the navigation after these pages.
Changing the colors¶
As any proper Material Design implementation, Material for MkDocs supports
Google's original color palette, which can be easily configured through
mkdocs.yml
. Furthermore, colors can be customized with a few lines of CSS to
fit your brand's identity by using CSS variables.
Configuration¶
Color palette¶
Color scheme¶
Material for MkDocs supports two color schemes: a light mode, which is just
called default
, and a dark mode, which is called slate
. The color scheme
can be set via mkdocs.yml
:
Click on a tile to change the color scheme:
Primary color¶
The primary color is used for the header, the sidebar, text links and several
other components. In order to change the primary color, set the following value
in mkdocs.yml
to a valid color name:
Click on a tile to change the primary color:
See our guide below to learn how to set custom colors.
Accent color¶
The accent color is used to denote elements that can be interacted with, e.g.
hovered links, buttons and scrollbars. It can be changed in mkdocs.yml
by
choosing a valid color name:
Click on a tile to change the accent color:
See our guide below to learn how to set custom colors.
Color palette toggle¶
Offering a light and dark color palette makes your documentation pleasant to
read at different times of the day, so the user can choose accordingly. Add the
following lines to mkdocs.yml
:
-
Note that the
theme.palette
setting is now defined as a list. -
Enter a few keywords to find the perfect icon using our icon search and click on the shortcode to copy it to your clipboard:
This configuration will render a color palette toggle next to the search bar.
Note that you can also define separate settings for primary
and accent
per color palette.
The following properties must be set for each toggle:
-
This property must point to a valid icon path referencing any icon bundled with the theme, or the build will not succeed. Some popular combinations:
- + –
material/brightness-7
+material/brightness-4
- + –
material/toggle-switch
+material/toggle-switch-off-outline
- + –
material/weather-night
+material/weather-sunny
- + –
material/eye
+material/eye-outline
- + –
material/lightbulb
+material/lightbulb-outline
- + –
-
This property is used as the toggle's
title
attribute and should be set to a discernable name to improve accessibility. It's rendered as a tooltip.
System preference¶
Each color palette can be linked to the user's system preference for light and
dark appearance by using a media query. Simply add a media
property next to
the scheme
definition in mkdocs.yml
:
When the user first visits your site, the media queries are evaluated in the order of their definition. The first media query that matches selects the default color palette.
Automatic light / dark mode¶
Newer operating systems allow to automatically switch between light and dark
appearance during day and night times. Material for MkDocs adds support for
automatic light / dark mode, delegating color palette selection to the user's
operating system. Add the following lines to mkdocs.yml
:
- You can also define separate settings for
primary
andaccent
per color palette, i.e. different colors for light and dark mode.
Material for MkDocs will now change the color palette each time the operating system switches between light and dark appearance, even when the user doesn't reload the site.
Customization¶
Custom colors¶
Material for MkDocs implements colors using CSS variables (custom properties). If you want to customize the colors beyond the palette (e.g. to use your brand-specific colors), you can add an additional style sheet and tweak the values of the CSS variables.
First, set the primary
or accent
values
in mkdocs.yml
to custom
, to signal to the theme that you want to define
custom colors, e.g., when you want to override the primary
color:
Let's say you're YouTube, and want to set the primary color to your brand's palette. Just add:
See the file containing the color definitions for a list of all CSS variables.
Custom color schemes¶
Besides overriding specific colors, you can create your own, named color scheme
by wrapping the definitions in a [data-md-color-scheme="..."]
attribute selector, which you can then set via mkdocs.yml
as described
in the color schemes section:
Additionally, the slate
color scheme defines all of it's colors via hsla
color functions and deduces its colors from the --md-hue
CSS variable. You
can tune the slate
theme with:
- The
hue
value must be in the range of[0, 360]
icon: material/alert-outline¶
Admonitions¶
Admonitions, also known as call-outs, are an excellent choice for including side content without significantly interrupting the document flow. Material for MkDocs provides several different types of admonitions and allows for the inclusion and nesting of arbitrary content.
Configuration¶
This configuration enables admonitions, allows to make them collapsible and to
nest arbitrary content inside admonitions. Add the following lines to
mkdocs.yml
:
See additional configuration options:
Admonition icons¶
Each of the supported admonition types has a distinct icon, which can be changed
to any icon bundled with the theme, or even a custom icon. Add the following
lines to mkdocs.yml
:
-
Enter a few keywords to find the perfect icon using our icon search and click on the shortcode to copy it to your clipboard:
Expand to show alternate icon sets
Usage¶
Admonitions follow a simple syntax: a block starts with !!!
, followed by a
single keyword used as a type qualifier. The content of the block follows on
the next line, indented by four spaces:
Admonition | |
---|---|
Note
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla et euismod nulla. Curabitur feugiat, tortor non consequat finibus, justo purus auctor massa, nec semper lorem quam in massa.
Changing the title¶
By default, the title will equal the type qualifier in titlecase. However, it can be changed by adding a quoted string containing valid Markdown (including links, formatting, ...) after the type qualifier:
Admonition with custom title | |
---|---|
Phasellus posuere in sem ut cursus
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla et euismod nulla. Curabitur feugiat, tortor non consequat finibus, justo purus auctor massa, nec semper lorem quam in massa.
Removing the title¶
Similar to changing the title, the icon and title can be omitted entirely by adding an empty string directly after the type qualifier. Note that this will not work for collapsible blocks:
Admonition without title | |
---|---|
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla et euismod nulla. Curabitur feugiat, tortor non consequat finibus, justo purus auctor massa, nec semper lorem quam in massa.
Collapsible blocks¶
When Details is enabled and an admonition block is started with ???
instead
of !!!
, the admonition is rendered as a collapsible block with a small toggle
on the right side:
Admonition, collapsible | |
---|---|
Note
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla et euismod nulla. Curabitur feugiat, tortor non consequat finibus, justo purus auctor massa, nec semper lorem quam in massa.
Adding a +
after the ???
token renders the block expanded:
Admonition, collapsible and initially expanded | |
---|---|
Note
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla et euismod nulla. Curabitur feugiat, tortor non consequat finibus, justo purus auctor massa, nec semper lorem quam in massa.
Inline blocks¶
Admonitions can also be rendered as inline blocks (e.g., for sidebars), placing
them to the right using the inline
+ end
modifiers, or to the left using
only the inline
modifier:
Lorem ipsum
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla et euismod nulla. Curabitur feugiat, tortor non consequat finibus, justo purus auctor massa, nec semper lorem quam in massa.
Use inline end
to align to the right (left for rtl languages).
Lorem ipsum
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla et euismod nulla. Curabitur feugiat, tortor non consequat finibus, justo purus auctor massa, nec semper lorem quam in massa.
Use inline
to align to the left (right for rtl languages).
Important: admonitions that use the inline
modifiers must be declared
prior to the content block you want to place them beside. If there's
insufficient space to render the admonition next to the block, the admonition
will stretch to the full width of the viewport, e.g., on mobile viewports.
Supported types¶
Following is a list of type qualifiers provided by Material for MkDocs, whereas
the default type, and thus fallback for unknown type qualifiers, is note
1:
-
Note
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla et euismod nulla. Curabitur feugiat, tortor non consequat finibus, justo purus auctor massa, nec semper lorem quam in massa.
-
Abstract
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla et euismod nulla. Curabitur feugiat, tortor non consequat finibus, justo purus auctor massa, nec semper lorem quam in massa.
-
Info
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla et euismod nulla. Curabitur feugiat, tortor non consequat finibus, justo purus auctor massa, nec semper lorem quam in massa.
-
Tip
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla et euismod nulla. Curabitur feugiat, tortor non consequat finibus, justo purus auctor massa, nec semper lorem quam in massa.
-
Success
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla et euismod nulla. Curabitur feugiat, tortor non consequat finibus, justo purus auctor massa, nec semper lorem quam in massa.
-
Question
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla et euismod nulla. Curabitur feugiat, tortor non consequat finibus, justo purus auctor massa, nec semper lorem quam in massa.
-
Warning
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla et euismod nulla. Curabitur feugiat, tortor non consequat finibus, justo purus auctor massa, nec semper lorem quam in massa.
-
Failure
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla et euismod nulla. Curabitur feugiat, tortor non consequat finibus, justo purus auctor massa, nec semper lorem quam in massa.
-
Danger
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla et euismod nulla. Curabitur feugiat, tortor non consequat finibus, justo purus auctor massa, nec semper lorem quam in massa.
-
Bug
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla et euismod nulla. Curabitur feugiat, tortor non consequat finibus, justo purus auctor massa, nec semper lorem quam in massa.
-
Example
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla et euismod nulla. Curabitur feugiat, tortor non consequat finibus, justo purus auctor massa, nec semper lorem quam in massa.
-
Quote
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla et euismod nulla. Curabitur feugiat, tortor non consequat finibus, justo purus auctor massa, nec semper lorem quam in massa.
Customization¶
Classic admonitions¶
Prior to version , admonitions had a slightly different appearance:
Note
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla et euismod nulla. Curabitur feugiat, tortor non consequat finibus, justo purus auctor massa, nec semper lorem quam in massa.
If you want to restore this appearance, add the following CSS to an additional style sheet:
Custom admonitions¶
If you want to add a custom admonition type, all you need is a color and an
*.svg
icon. Copy the icon's code from the .icons
folder
and add the following CSS to an additional style sheet:
After applying the customization, you can use the custom admonition type:
Admonition with custom type | |
---|---|
Pied Piper
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla et euismod nulla. Curabitur feugiat, tortor non consequat finibus, justo purus auctor massa, nec semper lorem quam in massa.
-
Previously, some of the supported types defined more than one qualifier. For example, authors could use
summary
ortldr
as alternative qualifiers to render anabstract
admonition. As this increased the size of the CSS that is shipped with Material for MkDocs, the additional type qualifiers are now all deprecated and will be removed in the next major version. This will also be mentioned in the upgrade guide. ↩↩↩ -
Note that improvements of existing features are sometimes released as patch releases, like for example improved rendering of content tabs, as they're not considered to be new features. ↩