For Aura components only. For LWC development, use lightning-button.
For Use In
Lightning Experience, Experience Builder Sites, Salesforce Mobile App, Lightning Out (Beta), Standalone Lightning App, Mobile Offline
A lightning:button component represents a button element that executes an action in a controller. Use lightning:button where users need to:
submit or reset a form
begin a new task
trigger a new UI element to appear on the page
specify a new or next step in a process
Use the type attribute to specify button, submit, or reset. The default type is button and doesn’t need to be specified.
The submit and reset types create buttons for submitting and resetting form data. Use these button types in lightning:recordEditForm and the HTML form element. The reset type button only deletes the values in the form fields without interacting with the database. For information about resetting the form fields to their initial values, see lightning:recordEditForm.
For the default button, clicking the button triggers the click event. Use an onclick handler to perform the button’s action.
Use the variant and class attributes to apply additional styling.
base is a button without a border, which gives it the look of a plain text link.
neutral is the default variant, a plain uncolored button.
brand is a blue button, used to draw attention to the primary action on a page.
brand-outline is similar to brand but only the label and border are blue.
destructive is a red button used to warn users that its action has a negative effect.
destructive-text is similar to destructive but only the label and border are red.
inverse uses the background color and light text, useful for dark backgrounds.
success is a green button used to indicate a successful action.
You can also apply utility classes with the class attribute.
You can create a button with a label only, or add the iconName attribute for a button with a label and icon. For an icon-only button, use lightning:buttonIcon instead.
You can also set the stretch attribute to true to expand the button to the full available width. In this example, the button stretches horizontally to fit the full <div> container.
The Lightning Design System utility icon category provides nearly 200 utility icons that can be used in lightning:button along with label text. Although SLDS provides several categories of icons, only the utility category can be used in this component.
This component implements styling from buttons in the Lightning Design System.
Here’s an example that creates a button with the brand variant, and displays label text on the button. The title attribute provides tooltip text for the button.
Here’s another example that creates a button with the brand variant, with a label and icon. The icon is positioned to the left of the label by default, so the example uses iconPosition to display it on the right.
You can retrieve the button that’s clicked by using event.getSource(). For example, to retrieve the label on the button, use event.getSource().get("v.label").
Usage Considerations
To create an icon-only button, use the lightning:buttonIcon component instead. Creating an icon-only button using lightning:button results in additional spacing next to the icon. To create a button that triggers a menu, use lightning:buttonMenu.
Icons are not available in Lightning Out, but they are available in Lightning Components for Visualforce and other experiences.
If you’re creating forms to interact with Salesforce records, consider using lightning:recordForm or lightning:recordEditForm.
Accessibility
Buttons must have an accessible name to enable assistive technology to describe the button’s purpose. Provide this name using the label attribute and make it a clear call to action, for example, “Edit record”.
If you create an icon-only button using lightning-button, provide an accessible name using the ariaLabel attribute, which provides a text label that’s not visible on the screen.
To use ariaLabel with additional descriptive text, use ariaDescribedBy.
1<lightning:button2 ariaLabel="Close"3 ariaDescribedBy="descriptionClose"4 iconName="utility:close"5 variant="base"6/>78<div id="descriptionClose">9 Closing this window resets the form and returns you back to the main page.10</div>
To inform screen readers that a button is disabled, set the disabled attribute to true.
lightning:button supports some aria attributes for accessibility. See the Specifications tab.
Specifies a shortcut key to activate or focus an element.
String
ariaAtomic
Indicates whether assistive technologies present all, or only parts of, the changed region. Valid values are 'true' or 'false'.
String
ariaControls
A space-separated list of element IDs whose presence or content is controlled by this button.
String
ariaDescribedBy
A space-separated list of element IDs that provide descriptive labels for the button.
String
ariaExpanded
Indicates whether an element the button controls is expanded or collapsed. Valid values are 'true' or 'false'.
String
ariaHasPopup
Indicates that the button has an interactive popup element. Valid values are 'true', 'false', 'menu', 'listbox', 'tree', 'grid', or 'dialog'.
String
ariaLabel
Label describing the button to assistive technologies.
String
ariaLive
Indicates that the button can be updated when it doesn't have focus. Valid values are 'polite', 'assertive', or 'off'. The polite value causes assistive technologies to notify users of updates at a low priority, generally without interrupting. The assertive value causes assistive technologies to notify users immediately, potentially clearing queued speech updates.
String
body
The body of the component. In markup, this is everything in the body of the tag.
Aura.Component[]
disabled
Specifies whether this button should be displayed in a disabled state. Disabled buttons can't be clicked. This value defaults to false.
Boolean
false
iconName
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
iconPosition
Describes the position of the icon with respect to body. Options include left and right. This value defaults to left.
String
left
label
The text to be displayed inside the button.
String
name
The name for the button element. This value is optional and can be used to identify the button in a callback.
String
onblur
The action triggered when the element releases focus.
Aura.Action
onclick
The action triggered when the button is clicked.
Aura.Action
onfocus
The action triggered when the element receives focus.
Aura.Action
stretch
Setting it to true allows the button to take up the entire available width.
Boolean
false
tabindex
Specifies the tab order of an element when the Tab key is used for navigating. The tabindex value can be set to 0 or -1. The default is 0, which means that the component is focusable and participates in sequential keyboard navigation. -1 means that the component is focusable but does not participate in keyboard navigation.
Integer
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 the button. Accepted variants include base, neutral, brand, brand-outline, destructive, destructive-text, inverse, and success. This value defaults to neutral.