mkdocs-material/docs/reference/icons-emojis.md

232 lines
6.3 KiB
Markdown
Raw Normal View History

2020-07-24 10:59:16 +03:00
---
template: overrides/main.html
2022-01-07 13:06:11 +03:00
icon: material/emoticon-happy-outline
2020-07-24 10:59:16 +03:00
---
# Icons + Emojis
One of the best features of Material for MkDocs is the possibility to use [more
2021-10-05 00:36:31 +03:00
than 8.000 icons][icon search] and thousands of emojis in your project
documentation with practically zero additional effort. Moreover, custom icons
can be added and used in `mkdocs.yml`, documents and templates.
[icon search]: #search
2020-07-24 10:59:16 +03:00
2021-02-06 14:35:19 +03:00
## Search
<div class="mdx-iconsearch" data-mdx-component="iconsearch">
<input
class="md-input md-input--stretch mdx-iconsearch__input"
2021-02-15 17:57:44 +03:00
placeholder="Search the icon and emoji database"
data-mdx-component="iconsearch-query"
/>
<div class="mdx-iconsearch-result" data-mdx-component="iconsearch-result">
<div class="mdx-iconsearch-result__meta"></div>
<ol class="mdx-iconsearch-result__list"></ol>
</div>
2021-02-06 14:35:19 +03:00
</div>
<small>
:octicons-light-bulb-16:
2021-10-05 00:36:31 +03:00
**Tip:** Enter some keywords to find icons and emojis and click on the
shortcode to copy it to your clipboard.
</small>
2021-02-06 14:35:19 +03:00
2020-07-24 10:59:16 +03:00
## Configuration
2021-10-05 00:36:31 +03:00
This configuration enables the use of icons and emojis by using simple
shortcodes which can be discovered through the [icon search]. Add the following
lines to `mkdocs.yml`:
2020-07-24 10:59:16 +03:00
``` yaml
markdown_extensions:
- pymdownx.emoji:
emoji_index: !!python/name:materialx.emoji.twemoji
emoji_generator: !!python/name:materialx.emoji.to_svg
```
The following icon sets are bundled with Material for MkDocs:
2021-10-05 00:36:31 +03:00
- :material-material-design: [Material Design]
- :fontawesome-brands-font-awesome: [FontAwesome]
- :octicons-mark-github-16: [Octicons]
2020-07-24 10:59:16 +03:00
2021-10-05 00:36:31 +03:00
See additional configuration options:
2020-07-26 15:46:09 +03:00
2021-10-05 00:36:31 +03:00
- [Emoji]
- [Emoji with custom icons]
2020-07-26 15:46:09 +03:00
2021-10-05 00:36:31 +03:00
[Material Design]: https://materialdesignicons.com/
[FontAwesome]: https://fontawesome.com/icons?d=gallery&m=free
[Octicons]: https://octicons.github.com/
[Emoji]: ../setup/extensions/python-markdown-extensions.md#emoji
2021-10-10 13:19:14 +03:00
[Emoji with custom icons]: ../setup/extensions/python-markdown-extensions.md#custom-icons
2020-07-26 15:46:09 +03:00
2020-07-24 10:59:16 +03:00
## Usage
### Using emojis
Emojis can be integrated in Markdown by putting the shortcode of the emoji
2021-10-05 00:36:31 +03:00
between two colons. If you're using [Twemoji] (recommended), you can look up
the shortcodes at [Emojipedia].
2020-07-24 10:59:16 +03:00
_Example_:
```
:smile:
```
_Result_:
:smile:
2021-10-05 00:36:31 +03:00
[Twemoji]: https://twemoji.twitter.com/
[Emojipedia]: https://emojipedia.org/twitter/
2020-07-24 10:59:16 +03:00
### Using icons
2021-10-05 00:36:31 +03:00
When [Emoji] is enabled, icons can be used similar to emojis, by referencing
2020-07-24 10:59:16 +03:00
a valid path to any icon bundled with the theme, which are located in the
2021-10-10 13:19:14 +03:00
[`.icons`][custom icons] directory, and replacing `/` with `-`:
2020-07-24 10:59:16 +03:00
_Example_:
```
2021-10-10 13:19:14 +03:00
- :material-account-circle: `material/account-circle.svg`
- :fontawesome-regular-laugh-wink: `fontawesome/regular/laugh-wink.svg`
- :octicons-repo-push-16: `octicons/repo-push-16.svg`
2020-07-24 10:59:16 +03:00
```
_Result_:
2021-10-10 13:19:14 +03:00
- :material-account-circle: [`material/account-circle.svg`][icon Material]
- :fontawesome-regular-laugh-wink: [`fontawesome/regular/laugh-wink.svg`][icon FontAwesome]
- :octicons-repo-push-16: [`octicons/repo-push-16.svg`][icon Octicons]
2020-07-26 15:46:09 +03:00
2021-10-10 13:19:14 +03:00
[custom icons]: https://github.com/squidfunk/mkdocs-material/tree/master/material/.icons
[icon Material]: https://raw.githubusercontent.com/squidfunk/mkdocs-material/master/material/.icons/material/account-circle.svg
[icon FontAwesome]: https://raw.githubusercontent.com/squidfunk/mkdocs-material/master/material/.icons/fontawesome/regular/laugh-wink.svg
[icon Octicons]: https://raw.githubusercontent.com/squidfunk/mkdocs-material/master/material/.icons/octicons/repo-push-16.svg
2020-07-26 15:46:09 +03:00
#### with colors
2021-10-10 13:19:14 +03:00
When [Attribute Lists] is enabled, custom CSS classes can be added to icons by
suffixing the icon with a special syntax. While HTML allows to use
[inline styles], it's always recommended to add an [additional style sheet] and
move declarations into dedicated CSS classes.
<style>
.medium {
color: #00AB6C;
}
.twitter {
color: #1DA1F2;
}
.facebook {
color: #4267B2;
}
</style>
_Example_:
2021-10-10 13:19:14 +03:00
=== ":octicons-file-code-16: docs/example.md"
``` markdown
- :fontawesome-brands-medium:{ .medium } Medium
- :fontawesome-brands-twitter:{ .twitter } Twitter
- :fontawesome-brands-facebook:{ .facebook } Facebook
```
2021-10-10 18:39:53 +03:00
=== ":octicons-file-code-16: docs/stylesheets/extra.css"
2021-10-10 13:19:14 +03:00
``` css
.medium {
color: #00AB6C;
}
.twitter {
color: #1DA1F2;
}
.facebook {
color: #4267B2;
}
```
=== ":octicons-file-code-16: mkdocs.yml"
``` yaml
extra_css:
2021-10-10 18:39:53 +03:00
- stylesheets/extra.css
2021-10-10 13:19:14 +03:00
```
_Result_:
- :fontawesome-brands-medium:{ .medium } Medium
- :fontawesome-brands-twitter:{ .twitter } Twitter
- :fontawesome-brands-facebook:{ .facebook } Facebook
2021-10-10 13:19:14 +03:00
[Attribute Lists]: ../setup/extensions/python-markdown.md#attribute-lists
[inline styles]: https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/style
[additional style sheet]: ../customization.md#additional-css
#### with animations
2021-10-10 13:19:14 +03:00
Similar to adding [colors], it's just as easy to add [animations] to icons by
using an [additional style sheet], defining a `@keyframes` rule and adding a
dedicated CSS class to the icon.
2021-10-10 13:19:14 +03:00
_Example_:
2021-10-10 13:19:14 +03:00
=== ":octicons-file-code-16: docs/example.md"
2021-10-10 13:19:14 +03:00
``` markdown
:octicons-heart-fill-24:{ .heart }
```
2021-10-10 18:39:53 +03:00
=== ":octicons-file-code-16: docs/stylesheets/extra.css"
2021-10-10 13:19:14 +03:00
``` css
@keyframes heart {
0%, 40%, 80%, 100% {
transform: scale(1);
}
20%, 60% {
transform: scale(1.15);
}
}
.heart {
animation: heart 1000ms infinite;
}
```
=== ":octicons-file-code-16: mkdocs.yml"
``` yaml
extra_css:
2021-10-10 18:39:53 +03:00
- stylesheets/extra.css
2021-10-10 13:19:14 +03:00
```
_Result_:
:octicons-heart-fill-24:{ .mdx-heart }
2020-07-24 10:59:16 +03:00
2021-10-10 13:19:14 +03:00
[colors]: #with-colors
[animations]: https://developer.mozilla.org/en-US/docs/Web/CSS/animation
## Customization
### Using icons in templates
2021-10-10 13:19:14 +03:00
When you're [extending the theme] with partials or blocks, you can simply
reference any icon that's [bundled with the theme][icon search] with Jinja's
[`include`][include] function and wrap it with the `.twemoji` CSS class:
``` html
<span class="twemoji">
{% include ".icons/fontawesome/brands/twitter.svg" %}
</span>
```
This is exactly what Material for MkDocs does in its templates.
2021-10-10 13:19:14 +03:00
[extending the theme]: ../customization.md#extending-the-theme
[include]: https://jinja.palletsprojects.com/en/2.11.x/templates/#include