Button Icon
lightning-button-icon
A button that contains only an icon.
For Use In
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.
Here’s an example.
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.
| SLDS 1 | SLDS 2 | |
|---|---|---|
| Design | Button Icons | Button Icons |
| For Use In | Lightning Experience, Experience Builder sites, Salesforce mobile app, Lightning Out (Beta), Standalone Lightning app, Mobile Offline | Lightning Experience |
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.
Use the variant attribute with one of these values to apply styling.
bareshows an icon without a container or borderbare-inverseshows an icon in white color without a container or border, useful for dark backgroundsborderis the default variant, an icon in a transparent container with a borderborder-filledshows an icon in a filled container with a borderborder-inverseshows an icon in a transparent container with a border, useful for dark backgroundsbrandshows an icon in white color in a blue container with a blue bordercontainershows 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.
Adjust the button and icon sizes by using the size attribute with one of these values.
For bare and bare-inverse variants:
mediumis the default size, which creates a 14px by 14px iconsmallcreates a 12px by 12px iconx-smallcreates a 8px by 8px iconlargecreates a 24px by 24px icon
For other variants:
mediumis the default size, which creates a 32px by 32px button enclosing a 14px by 14px icon.smallcreates a 24px by 24px button enclosing a 14px by 14px iconx-smallcreates a 20px by 20px button enclosing a 12px by 12px iconxx-smallcreates a 16px by 16px button enclosing a 8px by 8px icon
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.
To apply custom styling, use the :host selector or define a custom class by using the class attribute.
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.
For more information, see Style Components Using Lightning Design System Styling Hooks in the Lightning Web Components Developer Guide.
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 |
--slds-c-button-radius-border | all |
--slds-c-button-sizing-border | bare, bare-inverse, border-inverse, and container |
For more information, see Style Components Using Lightning Design System Styling Hooks in the Lightning Web Components Developer Guide.
Icons aren’t available in Lightning Out, but they’re available in Lightning Components for Visualforce and other experiences.
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.
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. |
For more information, see the WAI-ARIA Specification.