Lightning Experience, Experience Builder Sites, Salesforce Mobile App, Lightning Out (Beta), Standalone Lightning App, Mobile Offline
A lightning-button-icon-stateful component represents an icon-only button
element that toggles between two states. For example, you can use this
component for capturing a customer’s feedback on a blog post (like or
dislike). Clicking the button triggers the handler set for onclick.
You can change the state of the icon by using the selected attribute.
This example creates a Like button that toggles between two states. The Like button is selected by default. The button’s state is stored in the selected attribute.
Selecting the Dislike button also toggles the state on the Like button and deselects it.
lightning-button-icon-stateful 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 icon-name, variant, size, and class attributes to
customize the button and icon styles.
Icons
Use the icon-name attribute to add a utility icon to the button.
The SLDS utility icon category offers nearly 200 utility
icons that can be used in lightning-button-icon-stateful. Although the
SLDS provides several categories of icons, only the utility
category can be used with this component.
When applying SLDS classes or icons, check that they are
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.
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
Sizes
Adjust the button and icon sizes by using the size attribute with one of these values.
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 an SLDS 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.
Icons are not available in Lightning Out, but they are available in Lightning Components for Visualforce and other experiences.
Accessibility
lightning-button-icon-stateful contains an informational icon, which conveys information that surrounding text doesn’t. Each icon should be accompanied by either assistive text.
When selected, the button renders with aria-pressed="true". When not selected, the button renders with aria-pressed="false".
The aria-pressed attribute enables screen readers to announce whether a button is pressed or not.
Use the alternative-text attribute to describe the icon.
The description should indicate what happens when you click the button, for example ‘Upload File’, not what the icon looks like, ‘Paperclip’.
The text is available to users in two ways.
On the tooltip when you hover over the button
As text for assistive technologies
Buttons that only show an icon to represent do not have an accessible name. For lightning-button-icon-stateful, provide the accessible name using the aria-label attribute.
Use the following accessibility and aria attributes on lightning-button-icon-stateful.
Attribute
Type
Description
accesskey
string
A shortcut key to activate or place focus on the button
aria-atomic
boolean
Specifies whether the screen reader should always present 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 a descriptive label or description for the button.
aria-expanded
boolean
Indicates whether the state of an element, controlled by the button, is expanded or collapsed. To reference the controlled element, use aria-controls.
aria-label
string
Provides an assistive label where a visible label cannot be used.
aria-live
string
Indicates whether the button will be updated, and describes the types of updates assistive technologies will make. 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.
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. 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
selected
Specifies whether the button is in a selected state. This value defaults to false.
boolean
size
The size of the button-icon component. Options include xx-small, x-small, small, and medium. This value defaults to medium.
string
medium
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
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 border, border-filled, and border-inverse. This value defaults to border.