Setting up site search¶
Material for MkDocs provides an excellent client-side search implementation, omitting the need for the integration of third-party services, which might not be compliant with privacy regulations. Moreover, search even works offline, allowing users to download your documentation.
Configuration¶
Built-in search plugin¶
The built-in search plugin integrates seamlessly with Material for MkDocs, adding multilingual client-side search with lunr and lunr-languages. It's enabled by default, but must be re-added to mkdocs.yml
when other plugins are used:
For a list of all settings, please consult the plugin documentation.
Search suggestions¶
When search suggestions are enabled, the search will display the likeliest completion for the last word which can be accepted with the Right key. Add the following lines to mkdocs.yml
:
Searching for search su yields search suggestions as a suggestion.
Search highlighting¶
When search highlighting is enabled and a user clicks on a search result, Material for MkDocs will highlight all occurrences after following the link. Add the following lines to mkdocs.yml
:
Searching for code blocks highlights all occurrences of both terms.
Search sharing¶
When search sharing is activated, a share button is rendered next to the reset button, which allows to deep link to the current search query and result. Add the following lines to mkdocs.yml
:
When a user clicks the share button, the URL is automatically copied to the clipboard.
Usage¶
Search boosting¶
Pages can be boosted in search with the front matter search.boost
property, which will make them rank higher. Add the following lines at the top of a Markdown file:
Search exclusion¶
Pages can be excluded from search with the front matter search.exclude
property, removing them from the index. Add the following lines at the top of a Markdown file:
Excluding sections¶
When Attribute Lists is enabled, specific sections of pages can be excluded from search by adding the data-search-exclude
pragma after a Markdown heading:
Excluding blocks¶
When Attribute Lists is enabled, specific sections of pages can be excluded from search by adding the data-search-exclude
pragma after a Markdown inline- or block-level element: