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.

1<template>
2    <lightning-button-icon
3        icon-name="utility:close"
4        variant="bare"
5        onclick={handleClick}
6        alternative-text="Close window"
7    >
8    </lightning-button-icon>
9</template>

Design 

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 1SLDS 2
DesignButton IconsButton Icons
For Use InLightning Experience, Experience Builder sites, Salesforce mobile app, Lightning Out (Beta), Standalone Lightning app, Mobile OfflineLightning Experience

Component Styling 

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.

1<lightning-button-icon
2    icon-name="utility:settings"
3    variant="bare"
4    alternative-text="Settings"
5    icon-class="slds-m-around_medium"
6>
7</lightning-button-icon>

Icons 

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.

1<lightning-button-icon
2    icon-name="utility:zoomin"
3    alternative-text="Zoom in"
4    title="Zoom in"
5></lightning-button-icon>
6<lightning-button-icon
7    icon-name="utility:zoomout"
8    alternative-text="Zoom out"
9    title="Zoom out"
10    class="slds-m-left_xx-small"
11></lightning-button-icon>

To apply custom styling, use the :host selector or define a custom class by using the class attribute.

1<lightning-button-icon
2    icon-name="utility:zoomin"
3    alternative-text="Zoom in"
4    title="Zoom in"
5    class="my-round-button"
6></lightning-button-icon>

Styling Hooks 

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 Propertylightning-button-icon Variants
--slds-c-button-color-backgroundborder (default), bare, bare-inverse, and container
--slds-c-button-color-borderbare, bare-inverse, and container
--slds-c-button-text-colorN/A
--slds-c-button-text-color-*border (default), bare, container, and border-filled
--slds-c-button-radius-borderall
--slds-c-button-sizing-borderbare, 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.

Usage Considerations 

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-icon
2    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.

AttributeTypeDescription
accesskeystringA shortcut key to activate or place focus on the button.
aria-atomicbooleanSpecifies 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-controlsID reference listAn element ID or a space-separated list of element IDs whose presence or content is controlled by this button.
aria-describedbyID reference listAn element ID or a space-separated list of element IDs that provide descriptive labels for the button.
aria-expandedbooleanIndicates whether a collapsible element that’s controlled by the button is expanded or collapsed. To reference the controlled element, use aria-controls.
aria-haspopuptokenIndicates 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-labelstringProvides an assistive label where a visible label can’t be used.
aria-livetokenIndicates 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.
tabindexintegerSpecifies 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.

Attributes 

NameDescriptionTypeDefaultRequired
alternative-textThe 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-titleReserved for internal use only. Disables the alternative text being used for the button title when the title has not been provided.booleanfalse
icon-classThe class to be applied to the contained icon element. Only Lightning Design System utility classes are currently supported.string
icon-nameThe 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
nameThe name for the button element. This value is optional and can be used to identify the button in a callback.string
sizeThe 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.stringmedium
tab-indexReserved 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
tooltipText 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-typeReserved 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.stringinfo
typeSpecifies the type of button. Valid values are button, reset, and submit. This value defaults to button.stringbutton
valueThe value for the button element. This value is optional and can be used when submitting a form.string
variantThe 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.stringborder

Methods 

NameDescriptionArgument NameArgument TypeArgument Description
clickSimulates a mouse click on the button.
focusSets focus on the button.