1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935
|
---
title: Built-in tags plugin
icon: material/tag-text
---
# Built-in tags plugin
The tags plugin adds first-class support for categorizing pages with the use
of tags, adding the possibility to group related pages and make them
discoverable via search and dedicated tags indexes. If your documentation is
large, tags can help to discover relevant information faster.
## Objective
### How it works
The plugin scans all pages for the [`tags`][meta.tags] metadata property and
generates a tags index, which is an inverted list of tags and the pages they
appear on. The tags index can be located anywhere in the [`nav`][mkdocs.nav],
allowing for maximum flexibility when adding tags to your project.
### When to use it
If you want to add one or multiple tags indexes to your project, the tags
plugin is a perfect choice as it makes this process ridiculously simple.
Additionally, it integrates perfectly with several of the other
[built-in plugins] that Material for MkDocs offers:
<div class="grid cards" markdown>
- :material-file-tree: __[Built-in meta plugin][meta]__
---
The meta plugin makes it possible to ensure that subsections of your
project are annotated with [specific tags][meta.tags], so they can't be
forgotten when adding pages.
---
__Simpler organization and management of tags in different subsections__
- :material-newspaper-variant-outline: __[Built-in blog plugin][blog]__
---
The tags plugin allows to categorize posts alongside with pages in your
project, to improve their discoverability and connect posts to your
documentation.
---
__Your documentation's tag system integrates with your blog__
</div>
[meta]: meta.md
[blog]: blog.md
[built-in plugins]: index.md
## Configuration
<!-- md:version 8.2.0 -->
<!-- md:plugin [tags] – built-in -->
<!-- md:flag multiple -->
As with all [built-in plugins], getting started with the tags plugin is
straightforward. Just add the following lines to `mkdocs.yml`, and start using
[tags][meta.tags] to categorize your pages:
``` yaml
plugins:
- tags
```
The tags plugin is built into Material for MkDocs and doesn't need to be
installed.
[tags]: tags.md
### General
The following settings are available:
---
#### <!-- md:setting config.enabled -->
<!-- md:version 9.1.7 -->
<!-- md:default `true` -->
Use this setting to enable or disable the plugin when [building your project].
It's normally not necessary to specify this setting, but if you want to disable
the plugin, use:
``` yaml
plugins:
- tags:
enabled: false
```
[building your project]: ../creating-your-site.md#building-your-site
### Tags
The following settings are available for tags:
---
#### <!-- md:setting config.tags -->
<!-- md:version 9.3.2 -->
<!-- md:default `true` -->
Use this setting to enable or disable rendering of tags. The plugin still
extracts tags from all pages, e.g., for [exporting tags] without rendering them.
Rendering can be disabled with:
``` yaml
plugins:
- tags:
tags: false
```
This setting is automatically disabled if [`export_only`][config.export_only]
is enabled.
[exporting tags]: #export
---
#### <!-- md:setting config.tags_file -->
<!-- md:version 8.2.0 -->
<!-- md:default none -->
!!! warning "This setting is deprecated"
As of version <!-- md:version 9.6.0 -->, this setting is deprecated, as this
version ships a __ground up rewrite of the tags plugin__ which is much more
powerful than the previous version. Tags [listings] can be used on any page
now.
<div style="opacity: 0.5" markdown>
Use this setting to specify the location of the tags index, which is the page
used to render a list of all tags and their associated pages. If this setting is
specified, tags become clickable, pointing to the corresponding section in the
tags index:
``` yaml
plugins:
- tags:
tags_file: tags.md
```
The page holding the tags index can be linked anywhere in the [`nav`][mkdocs.nav]
section of `mkdocs.yml`. This setting is not required – you should only use it
if you want to have a tags index.
The provided path is resolved from the [`docs` directory][mkdocs.docs_dir].
</div>
[listings]: ../setup/setting-up-tags.md#adding-a-tags-index
---
#### <!-- md:setting config.tags_slugify -->
<!-- md:version 9.6.0 -->
<!-- md:default [`pymdownx.slugs.slugify`][pymdownx.slugs.slugify] -->
Use this setting to change the function for generating URL-compatible slugs
from post titles. By default, the [`slugify`][pymdownx.slugs.slugify] function
from [Python Markdown Extensions] is used as follows:
``` yaml
plugins:
- tags:
tags_slugify: !!python/object/apply:pymdownx.slugs.slugify
kwds:
case: lower
```
The default configuration is Unicode-aware and should produce good slugs for all
languages. Of course, you can also provide a custom slugification function for
more granular control.
[pymdownx.slugs.slugify]: https://github.com/facelessuser/pymdown-extensions/blob/01c91ce79c91304c22b4e3d7a9261accc931d707/pymdownx/slugs.py#L59-L65
[Python Markdown Extensions]: https://facelessuser.github.io/pymdown-extensions/extras/slugs/
---
#### <!-- md:setting config.tags_slugify_separator -->
<!-- md:version 9.6.0 -->
<!-- md:default `-` -->
Use this setting to change the separator that is passed to the slugification
function set as part of [`tags_slugify`][config.tags_slugify]. While the default
is a hyphen, it can be set to any string, e.g., `_`:
``` yaml
plugins:
- tags:
tags_slugify_separator: _
```
---
#### <!-- md:setting config.tags_slugify_format -->
<!-- md:version 9.6.0 -->
<!-- md:default `tag:{slug}` -->
Use this setting to change the format string that is used when generating tag
slugs. It is a good idea to prefix tag slugs with a string that makes them
unique, the default being:
``` yaml
plugins:
- tags:
tags_slugify_format: "tag:{slug}"
```
The following placeholders are available:
- `slug` – Tag slug, slugified with [`tags_slugify`][config.tags_slugify]
---
#### <!-- md:setting config.tags_hierarchy -->
<!-- md:sponsors -->
<!-- md:version insiders-4.48.0 -->
<!-- md:default `false` -->
<!-- md:flag experimental -->
Use this setting to enable support for tag hierarchies (nested tags, e.g.,
`foo/bar`). If you intend to create hierarchical listings of tags, you can
enable this setting in `mkdocs.yml` with:
``` yaml
plugins:
- tags:
tags_hierarchy: true
```
---
#### <!-- md:setting config.tags_hierarchy_separator -->
<!-- md:sponsors -->
<!-- md:version insiders-4.48.0 -->
<!-- md:default `/` -->
<!-- md:flag experimental -->
Use this setting to change the separator that is used when creating tag
hierarchies. By default, tags are separated by a forward slash `/`, but you
can change this to any string, e.g., `.`:
``` yaml
plugins:
- tags:
tags_hierarchy_separator: .
```
---
#### <!-- md:setting config.tags_sort_by -->
<!-- md:version 9.6.0 -->
<!-- md:default `material.plugins.tags.tag_name` -->
Use this setting to specify a custom function for comparing tags. By default,
tag comparison is case-sensitive, but you can use `tag_name_casefold` for
case-insensitive comparison:
``` yaml
plugins:
- tags:
tags_sort_by: !!python/name:material.plugins.tags.tag_name_casefold
```
You can also define your own comparison function, which must return a string
or number representing the tag, that is used for sorting, and reference it in
[`tags_sort_by`][config.tags_sort_by].
---
#### <!-- md:setting config.tags_sort_reverse -->
<!-- md:version 9.6.0 -->
<!-- md:default `false` -->
Use this setting to reverse the order in which tags are sorted when comparing
them. By default, tags are sorted in ascending order, but you can reverse
ordering as follows:
``` yaml
plugins:
- tags:
tags_sort_reverse: true
```
---
#### <!-- md:setting config.tags_name_property -->
<!-- md:version 9.6.0 -->
<!-- md:default [`tags`][meta.tags] -->
Use this setting to change the name of the front matter property that is used by
the plugin. It is normally not necessary to change this setting, but if you want
to change it, you can use:
``` yaml
plugins:
- tags:
tags_name_property: tags
```
---
#### <!-- md:setting config.tags_name_variable -->
<!-- md:version 9.6.0 -->
<!-- md:default `tags` -->
Use this setting to change the name of the template variable that is used by
the plugin. It is normally not necessary to change this setting, but if you want
to change it, you can use:
``` yaml
plugins:
- tags:
tags_name_variable: tags
```
---
#### <!-- md:setting config.tags_allowed -->
<!-- md:version 9.6.0 -->
<!-- md:default none -->
The plugin allows to check tags against a predefined list, in order to catch
typos or make sure that tags are not arbitrarily added. Specify the tags you
want to allow with:
``` yaml
plugins:
- tags:
tags_allowed:
- HTML5
- JavaScript
- CSS
```
The plugin stops the build if a page references a tag that is not part of
this list. Pages can be assigned to tags by using the [`tags`][meta.tags]
metadata property.
### Listings
The following settings are available for listings:
---
#### <!-- md:setting config.listings -->
<!-- md:version 9.6.0 -->
<!-- md:default `true` -->
Use this setting to enable or disable listings. It is normally not necessary to
change this setting, as listings are created entirely by inline comments, but
you can disable them if necessary with:
``` yaml
plugins:
- tags:
listings: false
```
This setting is automatically disabled if [`export_only`][config.export_only]
is enabled.
[exporting tags]: #export
---
#### <!-- md:setting config.listings_map -->
<!-- md:version 9.6.0 -->
<!-- md:default none -->
Use this define listing configurations that you can then reference in listings
with a custom identifier. Sharing configurations is a good idea, especially
when you have many tag listings:
``` yaml
plugins:
- tags:
listings_map:
custom-id:
scope: true
exclude: Internal
```
Then, just reference the listing identifier:
``` html
<!-- material/tags custom-id -->
```
See the [listings section] for a list of all available settings.
[listings section]: #listing-configuration
---
#### <!-- md:setting config.listings_sort_by -->
<!-- md:version 9.6.0 -->
<!-- md:default `material.plugins.tags.item_title` -->
Use this setting to specify a custom function for comparing listing items. By
default, items are ordered by their titles, but you can change the sorting
criterion with the following configuration:
=== "Sort by item title"
``` yaml
plugins:
- tags:
listings_sort_by: !!python/name:material.plugins.tags.item_title
```
=== "Sort by item URL"
``` yaml
plugins:
- tags:
listings_sort_by: !!python/name:material.plugins.tags.item_url
```
You can also define your own comparison function, which must return a string
or number representing the item, that is used for sorting, and reference it in
[`listings_sort_by`][config.listings_sort_by].
---
#### <!-- md:setting config.listings_sort_reverse -->
<!-- md:version 9.6.0 -->
<!-- md:default `false` -->
Use this setting to reverse the order in which items are sorted when comparing
them. By default, items are sorted in ascending order, but you can reverse
ordering as follows:
``` yaml
plugins:
- tags:
listings_sort_reverse: true
```
---
#### <!-- md:setting config.listings_tags_sort_by -->
<!-- md:version 9.6.0 -->
<!-- md:default `material.plugins.tags.tag_name` -->
Use this setting to specify a custom function for comparing tags in listings. By
default, tag comparison is case-sensitive, but you can use `tag_name_casefold`
for case-insensitivity:
``` yaml
plugins:
- tags:
tags_sort_by: !!python/name:material.plugins.tags.tag_name_casefold
```
You can also define your own comparison function, which must return a string
or number representing the tag, that is used for sorting, and reference it in
[`tags_sort_by`][config.tags_sort_by].
---
#### <!-- md:setting config.listings_tags_sort_reverse -->
<!-- md:version 9.6.0 -->
<!-- md:default `false` -->
Use this setting to reverse the order in which tags are sorted when comparing
them. By default, tags are sorted in ascending order, but you can reverse
ordering as follows:
``` yaml
plugins:
- tags:
tags_sort_reverse: true
```
---
#### <!-- md:setting config.listings_directive -->
<!-- md:version 9.6.0 -->
<!-- md:default `material/tags` -->
Use this setting to change the name of the directive the plugin will look for
when processing pages. If you want to use a shorter directive than
`material/tags`, you could use:
``` yaml
plugins:
- tags:
listings_directive: $tags
```
Using this setting, listings must now be referenced as such:
``` html
<!-- $tags { include: [foo, bar] } -->
```
---
#### <!-- md:setting config.listings_toc -->
<!-- md:sponsors -->
<!-- md:version insiders-4.48.0 -->
<!-- md:default `true` -->
Use this setting to enable or disable tags showing up in the table of contents.
If you don't want tags to show up in the table of contents, you can disable this
behavior with:
``` yaml
plugins:
- tags:
listings_toc: false
```
### Shadow tags
The following settings are available for shadow tags:
---
#### <!-- md:setting config.shadow -->
<!-- md:sponsors -->
<!-- md:version insiders-4.48.0 -->
<!-- md:default `false` -->
Use this setting to specify whether the plugin should include shadow tags on
pages and in listings when [building your project], which might be useful for
deploy previews:
=== "Show shadow tags"
``` yaml
plugins:
- tags:
shadow: true
```
=== "Hide shadow tags"
``` yaml
plugins:
- tags:
shadow: false
```
---
#### <!-- md:setting config.shadow_on_serve -->
<!-- md:sponsors -->
<!-- md:version insiders-4.48.0 -->
<!-- md:default `true` -->
Use this setting to control whether the plugin should include shadow tags on
pages and in listings when [previewing your site]. If you don't wish to include
them when previewing, use:
``` yaml
plugins:
- tags:
shadow_on_serve: false
```
[previewing your site]: ../creating-your-site.md#previewing-as-you-write
---
#### <!-- md:setting config.shadow_tags -->
<!-- md:sponsors -->
<!-- md:version insiders-4.48.0 -->
<!-- md:default none -->
The plugin allows to specify a predefined list of shadow tags which can be
included and excluded from builds by using the [`shadow`][config.shadow]
setting. Shadow tags must be specified as a list:
``` yaml
plugins:
- tags:
shadow_tags:
- Draft
- Internal
```
---
#### <!-- md:setting config.shadow_tags_prefix -->
<!-- md:sponsors -->
<!-- md:version insiders-4.48.0 -->
<!-- md:default none -->
Use this setting to specify a string that is checked as a prefix for each tag.
If the tag starts with this string, the tag is marked as a shadow tag. A common
practice is to use `_` as a prefix:
``` yaml
plugins:
- tags:
shadow_tags_prefix: _
```
---
#### <!-- md:setting config.shadow_tags_suffix -->
<!-- md:sponsors -->
<!-- md:version insiders-4.48.0 -->
<!-- md:default none -->
Use this setting to specify a string that is checked as a suffix for each tag.
If the tag ends with this string, the tag is marked as a shadow tag. One option
can be to use `Internal` as a suffix:
``` yaml
plugins:
- tags:
shadow_tags_suffix: Internal
```
### Export
The following settings are available for exporting:
---
#### <!-- md:setting config.export -->
<!-- md:sponsors -->
<!-- md:version insiders-4.49.0 -->
<!-- md:default `true` -->
Use this setting to control whether the plugin creates a `tags.json` file
inside your [`site` directory][mkdocs.site_dir], which can then be consumed by
other plugins and projects:
``` yaml
plugins:
- tags:
export: true
```
---
#### <!-- md:setting config.export_file -->
<!-- md:sponsors -->
<!-- md:version insiders-4.49.0 -->
<!-- md:default `tags.json` -->
Use this setting to change the path of the file where the exported tags are
stored. It's normally not necessary to change this setting, but if you need to,
use:
``` yaml
plugins:
- tags:
export_file: tags.json
```
The provided path is resolved from the [`site` directory][mkdocs.site_dir].
---
#### <!-- md:setting config.export_only -->
<!-- md:sponsors -->
<!-- md:version insiders-4.49.0 -->
<!-- md:default `false` -->
This setting is solely provided for convenience to disable the rendering of tags
and listings with a single setting (e.g. by using an environment variable),
while keeping the export functionality:
``` yaml
plugins:
- tags:
export_only: true
```
This will automatically disable the [`tags`][config.tags] and
[`listings`][config.listings] settings.
## Usage
### Metadata
The following properties are available:
---
#### <!-- md:setting meta.tags -->
<!-- md:version 8.2.0 -->
<!-- md:flag metadata -->
<!-- md:default none -->
Use this property to associate a page with one or more tags, making the page
appear in the generated tags index. Tags are defined as a list of strings
(whitespaces are allowed):
``` yaml
---
tags:
- HTML5
- JavaScript
- CSS
---
# Page title
...
```
If you want to prevent accidental typos when assigning tags to pages, you can
set a predefined list of allowed tags in `mkdocs.yml` by using the
[`tags_allowed`][config.tags_allowed] setting.
### Listing configuration
The listings configuration controls which tags are included in or excluded from
a listing and whether a listing only includes pages in the current scope.
Furthermore, listings can override some values from the global configuration.
The following settings are available:
---
#### <!-- md:setting listing.scope -->
<!-- md:version 9.6.0 -->
<!-- md:default `false` -->
This setting specifies whether the listing should only consider pages that are
within the current subsection of the documentation of the page the listing is
embedded in:
=== "Inline usage"
``` html
<!-- material/tags { scope: true } -->
```
=== "Usage in `mkdocs.yml`"
``` yaml
plugins:
- tags:
listings_map:
custom-id:
scope: false
```
Then, just reference the listing identifier:
``` html
<!-- material/tags custom-id -->
```
---
#### <!-- md:setting listing.shadow -->
<!-- md:sponsors -->
<!-- md:version insiders-4.49.0 -->
<!-- md:default computed -->
This setting specifies whether the listing should include shadow tags, which
allows to override the global [`shadow`][config.shadow] setting on a per-listing
basis:
=== "Inline usage"
``` html
<!-- material/tags { shadow: true } -->
```
=== "Usage in `mkdocs.yml`"
``` yaml
plugins:
- tags:
listings_map:
custom-id:
shadow: true
```
Then, just reference the listing identifier:
``` html
<!-- material/tags custom-id -->
```
---
#### <!-- md:setting listing.toc -->
<!-- md:sponsors -->
<!-- md:version insiders-4.48.0 -->
<!-- md:default [`listings_toc`][config.listings_toc] -->
This setting specifies whether the listing should render tags inside the table
of contents, allowing to override the global [`listings_toc`][config.listings_toc]
setting on a per-listing basis:
=== "Inline usage"
``` html
<!-- material/tags { toc: true } -->
```
=== "Usage in `mkdocs.yml`"
``` yaml
plugins:
- tags:
listings_map:
custom-id:
toc: true
```
Then, just reference the listing identifier:
``` html
<!-- material/tags custom-id -->
```
---
#### <!-- md:setting listing.include -->
<!-- md:version 9.6.0 -->
<!-- md:default none -->
Use this setting to specify which tags should be included in the listing. Each
page that features a tag that is part of this setting, is listed under the
respective tag:
=== "Inline usage"
``` html
<!-- material/tags { include: [foo, bar] } -->
```
=== "Usage in `mkdocs.yml`"
``` yaml
plugins:
- tags:
listings_map:
custom-id:
include:
- foo
- bar
```
Then, just reference the listing identifier:
``` html
<!-- material/tags custom-id -->
```
If this setting is left empty, all tags and pages are included.
---
#### <!-- md:setting listing.exclude -->
<!-- md:version 9.6.0 -->
<!-- md:default none -->
Use this setting to specify which tags should be excluded from the listing. Each
page that features a tag that is part of this setting, is excluded from the
listing entirely:
=== "Inline usage"
``` html
<!-- material/tags { exclude: [foo, bar] } -->
```
=== "Usage in `mkdocs.yml`"
``` yaml
plugins:
- tags:
listings_map:
custom-id:
exclude:
- foo
- bar
```
Then, just reference the listing identifier:
``` html
<!-- material/tags custom-id -->
```
If this setting is left empty, no tags or pages are excluded.
|