2020-07-24 09:59:16 +02:00
|
|
|
|
---
|
2022-01-07 11:06:11 +01:00
|
|
|
|
icon: material/emoticon-happy-outline
|
2020-07-24 09:59:16 +02:00
|
|
|
|
---
|
|
|
|
|
|
2022-03-27 14:01:30 +02:00
|
|
|
|
# Icons, Emojis
|
2020-07-24 09:59:16 +02:00
|
|
|
|
|
|
|
|
|
One of the best features of Material for MkDocs is the possibility to use [more
|
2022-09-07 19:34:35 +02:00
|
|
|
|
than 10,000 icons][icon search] and thousands of emojis in your project
|
2021-10-04 23:36:31 +02:00
|
|
|
|
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 09:59:16 +02:00
|
|
|
|
|
2021-02-06 12:35:19 +01:00
|
|
|
|
## Search
|
|
|
|
|
|
2021-02-24 18:02:09 +01:00
|
|
|
|
<div class="mdx-iconsearch" data-mdx-component="iconsearch">
|
2021-02-14 14:51:08 +01:00
|
|
|
|
<input
|
2021-02-24 18:02:09 +01:00
|
|
|
|
class="md-input md-input--stretch mdx-iconsearch__input"
|
2021-02-15 15:57:44 +01:00
|
|
|
|
placeholder="Search the icon and emoji database"
|
2021-02-24 18:02:09 +01:00
|
|
|
|
data-mdx-component="iconsearch-query"
|
2021-02-14 14:51:08 +01:00
|
|
|
|
/>
|
2021-02-24 18:02:09 +01:00
|
|
|
|
<div class="mdx-iconsearch-result" data-mdx-component="iconsearch-result">
|
|
|
|
|
<div class="mdx-iconsearch-result__meta"></div>
|
|
|
|
|
<ol class="mdx-iconsearch-result__list"></ol>
|
2021-02-14 14:51:08 +01:00
|
|
|
|
</div>
|
2021-02-06 12:35:19 +01:00
|
|
|
|
</div>
|
2021-02-14 14:51:08 +01:00
|
|
|
|
<small>
|
|
|
|
|
:octicons-light-bulb-16:
|
2021-10-04 23:36:31 +02:00
|
|
|
|
**Tip:** Enter some keywords to find icons and emojis and click on the
|
|
|
|
|
shortcode to copy it to your clipboard.
|
2021-02-14 14:51:08 +01:00
|
|
|
|
</small>
|
2021-02-06 12:35:19 +01:00
|
|
|
|
|
2020-07-24 09:59:16 +02:00
|
|
|
|
## Configuration
|
|
|
|
|
|
2021-10-04 23:36:31 +02: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 09:59:16 +02:00
|
|
|
|
|
|
|
|
|
``` yaml
|
|
|
|
|
markdown_extensions:
|
2022-04-04 12:02:44 +02:00
|
|
|
|
- attr_list
|
2020-07-24 09:59:16 +02:00
|
|
|
|
- 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-04 23:36:31 +02:00
|
|
|
|
- :material-material-design: – [Material Design]
|
|
|
|
|
- :fontawesome-brands-font-awesome: – [FontAwesome]
|
|
|
|
|
- :octicons-mark-github-16: – [Octicons]
|
2022-09-07 19:34:35 +02:00
|
|
|
|
- :simple-simpleicons: – [Simple Icons]
|
2020-07-24 09:59:16 +02:00
|
|
|
|
|
2021-10-04 23:36:31 +02:00
|
|
|
|
See additional configuration options:
|
2020-07-26 14:46:09 +02:00
|
|
|
|
|
2022-04-04 12:02:44 +02:00
|
|
|
|
- [Attribute Lists]
|
2021-10-04 23:36:31 +02:00
|
|
|
|
- [Emoji]
|
|
|
|
|
- [Emoji with custom icons]
|
2020-07-26 14:46:09 +02:00
|
|
|
|
|
2021-10-04 23:36:31 +02:00
|
|
|
|
[Material Design]: https://materialdesignicons.com/
|
2022-02-09 10:06:24 +01:00
|
|
|
|
[FontAwesome]: https://fontawesome.com/search?m=free
|
2021-10-04 23:36:31 +02:00
|
|
|
|
[Octicons]: https://octicons.github.com/
|
2022-09-07 19:34:35 +02:00
|
|
|
|
[Simple Icons]: https://simpleicons.org/
|
2022-04-04 12:02:44 +02:00
|
|
|
|
[Attribute Lists]: ../setup/extensions/python-markdown.md#attribute-lists
|
2021-10-04 23:36:31 +02:00
|
|
|
|
[Emoji]: ../setup/extensions/python-markdown-extensions.md#emoji
|
2021-10-10 12:19:14 +02:00
|
|
|
|
[Emoji with custom icons]: ../setup/extensions/python-markdown-extensions.md#custom-icons
|
2020-07-26 14:46:09 +02:00
|
|
|
|
|
2020-07-24 09:59:16 +02:00
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
|
|
### Using emojis
|
|
|
|
|
|
|
|
|
|
Emojis can be integrated in Markdown by putting the shortcode of the emoji
|
2021-10-04 23:36:31 +02:00
|
|
|
|
between two colons. If you're using [Twemoji] (recommended), you can look up
|
2022-01-10 14:31:58 +01:00
|
|
|
|
the shortcodes at [Emojipedia]:
|
2020-07-24 09:59:16 +02:00
|
|
|
|
|
2022-01-10 14:31:58 +01:00
|
|
|
|
``` title="Emoji"
|
2020-07-24 09:59:16 +02:00
|
|
|
|
:smile:
|
|
|
|
|
```
|
|
|
|
|
|
2022-01-10 14:31:58 +01:00
|
|
|
|
<div class="result" markdown>
|
2020-07-24 09:59:16 +02:00
|
|
|
|
|
|
|
|
|
:smile:
|
|
|
|
|
|
2022-01-10 14:31:58 +01:00
|
|
|
|
</div>
|
|
|
|
|
|
2021-10-04 23:36:31 +02:00
|
|
|
|
[Twemoji]: https://twemoji.twitter.com/
|
|
|
|
|
[Emojipedia]: https://emojipedia.org/twitter/
|
2020-07-24 09:59:16 +02:00
|
|
|
|
|
|
|
|
|
### Using icons
|
|
|
|
|
|
2021-10-04 23:36:31 +02:00
|
|
|
|
When [Emoji] is enabled, icons can be used similar to emojis, by referencing
|
2020-07-24 09:59:16 +02:00
|
|
|
|
a valid path to any icon bundled with the theme, which are located in the
|
2021-10-10 12:19:14 +02:00
|
|
|
|
[`.icons`][custom icons] directory, and replacing `/` with `-`:
|
2020-07-24 09:59:16 +02:00
|
|
|
|
|
2022-01-10 14:31:58 +01:00
|
|
|
|
``` title="Icon"
|
2022-02-18 10:52:27 +01:00
|
|
|
|
:fontawesome-regular-face-laugh-wink:
|
2020-07-24 09:59:16 +02:00
|
|
|
|
```
|
|
|
|
|
|
2022-01-10 14:31:58 +01:00
|
|
|
|
<div class="result" markdown>
|
2020-07-24 09:59:16 +02:00
|
|
|
|
|
2022-02-18 10:52:27 +01:00
|
|
|
|
:fontawesome-regular-face-laugh-wink:
|
2022-01-10 14:31:58 +01:00
|
|
|
|
|
|
|
|
|
</div>
|
2020-07-26 14:46:09 +02:00
|
|
|
|
|
2021-10-10 12:19:14 +02:00
|
|
|
|
[custom icons]: https://github.com/squidfunk/mkdocs-material/tree/master/material/.icons
|
2020-07-26 14:46:09 +02:00
|
|
|
|
|
2020-07-26 17:06:57 +02:00
|
|
|
|
#### with colors
|
|
|
|
|
|
2022-04-04 12:05:23 +02: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:
|
2020-07-26 17:06:57 +02:00
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
.twitter {
|
|
|
|
|
color: #1DA1F2;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
|
2022-09-11 19:25:40 +02:00
|
|
|
|
=== ":octicons-file-code-16: `docs/stylesheets/extra.css`"
|
2021-10-10 12:19:14 +02:00
|
|
|
|
|
|
|
|
|
``` css
|
|
|
|
|
.twitter {
|
|
|
|
|
color: #1DA1F2;
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2022-09-11 19:25:40 +02:00
|
|
|
|
=== ":octicons-file-code-16: `mkdocs.yml`"
|
2021-10-10 12:19:14 +02:00
|
|
|
|
|
|
|
|
|
``` yaml
|
|
|
|
|
extra_css:
|
2021-10-10 17:39:53 +02:00
|
|
|
|
- stylesheets/extra.css
|
2021-10-10 12:19:14 +02:00
|
|
|
|
```
|
2020-07-26 17:06:57 +02:00
|
|
|
|
|
2022-01-10 14:31:58 +01:00
|
|
|
|
After applying the customization, add the CSS class to the icon shortcode:
|
|
|
|
|
|
|
|
|
|
``` markdown title="Icon with color"
|
|
|
|
|
:fontawesome-brands-twitter:{ .twitter }
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
<div class="result" markdown>
|
2020-07-26 17:06:57 +02:00
|
|
|
|
|
2022-01-10 14:31:58 +01:00
|
|
|
|
:fontawesome-brands-twitter:{ .twitter }
|
|
|
|
|
|
|
|
|
|
</div>
|
2020-07-26 17:06:57 +02:00
|
|
|
|
|
2021-10-10 12:19:14 +02: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
|
2020-07-26 17:06:57 +02:00
|
|
|
|
|
|
|
|
|
#### with animations
|
|
|
|
|
|
2021-10-10 12:19:14 +02: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
|
2022-01-10 14:31:58 +01:00
|
|
|
|
dedicated CSS class to the icon:
|
2020-07-26 17:06:57 +02:00
|
|
|
|
|
2022-09-11 19:25:40 +02:00
|
|
|
|
=== ":octicons-file-code-16: `docs/stylesheets/extra.css`"
|
2021-10-10 12:19:14 +02:00
|
|
|
|
|
|
|
|
|
``` css
|
|
|
|
|
@keyframes heart {
|
|
|
|
|
0%, 40%, 80%, 100% {
|
|
|
|
|
transform: scale(1);
|
|
|
|
|
}
|
|
|
|
|
20%, 60% {
|
|
|
|
|
transform: scale(1.15);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
.heart {
|
|
|
|
|
animation: heart 1000ms infinite;
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2022-09-11 19:25:40 +02:00
|
|
|
|
=== ":octicons-file-code-16: `mkdocs.yml`"
|
2021-10-10 12:19:14 +02:00
|
|
|
|
|
|
|
|
|
``` yaml
|
|
|
|
|
extra_css:
|
2021-10-10 17:39:53 +02:00
|
|
|
|
- stylesheets/extra.css
|
2021-10-10 12:19:14 +02:00
|
|
|
|
```
|
2020-07-26 17:06:57 +02:00
|
|
|
|
|
2022-01-10 14:31:58 +01:00
|
|
|
|
After applying the customization, add the CSS class to the icon shortcode:
|
|
|
|
|
|
|
|
|
|
``` markdown title="Icon with animation"
|
|
|
|
|
:octicons-heart-fill-24:{ .heart }
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
<div class="result" markdown>
|
2020-07-26 17:06:57 +02:00
|
|
|
|
|
2021-03-13 14:30:29 +01:00
|
|
|
|
:octicons-heart-fill-24:{ .mdx-heart }
|
2020-07-24 09:59:16 +02:00
|
|
|
|
|
2022-01-10 14:31:58 +01:00
|
|
|
|
</div>
|
|
|
|
|
|
2021-10-10 12:19:14 +02:00
|
|
|
|
[colors]: #with-colors
|
|
|
|
|
[animations]: https://developer.mozilla.org/en-US/docs/Web/CSS/animation
|
2020-07-30 20:36:08 +02:00
|
|
|
|
|
|
|
|
|
## Customization
|
|
|
|
|
|
|
|
|
|
### Using icons in templates
|
|
|
|
|
|
2021-10-10 12:19:14 +02: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:
|
2020-07-30 20:36:08 +02:00
|
|
|
|
|
|
|
|
|
``` html
|
|
|
|
|
<span class="twemoji">
|
2022-01-16 17:27:14 +01:00
|
|
|
|
{% include ".icons/fontawesome/brands/twitter.svg" %} <!-- (1)! -->
|
2020-07-30 20:36:08 +02:00
|
|
|
|
</span>
|
|
|
|
|
```
|
|
|
|
|
|
2022-01-16 17:27:14 +01:00
|
|
|
|
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:
|
|
|
|
|
|
|
|
|
|
<div class="mdx-iconsearch" data-mdx-component="iconsearch">
|
|
|
|
|
<input class="md-input md-input--stretch mdx-iconsearch__input" placeholder="Search icon" data-mdx-component="iconsearch-query" value="brands twitter" />
|
|
|
|
|
<div class="mdx-iconsearch-result" data-mdx-component="iconsearch-result" data-mdx-mode="file">
|
|
|
|
|
<div class="mdx-iconsearch-result__meta"></div>
|
|
|
|
|
<ol class="mdx-iconsearch-result__list"></ol>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2020-07-30 20:36:08 +02:00
|
|
|
|
This is exactly what Material for MkDocs does in its templates.
|
|
|
|
|
|
2021-10-10 12:19:14 +02:00
|
|
|
|
[extending the theme]: ../customization.md#extending-the-theme
|
|
|
|
|
[include]: https://jinja.palletsprojects.com/en/2.11.x/templates/#include
|