Create custom statuses for pages in Material for MkDocs
The Material theme for the MkDocs static site generator has a Status feature. You can use frontmatter to mark a page as either new
or deprecated
, and the theme gives it an icon in the navigation.
Recently, at n8n, I wanted to mark pages as beta
to signal they're documentation for a beta feature. I didn't want to use new
and its default icon for this, so had to add a custom status.
This is was the result:
Enable the feature
Start by enabling the status feature in your mkdocs.yml
in the extra
section:
For a beta
status, I put:
The description shows up when a user hovers over the status icon in the navigation.
Set the page status
To tag a page as beta
, set the status in the YAML frontmatter at the top of the page:
Create a style for your status
You probably already have extra CSS files set up to customise your site. If not, follow the instructions for adding Additional CSS.
In your CSS file, create a new class that includes the custom status name:
For a beta
status, I added:
Setting the text colour to white interfered with a hover effect, causing the status tag to disappear on hover, so I also added:
This is was the result:
Explanation
The key code for this feature is in the Material theme's nav-item.html
template:
The theme determines the look and feel of the status icon in the navigation using the CSS class name. As the theme has built-in support for new
and deprecated
, it provides styles for these. By adding a class with the name format .md-status--<status-name>
, where <status-name>
is the status you assign to the page, you can add whatever icon or text you want.
Wrap up
Another niche Material for MkDocs guide, though I think Prevent MkDocs from replacing tabs with spaces in code blocks still holds the record for most-niche post. As usual, I'm not 100% certain I've done things in the best or most elegant way, but it works, and got done in a few minutes hours before feature release, so I'm ok with quick-and-working.