Setting up tags - Material for MkDocs (original) (raw)

Material for MkDocs adds first-class support for categorizing pages with tags, which adds the possibility to group related pages and make them discoverable via search and a dedicated tags index. If your documentation is large, tags can help to discover relevant information faster.

Configuration

Built-in tags plugin

8.2.0

The built-in tags plugin adds the ability to categorize any page with tags as part of the front matter of the page. In order to add support for tags, add the following lines to mkdocs.yml:

For a list of all settings, please consult the plugin documentation.

Tag icons and identifiers

8.5.0 .zip

Each tag can be associated with an icon, which is then rendered inside the tag. Before assigning icons to tags, associate each tag with a unique identifier, by adding the following to mkdocs.yml:

[](#%5F%5Fcodelineno-1-1)extra: [](#%5F%5Fcodelineno-1-2) tags: [](#%5F%5Fcodelineno-1-3) <tag>: <identifier> # (1)!

  1. The identifier can only include alphanumeric characters, as well as dashes and underscores. For example, if you have a tag Compatibility, you can set compat as an identifier:
    `extra:
    tags:

Compatibility: compat
`
Identifiers can be reused between tags. Tags which are not explicitly associated will use the default tag icon which is

Next, each identifier can be associated with an icon, even a custom icon, by adding the following lines to mkdocs.yml under the theme.icon configuration setting:

Tag iconTag default icon

[](#%5F%5Fcodelineno-3-1)theme: [](#%5F%5Fcodelineno-3-2) icon: [](#%5F%5Fcodelineno-3-3) tag: [](#%5F%5Fcodelineno-3-4) <identifier>: <icon> # (1)!

  1. Enter a few keywords to find the perfect icon using our icon search and click on the shortcode to copy it to your clipboard:

[](#%5F%5Fcodelineno-4-1)theme: [](#%5F%5Fcodelineno-4-2) icon: [](#%5F%5Fcodelineno-4-3) tag: [](#%5F%5Fcodelineno-4-4) default: <icon>

Expand to inspect example

[](#%5F%5Fcodelineno-5-1)theme: [](#%5F%5Fcodelineno-5-2) icon: [](#%5F%5Fcodelineno-5-3) tag: [](#%5F%5Fcodelineno-5-4) html: fontawesome/brands/html5 [](#%5F%5Fcodelineno-5-5) js: fontawesome/brands/js [](#%5F%5Fcodelineno-5-6) css: fontawesome/brands/css3 [](#%5F%5Fcodelineno-5-7)extra: [](#%5F%5Fcodelineno-5-8) tags: [](#%5F%5Fcodelineno-5-9) HTML5: html [](#%5F%5Fcodelineno-5-10) JavaScript: js [](#%5F%5Fcodelineno-5-11) CSS: css

Usage

Adding tags

8.2.0 .zip

When the built-in tags plugin is enabled, tags can be added for a document with the front matter tags property. Add the following lines at the top of a Markdown file:

[](#%5F%5Fcodelineno-6-1)--- [](#%5F%5Fcodelineno-6-2)tags: [](#%5F%5Fcodelineno-6-3) - HTML5 [](#%5F%5Fcodelineno-6-4) - JavaScript [](#%5F%5Fcodelineno-6-5) - CSS [](#%5F%5Fcodelineno-6-6)--- [](#%5F%5Fcodelineno-6-7) [](#%5F%5Fcodelineno-6-8)...

The page will now render with those tags above the main headline and within the search preview, which now allows to find pages by tags.

How to set tags for an entire folder?

With the help of the built-in meta plugin, you can ensure that tags are set for an entire section and all nested pages, by creating a .meta.yml file in the corresponding folder with the following content:

[](#%5F%5Fcodelineno-7-1)tags: [](#%5F%5Fcodelineno-7-2) - HTML5 [](#%5F%5Fcodelineno-7-3) - JavaScript [](#%5F%5Fcodelineno-7-4) - CSS

The tags set in .meta.yml are merged and deduplicated with the tags defined for a page, which means you can define common tags in .meta.yml and then add specific tags for each page. The tags in .meta.yml are appended.

Adding a tags index

8.2.0 .zip

The built-in tags plugin allows to define a file to render a tags index, which can be any page that is part of the nav section. To add a tags index, create a page, e.g. tags.md:

[](#%5F%5Fcodelineno-8-1)# Tags [](#%5F%5Fcodelineno-8-2) [](#%5F%5Fcodelineno-8-3)Following is a list of relevant tags: [](#%5F%5Fcodelineno-8-4) [](#%5F%5Fcodelineno-8-5)<!-- material/tags -->

The tags marker specifies the position of the tags index, i.e. it is replaced with the actual tags index when the page is rendered. You can include arbitrary content before and after the marker:

Tags index

Advanced features

Configurable listings

9.6.0

Listings can be configured in mkdocs.yml or directly at the location of the marker that you position in a Markdown document. Some examples:

See the listing configuration for all options.

Scoped listings

9.7.0

If your documentation is large, you might want to consider using scoped listings which will only include pages that are on the same level or below the page containing the listing. Just use:

[](#%5F%5Fcodelineno-13-1)<!-- material/tags { scope: true } -->

If you plan to use multiple scoped indexes, it's a good idea to define a listing configuration in mkdocs.yml, which you can then reference by its id:

[](#%5F%5Fcodelineno-14-1)plugins: [](#%5F%5Fcodelineno-14-2) - tags: [](#%5F%5Fcodelineno-14-3) listings_map: [](#%5F%5Fcodelineno-14-4) scoped: [](#%5F%5Fcodelineno-14-5) scope: true

You can now use:

[](#%5F%5Fcodelineno-15-1)<!-- material/tags scoped -->

Shadow tags

9.7.0

Shadow tags are tags that are solely meant to organization, which can be included or excluded for rendering with a simple flag. They can be enumerated in the shadow_tags setting:

[](#%5F%5Fcodelineno-16-1)plugins: [](#%5F%5Fcodelineno-16-2) - tags: [](#%5F%5Fcodelineno-16-3) shadow_tags: [](#%5F%5Fcodelineno-16-4) - Draft [](#%5F%5Fcodelineno-16-5) - Internal

If a document is tagged with Draft, the tag will only be rendered if shadow setting is enabled, and excluded when it is disabled. This is an excellent opportunity for using tags for structuring.

Nested tags

9.7.0

The tags_hierarchy_separator allows to create hierarchies of tags, e.g., Foo/Bar. Nested tags will be rendered as children of the parent tag:

[](#%5F%5Fcodelineno-17-1)plugins: [](#%5F%5Fcodelineno-17-2) - tags: [](#%5F%5Fcodelineno-17-3) tags_hierarchy: true

Hiding tags on a page

While the tags are rendered above the main headline, sometimes, it might be desirable to hide them for a specific page, which can be achieved with the front matter hide property:

[](#%5F%5Fcodelineno-18-1)--- [](#%5F%5Fcodelineno-18-2)hide: [](#%5F%5Fcodelineno-18-3) - tags [](#%5F%5Fcodelineno-18-4)--- [](#%5F%5Fcodelineno-18-5) [](#%5F%5Fcodelineno-18-6)# Page title [](#%5F%5Fcodelineno-18-7)...