What is an icon
An icon is used to provide additional meaning to text and, in some rare contexts, meaning on its own.
You can see all the available icons ("glyphs") in our icon library, also known as Flight Icons library.
Types
There are four types of icons: Outlined, Filled, Off, and Contained.
Outlined
Outlined icons are icons with a standard outline.
Use Outlined icons by default.
Filled
Filled icons are icons with a solid fill and are indicated by -fill
in the icon name.
Use Filled icons to show a toggled state or for contrast with Outlined icons.
Indicating a toggled state
For objects that can be toggled on/off, show the Outlined icon for off
and the Filled icon for on
.
Using for contrast
If contrast against other icons is important, use Filled for the more important icon(s).
For example, when showing one failure in a list of 20 otherwise successful builds, use x-square-fill
while keeping the remaining icons in the Outlined style so the failure is more prominent.
Off
Off icons are icons including a strike-through and are indicated by -off
in the icon name.
Use Off icons to indicate something is disabled, unavailable, or will return a toggled icon off
.
Indicating a disabled or unavailable icon
When needing to indicate an action is disabled or unavailable, consider pairing an Off icon with the color style Foreground/Disabled
and cursor property value not-allowed
.
Return toggled state back off
If an object is toggled on
and it can be toggled off
, consider showing the Off icon on hover to indicate that clicking the icon again will toggle the object back off
.
Contained
Contained icons are icons with a containing shape and are indicated by their shape type in the icon name, e.g., -circle
, -square
, etc.
Use contained icons for emphasis in the hierarchy.
If an object can have multiple states, use a Contained icon for the overall parent state and the Outlined icon(s) for the children’s state(s).
Animated
Animated icons are icons with an animated effect that show a transition between two states.
Use animated icons to communicate activity happening in the background. For example, when an object is updated, the loading icon could appear after the save action is triggered, indicating that the changes are in progress.
Sizes
Icons are optimized for two icon sizes: 16px
and 24px
.
Use 16px
icons by default in product interfaces and 24px
icons for empty states.
States
Icons frequently represent different states within product interfaces, most commonly as states of an object or states of feedback.
States of an object
Some objects can return a state, e.g., a Build, Run, Cluster, etc. Objects are typically displayed in lists or as cards and include their state when presented to the user.
States of feedback
Feedback is presented in response to user interaction, such as a displaying a success message after submitting a form or a warning when a user nears their usage limit.
Common icons
Some icons represent common actions within our products.
Editing actions
Navigation actions
Help actions
Use
learn-link
when linking to tutorials.Use
docs-link
when linking to documentation pages and installation guides.Use
support
when referencing HashiCorp support.
How to use this component
The most basic invocation of the Icon component requires only the @name
property to be passed with a value matching an existing name in the Icon library:
<Hds::Icon @name="alert-circle" />
It renders to this (where the id
will be unique each time):
<svg
id="icon-ember115"
class="hds-icon icon-alert-circle"
width="16"
height="16"
viewBox="0 0 16 16"
xmlns="http://www.w3.org/2000/svg"
fill="currentColor"
aria-hidden="true"
data-test-icon="alert-circle"
>
<use href="/@hashicorp/flight-icons/icons/sprite.svg#alert-circle-16"></use>
</svg>
Because the icons are hidden to assistive technology, they cannot be used on their own and must be used inside of an element with an accessible name. See the Accessibility section for more details on how to best use this component in different contexts.
Size
The default size is 16px. To use the alternative 24px icon size, set the @size
value:
<Hds::Icon @name="zap" @size="24" />
Color
The default value is currentColor
which uses the inherited text color as the icon color. When setting a custom value, we recommend using one of the pre-defined variables to ensure consistency with our design language:
<Hds::Icon @name="zap" @color="var(--token-color-foreground-success)" />
Other accepted values include named colors and color values themselves (e.g., hex, rgb, etc).
<Hds::Icon @name="zap" @color="rebeccapurple" />
<Hds::Icon @name="zap" @color="rgb(46, 113, 229)" />
Stretched
To have the icon fill the parent container (width: 100%, height: 100%), set the @stretched
attribute to true:
<div class="doc-icon-demo--constrain-max-width">
<Hds::Icon @name="zap" @size="24" @stretched= />
</div>
Block vs. inline display
To change the default display from block
to inline-block
, set @isInline
to true:
<Hds::Icon @name="triangle" @isInline= />
<Hds::Icon @name="triangle-fill" @isInline= />
Aligning icons
Because the Hds::Icon
component has a block
display value by default (changeable using the @isInline
argument), the icon behaves like a block element. So, if you want to horizontally align it in relation to other sibling elements, you will have to use CSS to achieve the expected result.
For example, to visually center an icon with a generic text node, you will need to use a parent flex
container with align-items: center
.
Animated icons
The loading and running icons are animated by default, meaning no additional properties are needed:
<Hds::Icon @name="loading" @size="24" />
If you need the non-animated version of these icons, use the corresponding loading-static and running-static:
<Hds::Icon @name="loading-static" @size="24" />
Component API
name
string
color
string
- currentColor (default)
@color
argument can be used to change the color. It works by setting the value of the icon SVG’s fill
property.
size
number
- 16 (default)
- 24
stretched
boolean
- false (default)
true
will make the icon have a height and width of 100%.
isInline
boolean
- false (default)
display
style for the icon. Setting it to true
will make the icon have a display of inline-block
.
title
string
aria-hidden
value to false
instead of the default value of true
.
Conformance rating
When used as recommended, there should not be any accessibility issues with this component.
Browser accessibility support
Accessibility support for SVGs is inconsistent across browsers and assistive technology. Currently, the best practice is to set the aria-hidden
attribute to true
on the SVG itself (as we do by default for the Hds::Icon
component). This means that the icon (both the singular icon and the icon component) will need to be used in context. The icons themselves are for presentation purposes only and should never be used on their own.
<h2>
Activity report <Hds::Icon @name="activity" />
</h2>
If you make a custom element, or want to use a Hds::Icon
inside of a native HTML element like a <button>
element, ensure that an aria-label
attribute is added, like this:
<button aria-label="Check activity">
<Hds::Icon @name="activity" />
</button>
Resources
Here is a list of resources that are associated with our HDS icon component.
Icon Library
A list of all icons our component supports.
Figma library
For internal use only, the Figma library of icons that designers can leverage in their designs.
SVG assets
A ZIP file containing all SVG assets of our icons.
HDS support
If you are unable to find a specific icon, or notice a problem with an existing one, reach out to HDS support.
4.9.0
Added
Added the Hds::Icon
component. It replaces the FlightIcon
component.
How to migrate
We now recommend migrating the existing FlightIcon
instances to the Hds::Icon
component.
You can automate this migration using the codemod v4/icon
(see readme file). This codemod provides also a special flag to preserve the old display
layout for the icon (but we suggest to avoid using it, it's likely not needed at all).
If you have already started to use the FlightIconSignature
in TypeScript, you will have to replace the signature with the equivalent HdsIconSignature
(note: the isInlineBlock
argument has now become isInline
)