---
title: Built-in social plugin
icon: material/share-circle
---
# Built-in social plugin
The social plugin automatically and intelligently generates beautiful and highly
customizable social cards in different [layouts][default layouts] for each page
of your project, rendering as preview images whenever you or somebody else share
a link to your project on social media.
## Objective
### How it works
The plugin automatically generates a customizable social card for each page
of your project, which appears as a preview image when sharing a link to your
project on social media, without the use of external services and just
[a single line of configuration][configuration].
With the use of an efficient [image processing] library, the plugin allows to
define [custom layouts] for social cards, which can be adapted to match your
project's style and branding. While it would technically be much simpler to
generate social cards by using a web browser and an automation framework like
[Puppeteer][^1], it would add further liabilities to your toolchain, with the
potential to make build pipelines more complex, much more resource intense,
and significantly slower.
[^1]:
[GitHub wrote in their blog] that they use [Puppeteer] to generate social
card images for repositories, issues, commits, discussions, and basically
everything else that appear as preview images when shared on social media.
The generated social cards are [cached] and stored in the
[`site` directory][mkdocs.site_dir], and thus self-hosted, ensuring that your
project doesn't depend on external services. In order to generate social cards
images, a few [dependencies] need to be available on your system.
[configuration]: #configuration
[image processing]: requirements/image-processing.md
[custom layouts]: ../setup/setting-up-social-cards.md#customization
[Puppeteer]: https://github.com/puppeteer/puppeteer
[GitHub wrote in their blog]: https://github.blog/2021-06-22-framework-building-open-graph-images/
[cached]: #caching
[dependencies]: #configuration
### When to use it
There's one particular case when we don't recommend to use the plugin: when you
build [offline-capable documentation] to offer it as a download. Otherwise, it
always makes sense to enable the plugin, as links to your documentation shared
on social media will appear much more appealing.
Even more interestingly, the plugin can be combined with other built-in plugins
that Material for MkDocs offers, in order to create sophisticated build
pipelines tailored to your project:
- :material-newspaper-variant-outline: __[Built-in blog plugin][blog]__
---
The social plugin automatically generates beautiful and customizable
social cards for each post and page, showing as previews on social media.
---
__Links to your blog render beautiful social cards when shared on social media__
- :material-file-tree: __[Built-in meta plugin][meta]__
---
The meta plugin can be used to [change the layout][meta.social.cards_layout]
for social cards or [change specific layout options]
[meta.social.cards_layout_options] like [background][option.background_color]
or [color][option.color] for a subset of pages.
---
__Your documentation can use completely different social cards per section__
[offline-capable documentation]: ../setup/building-for-offline-usage.md
[blog]: blog.md
[meta]: meta.md
## Configuration
In order to get started with the social plugin, just add the following lines to
`mkdocs.yml`, and observe how Material for MkDocs generates beautiful social
cards for you:
``` yaml
plugins:
- social
```
The social plugin is built into Material for MkDocs and doesn't need to be
installed.
However, in order to generate social card images, it's necessary to install the
dependencies for [image processing], if they're not already available on your
system. The linked guide includes instructions for several operating systems
and mentions some alternative environments.
[social]: social.md
### General
The following settings are available:
---
####
Use this setting to enable or disable the plugin when [building your project].
If you want to disable the plugin, e.g., for local builds, you can use an
[environment variable][mkdocs.env] in `mkdocs.yml`:
``` yaml
plugins:
- social:
enabled: !ENV [CI, false]
```
This configuration enables the plugin only during continuous integration (CI).
[building your project]: ../creating-your-site.md#building-your-site
---
####
With more CPUs available, the plugin can do more work in parallel, and thus
complete social card generation faster. If you want to disable concurrent
processing completely, use:
``` yaml
plugins:
- social:
concurrency: 1
```
By default, the plugin uses all available CPUs - 1 with a minimum of 1.
### Caching
The plugin implements an [intelligent caching] mechanism, ensuring that social
cards are only regenerated when their contents change or they're not already
contained in the cache. If any of the variables used in a layout changes, the
plugin detects it and regenerates the social card.
The following settings are available for caching:
[intelligent caching]: requirements/caching.md
---
####
Use this setting to instruct the plugin to bypass the cache, in order to
re-generate social cards for all pages, even though the cache may not be stale.
It's normally not necessary to specify this setting, except for when debugging
the plugin itself. Caching can be disabled with:
``` yaml
plugins:
- social:
cache: false
```
---
####
It is normally not necessary to specify this setting, except for when you want
to change the path within your root directory where social card images are
cached. If you want to change it, use:
``` yaml
plugins:
- social:
cache_dir: my/custom/dir
```
If you're using [multiple instances] of the plugin, it can be a good idea to
set different cache directories for both instances, so that they don't interfere
with each other.
[multiple instances]: index.md#multiple-instances
### Logging
The following settings are available for logging:
---
####
Use this setting to control whether the plugin should only log errors when
generating social cards without terminating the build, e.g., invalid references
to icons. To terminate the build, use:
``` yaml
plugins:
- social:
log: false
```
---
####
Use this setting to control the log level that the plugin should employ when
encountering errors, which requires that the [`log`][config.log] setting is
enabled. The following log levels are available:
=== "`warn`"
``` yaml
plugins:
- social:
log_level: warn
```
Errors are reported as warnings, terminating the build in
[`strict`][mkdocs.strict] mode.
=== "`info`"
``` yaml
plugins:
- social:
log_level: info
```
Errors are only reported as informational messages.
=== "`ignore`"
``` yaml
plugins:
- social:
log_level: ignore
```
Errors are only reported when using the `--verbose` flag.
### Social cards
The following settings are available for social card generation:
---
####
Use this setting to enable or disable social card generation. Currently, the
plugin's sole purpose is to generate social cards, so it's equivalent to the
[`enabled`][config.enabled] setting, but in the future, other features might be
added. If you want to disable social card generation, use:
``` yaml
plugins:
- social:
cards: false
```
---
####
It is normally not necessary to specify this setting, except for when you want
to change the path within the [`site` directory][mkdocs.site_dir] where
social cards are stored. If you want to change it, use:
``` yaml
plugins:
- social:
cards_dir: my/custom/dir
```
This configuration stores the generated images at `my/custom/dir` in the
[`site` directory][mkdocs.site_dir].
---
####
If you want to build a [custom social card layout][custom layouts], use this
setting to change the folder where you store your custom layouts, the default
being a folder called `layouts` in your root directory:
``` yaml
plugins:
- social:
cards_layout_dir: layouts
```
The provided path is resolved from the root directory.
!!! tip "Where to store custom layouts"
Our recommendation is to locate the folder outside of the
[`docs` directory][mkdocs.docs_dir], to make sure that your [custom layouts]
are not copied to the [`site` directory][mkdocs.site_dir] when
[building your project], e.g., by adhering to the following directory
layout:
``` { .sh .no-copy }
.
├─ docs/
│ └─ *.md
├─ layouts/
│ └─ *.yml
└─ mkdocs.yml
```
---
####
The plugin ships a growing list of [`default` layouts][default layouts] for
social cards. If you've created a [custom social card layout][custom layouts],
you can instruct the plugin to use it exactly as one of the included layouts:
``` yaml
plugins:
- social:
cards_layout: my-custom-layout
```
The provided path is resolved from the[
`layouts` directory][config.cards_layout_dir].
!!! tip "How custom layouts are resolved"
By default, the plugin will load your [custom layouts] from a folder named
`layouts` in your root directory. If your layout is called
`my-custom-layout`, the directory layout must adhere to:
``` { .sh .no-copy }
.
├─ docs/
│ └─ *.md
├─ layouts/
│ └─ my-custom-layout.yml
└─ mkdocs.yml
```
---
####
Use this setting to set options for the layout specified via [`cards_layout`]
[config.cards_layout] (if the layout supports it), which allows for making
layouts easily and entirely configurable:
``` yaml
plugins:
- social:
cards_layout_options: