Icon
The icon shortcode allows you to easily embed Font Awesome SVG icons inline within your markdown content.
Basic Usage #
Using Positional Parameters (Recommended) #
{{< icon "github" >}}
{{< icon "heart" "solid" >}}
{{< icon "envelope" "regular" "custom-class" >}}Using Named Parameters #
{{< icon name="github" style="brands" >}}
{{< icon name="heart" style="solid" class="text-lg" >}}
{{< icon name="twitter" style="brands" ariaLabel="Twitter Profile" >}}Supported Parameters #
| Parameter | Position | Type | Default | Description |
|---|---|---|---|---|
name | 0 | string | required | The Font Awesome icon name (e.g., “github”, “heart”, “envelope”) |
style | 1 | string | "solid" | Icon style: "solid", "regular", or "brands" |
class | 2 | string | "" | Additional CSS classes to apply to the icon |
ariaLabel | - | string | icon name | Accessibility label for screen readers (named params only) |
Examples #
Social Media Icons #
Using brand icons for social media:
{{< icon “github” “brands” >}} GitHub
{{< icon “twitter” “brands” >}} Twitter
{{< icon “linkedin” “brands” >}} LinkedIn
{{< icon “youtube” “brands” >}} YouTube
Output:
GitHub
Twitter
LinkedIn
YouTube
Solid Icons (Default) #
Standard solid icons (style defaults to “solid”):
{{< icon “heart” >}} Favorite
{{< icon “star” >}} Rating
{{< icon “check” >}} Completed
{{< icon “envelope” >}} Email
Output:
Favorite
Rating
Completed
Email
Regular Style Icons #
Using the regular (outline) style:
{{< icon “heart” “regular” >}} Like
{{< icon “star” “regular” >}} Bookmark
{{< icon “circle” “regular” >}} Indicator
Output:
Like
Bookmark
Indicator
With Custom Classes #
Add custom CSS classes for styling:
{{< icon name=“heart” style=“solid” class=“text-red” >}}
{{< icon name=“star” style=“solid” class=“text-yellow” >}}
With Accessibility Labels #
Provide meaningful labels for screen readers:
{{< icon name=“github” style=“brands” ariaLabel=“Visit our GitHub repository” >}}
{{< icon name=“envelope” ariaLabel=“Send us an email” >}}
How It Works #
- Icon Fetching: The shortcode fetches SVG icons from the Font Awesome CDN (
https://raw.githubusercontent.com/FortAwesome/Font-Awesome/) - Inline SVG: Icons are embedded as inline SVGs in your HTML output
- Accessibility: Each icon includes proper
aria-labelandrole="img"attributes - Fallback: If an icon fails to load, a text fallback
[icon-name]is displayed with a warning - CSS Classes: Icons automatically get
.iconand.icon-{name}classes, plus any custom classes you specify
Note
Icon SVGs are fetched at build time, so internet access is required during Hugo builds
Icon Styles #
Font Awesome provides three main styles:
solid(default): Filled icons, the most commonly used styleregular: Outline/line icons, lighter weightbrands: Brand and logo icons (GitHub, Twitter, etc.)
Finding Icons #
Browse the complete Font Awesome icon library at fontawesome.com/icons to find icon names and check which styles are available for each icon.
Note
Font Awesome has both FREE and PRO icons, you would only be able to use icons which are FREE.
CSS Customization #
Icons receive the following CSS classes:
.icon- Base class for all icons.icon-{name}- Specific class for the icon name (e.g.,.icon-github)- Any custom classes you specify via the
classparameter
You can style icons using these classes in your custom CSS:
.icon {
width: 1em;
height: 1em;
vertical-align: middle;
}
.icon-github {
color: #333;
}
.text-red .icon {
color: red;
}