Represents a visual element that provides context and enhances usability.
For Use In
Lightning Experience, Experience Builder Sites, Salesforce Mobile App, Lightning Out (Beta), Standalone Lightning App, Mobile Offline
A lightning-icon component is a visual element that provides context and enhances
usability. lightning-icon provides you with icons in the Salesforce Lightning Design System (SLDS).
Use icons inside the body of another component or on their own.
You can specify an icon from the Lightning Design System by using the icon-name attribute.
Alternatively, you can provide a custom icon by using the src attribute. See the Use SVG Icons section.
Design
lightning-icon implements the icons blueprint in the Salesforce Lightning Design System (SLDS). The icons adapt to SLDS 1 or SLDS 2 styling based on the org’s theme or the container app that you use. Visit icons to view the available icons.
Use the src attribute to specify the path of the resource for your
icon. When this attribute is present, lightning-icon attempts to load an
icon from the provided resource.
Define a static resource in your org and upload your icon’s SVG resource
to it. The SVG code must include a <g> element with an id value that you can reference.
For example, your static resource is named mySVG_icon and it contains
this google.svg content.
Override the Icon Fill Color of Your Imported Icons
Note that icons you import have a default fill attribute value #fff, which
you can override in your svg sprite directly. For example, change the color to
a shade of green by inserting fill=#648079 in the <svg> element.
Alternatively, use CSS custom properties to change the fill color on your imported icon. See the non-utility icon example in the Customize Component Styling section.
Component Styling
Use a combination of the variant, size, and class attributes to customize the icon styling.
When applying SLDS classes or icons, check that they’re
available in the SLDS release tied to your org. The latest
SLDS resources become available only when the new release
is available in your org.
Sizes
Adjust icon sizes by using the size attribute with one of these values.
medium is the default size, which creates a 32px by 32px icon
small creates a 24px by 24px icon
x-small creates a 16px by 16px icon
xx-small creates a 14px by 14px icon
large creates a 48px by 48px icon
Variants
Variants are supported only for the utility icons. To change the appearance of a utility icon, use the variant attribute with one of these values.
inverse adds a white fill to a utility icon, useful for dark backgrounds
error adds a red fill to a utility icon to call out a user- or system-related error
success adds a green fill to a utility icon to represent a successful operation
warning adds a yellow fill to a utility icon to advise caution
This example uses the error variant to add a red fill to the error utility icon.
To apply additional styling, use the SLDS utility classes with the class attribute.
For example, you can set class="slds-m-vertical_large" or other margin classes to add spacing around the icon.
Component styling hooks provide CSS custom properties that use the --slds-c-* prefix and they change styling for specific elements or properties of a component. Component styling hooks are supported for SLDS 1 only. See the SLDS 1 component blueprints for available component styling hooks.
Use the alternative-text attribute to describe the icon for assistive devices.
The description indicates what happens when you click the button, for example ‘Upload
File’, not what the icon looks like, ‘Paperclip’.
Sometimes an icon is decorative and doesn’t need a description. But icons can
switch between being decorative or informational based on the screen size. If
you choose not to include an alternative-text description, check smaller
screens and windows to make sure that the icon is decorative on all formats.
Usage Considerations
Icons aren’t available in Lightning Out, but they’re available in Lightning Components for Visualforce and other experiences.
Attributes
Name
Description
Type
Default
Required
alternative-text
The alternative text used to describe the icon. This text should describe what happens when you click the button, for example 'Upload File', not what the icon looks like, 'Paperclip'.
string
icon-name
The Lightning Design System name of the icon. Names are written in the format 'utility:down' where 'utility' is the category, and 'down' is the specific icon to be displayed.
string
size
The size of the icon. Options include xx-small, x-small, small, medium, or large. The default is medium.
string
medium
src
A uri path to a custom svg sprite, including the name of the resouce, for example: /assets/icons/standard-sprite/svg/test.svg#icon-heart
string
variant
The variant changes the appearance of a utility icon. Accepted variants include inverse, success, warning, and error. Use the inverse variant to implement a white fill in utility icons on dark backgrounds.