119 lines
4.2 KiB
Markdown
Raw Normal View History

2022-12-02 18:31:54 +01:00
+++
categories = ['howto', 'reference']
description = 'Nice icons for your page'
title = 'Icon'
2022-12-02 18:31:54 +01:00
+++
2023-01-24 23:58:52 +01:00
The `icon` shortcode displays icons using the [Font Awesome](https://fontawesome.com) library.
2022-12-02 18:31:54 +01:00
{{% icon skull-crossbones blue %}}
{{% icon style="warning" %}}
{{% icon icon="angle-double-up" color="blue" %}}
2022-12-02 18:31:54 +01:00
## Usage
{{< tabs groupid="shortcode-parameter">}}
{{% tab title="shortcode" %}}
2022-12-02 18:31:54 +01:00
````go
{{%/* icon icon="skull-crossbones" style="blue" */%}}
{{%/* icon style="warning" */%}}
{{%/* icon icon="angle-double-up" color="blue" */%}}
2022-12-02 18:31:54 +01:00
````
{{% /tab %}}
{{% tab title="shortcode (positional)" %}}
2022-12-02 18:31:54 +01:00
````go
{{%/* icon skull-crossbones blue */%}}
{{%/* icon exclamation-triangle red */%}}
{{%/* icon angle-double-up blue */%}}
2022-12-02 18:31:54 +01:00
````
{{% /tab %}}
{{% tab title="partial" %}}
2022-12-02 18:31:54 +01:00
````go
{{ partial "shortcodes/icon.html" (dict
"page" .
"icon" "skull-crossbones"
"style" "blue"
2022-12-02 18:31:54 +01:00
)}}
{{ partial "shortcodes/icon.html" (dict
"page" .
"style" "warning"
2022-12-02 18:31:54 +01:00
)}}
{{ partial "shortcodes/icon.html" (dict
"page" .
"icon" "angle-double-up"
"color" "blue"
2022-12-02 18:31:54 +01:00
)}}
````
{{% /tab %}}
{{< /tabs >}}
### Parameter
| Name | Position | Default | Notes |
|-----------------------|----------|-----------------|-------------|
2023-10-24 22:49:34 +02:00
| **icon** | 1 | _&lt;empty&gt;_ | [Font Awesome icon name](#finding-an-icon) to be displayed. It will be displayed in the text color of its according context. |
| **style** | 2 | _&lt;empty&gt;_ | The style scheme used for the icon.<br><br>- by severity: `caution`, `important`, `info`, `note`, `tip`, `warning`<br>- by brand color: `primary`, `secondary`, `accent`<br>- by color: `blue`, `cyan`, `green`, `grey`, `magenta`, `orange`, `red`<br>- by special color: `default`, `transparent`, `code`<br><br>You can also [define your own styles](shortcodes/notice#defining-own-styles). |
| **color** | | _&lt;empty&gt;_ | The [CSS color value](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value) to be used. If not set, the chosen color depends on the **style**. Any given value will overwrite the default.<br><br>- for severity styles: a nice matching color for the severity<br>- for all other styles: the corresponding color<br><br> |
2022-12-02 18:31:54 +01:00
2022-12-02 19:26:49 +01:00
### Finding an icon
2022-12-02 18:31:54 +01:00
Browse through the available icons in the [Font Awesome Gallery](https://fontawesome.com/v6/search?m=free). Notice that the **free** filter is enabled, as only the free icons are available by default.
2022-12-02 18:31:54 +01:00
Once on the Font Awesome page for a specific icon, for example the page for the [heart](https://fontawesome.com/v6/icons/heart?s=solid), copy the icon name and paste into the Markdown content.
2022-12-02 18:31:54 +01:00
### Customizing Icons
2022-12-02 18:31:54 +01:00
Font Awesome provides many ways to modify the icon
- Change color (by default the icon will inherit the parent color)
- Increase or decrease size
- Rotate
- Combine with other icons
Check the full documentation on [web fonts with CSS](https://docs.fontawesome.com/web/style/styling) for more.
2022-12-02 18:31:54 +01:00
## Examples
2022-12-02 19:26:49 +01:00
### Standard Usage
2022-12-02 18:31:54 +01:00
````go
Built with {{%/* icon heart */%}} by Relearn and Hugo
````
Built with {{% icon heart %}} by Relearn and Hugo
### With color
````go
- Built with {{%/* icon heart red */%}} by Relearn and Hugo
- Built with {{%/* icon icon="heart" style="red" */%}} by Relearn and Hugo - long form, same as above
- Built with {{%/* icon icon="heart" color="red" */%}} by Relearn and Hugo - this uses the HTML color red instead of the red style
````
- Built with {{% icon heart red %}} by Relearn and Hugo
- Built with {{% icon icon="heart" style="red" %}} by Relearn and Hugo - long form, same as above
- Built with {{% icon icon="heart" color="red" %}} by Relearn and Hugo - this uses the HTML color red instead of the red style
2022-12-02 18:31:54 +01:00
### Advanced HTML Usage
While the shortcode simplifies using standard icons, the icon customization and other advanced features of the Font Awesome library require you to use HTML directly. Paste the `<i>` HTML into markup, and Font Awesome will load the relevant icon.
2022-12-02 18:31:54 +01:00
````html
Built with <i class="fas fa-heart"></i> by Relearn and Hugo
````
Built with <i class="fas fa-heart"></i> by Relearn and Hugo
To use these native HTML elements in your Markdown, add this in your `hugo.toml`:
````toml
[markup.goldmark.renderer]
unsafe = true
````