Lightning Experience, Experience Builder Sites, Salesforce Mobile App, Lightning Out (Beta), Standalone Lightning App, Mobile Offline
A lightning-button-icon component represents an icon-only button element that
runs an action. Clicking the button triggers the JavaScript
method set for onclick.
lightning-button-icon implements the button icons blueprint in the Salesforce Lightning Design System (SLDS). The button icons adapt to SLDS 1 or SLDS 2 styling based on the org’s theme or the container app that you use.
Use a combination of the icon-class, size, variant, and class
attributes to customize the button and icon styles.
To customize styling on the icon element, use the
icon-class attribute. This example creates an icon-only button with bare
variant and icon styling. icon-class supports SLDS utility classes only.
Use the icon-name attribute to add a utility icon to the button.
The SLDS utility icon category offers nearly 200 utility
icons for use with lightning-button-icon. You can use only the utility category with lightning-button-icon.
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.
Note
Variants
Use the variant attribute with one of these values to apply styling.
bare shows an icon without a container or border
bare-inverse shows an icon in white color without a container or border, useful for dark backgrounds
border is the default variant, an icon in a transparent container with a border
border-filled shows an icon in a filled container with a border
border-inverse shows an icon in a transparent container with a border, useful for dark backgrounds
brand shows an icon in white color in a blue container with a blue border
container shows an icon in a transparent container without a border
For the bare and bare-inverse variants, the size class applies to the icon itself. For all other variants, the size class applies to the button.
Add the disabled attribute to prevent interaction with the button icon.
Sizes
Adjust the button and icon sizes by using the size attribute with one of these values.
For bare and bare-inverse variants:
medium is the default size, which creates a 14px by 14px icon
small creates a 12px by 12px icon
x-small creates a 8px by 8px icon
large creates a 24px by 24px icon
For other variants:
medium is the default size, which creates a 32px by 32px button enclosing a 14px by 14px icon.
small creates a 24px by 24px button enclosing a 14px by 14px icon
x-small creates a 20px by 20px button enclosing a 12px by 12px icon
xx-small creates a 16px by 16px button enclosing a 8px by 8px icon
Utility Classes
To apply additional styling, use the SLDS utility classes with the class attribute.
This example adds a margin to the left of the second button by using the slds-m-left_xx-small class.
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.
lightning-button-icon contains the same customizable elements as lightning-button, which supports --slds-c-button-* custom properties. Custom properties for button icons work only with specific lightning-button-icon variants.
CSS Custom Property
lightning-button-icon Variants
--slds-c-button-color-background
border (default), bare, bare-inverse, and container
--slds-c-button-color-border
bare, bare-inverse, and container
--slds-c-button-text-color
N/A
--slds-c-button-text-color-*
border (default), bare, container, and border-filled
Icons aren’t available in Lightning Out, but they’re available in Lightning Components for Visualforce and other experiences.
Accessibility
lightning-button-icon contains an informational icon, which conveys information that surrounding text doesn’t.
For each icon, provide assistive text that describes the button’s action.
Use the alternative-text attribute to describe the icon. The description indicates what happens when you click the button, for example ‘Upload File’, not what the icon looks like, ‘Paperclip’.
The description you provide to alternative-text is available to users in two ways.
As hover text when you hover over the button
As hidden text for assistive technologies
To override the hover text provided by alternative-text, use the title attribute, which corresponds to the native browser tooltip.
The description you provide to title appears when you hover over the button. To support touch-only devices, keyboard navigation, and assistive technologies, use title together with label or alternative-text.
To show a contextual popup on the button, use the tooltip attribute.
The popup becomes visible when you hover over the button, or after the button receives keyboard focus. Showing the popup on hover or on keyboard focus makes sure that all users can access it, even if they aren’t using a mouse. The button is rendered with aria-describedby, linking it to the ID of the popup, which helps assistive technology read the popup content.
If you use both title and tooltip attributes, they’re both visible when you hover over the button. Some screen readers don’t support the title attribute and many of them don’t read the title attribute by default.
1<lightning-button-icon2 icon-name="utility:settings"3 title="Settings"4 tooltip="Display your account settings"5 alternative-text="Hidden text for assistive technology"6>7</lightning-button-icon>
For sighted users, make sure your description on title and tooltip aren’t repetitive. We recommend providing detailed information to tooltip and make title more concise if you use both.
Buttons that show an icon instead of text don’t have an accessible name. To provide an accessible name in lightning-button-icon, use the aria-label attribute. If there’s visible text for the element, use aria-labelled-by instead.
To inform screen readers that a button is disabled, set the disabled attribute to true.
Use these accessibility and aria attributes on lightning-button-icon.
Attribute
Type
Description
accesskey
string
A shortcut key to activate or place focus on the button.
aria-atomic
boolean
Specifies whether the screen reader always presents the live region as a whole, even if only part of the region changes. The default is false.
aria-controls
ID reference list
An element ID or a space-separated list of element IDs whose presence or content is controlled by this button.
aria-describedby
ID reference list
An element ID or a space-separated list of element IDs that provide descriptive labels for the button.
aria-expanded
boolean
Indicates whether a collapsible element that’s controlled by the button is expanded or collapsed. To reference the controlled element, use aria-controls.
aria-haspopup
token
Indicates that the button has an interactive popup element. Valid values are ‘true’, ‘dialog’, ‘menu’, ‘listbox’, ‘tree’, and ‘grid’. To create a button that displays a list of menu items when clicked, use lightning-button-menu instead.
aria-label
string
Provides an assistive label where a visible label can’t be used.
aria-live
token
Indicates that the button can dynamically update without a page reload, and specifies how the change is announced by assistive technologies. Possible values include off, polite, and assertive. The default is off. For the screen reader to announce changes when the user is idle, use polite. For immediate notifications, use assertive.
tabindex
integer
Specifies whether the button is focusable during tab navigation. Set the tab index to -1 to prevent focus on the button during tab navigation. The default value is 0, which makes the button focusable during tab navigation. For more information, see tabindex.
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
disable-alternative-text-title
Reserved for internal use only. Disables the alternative text being used for the button title when the title has not been provided.
boolean
false
icon-class
The class to be applied to the contained icon element. Only Lightning Design System utility classes are currently supported.
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. Only utility icons can be used in this component.
string
name
The name for the button element. This value is optional and can be used to identify the button in a callback.
string
size
The size of the button-icon. For the bare variant, options include x-small, small, medium, and large. For non-bare variants, options include xx-small, x-small, small, and medium. This value defaults to medium.
string
medium
tab-index
Reserved for internal use only. Use the global tabindex attribute instead. Set tab index to -1 to prevent focus on the button during tab navigation. The default value is 0, which makes the button focusable during tab navigation.
number
tooltip
Text to display when the user mouses over or focuses on the button. The tooltip is auto-positioned relative to the button and screen space.
string
tooltip-type
Reserved for internal use only. Specifies the type of tooltip to be used. Use info in cases where target already has click handlers. Use toggle in cases where target only shows a tooltip, such as helptext.
string
info
type
Specifies the type of button. Valid values are button, reset, and submit. This value defaults to button.
string
button
value
The value for the button element. This value is optional and can be used when submitting a form.
string
variant
The variant changes the appearance of button-icon. Accepted variants include bare, container, brand, border, border-filled, bare-inverse, and border-inverse. This value defaults to border.