Button
- Styles
- Buttons with Icons
- Buttons with Images
- Disabled
- Focus
- Keyboard Usage
- Best Practices
- Related Components
The Button component allows users to perform actions. It comes in several different style variants, and supports icons as well as text labels.
Styles
The following variants can be used to distinguish between actions of different importance in the UI:
Variant | Usage recommendations |
---|---|
Primary |
|
Secondary |
|
Tertiary |
|
Danger / Error Variants
A style for distinguishing actions related to dangers, warnings, or errors.
Use this style for:
-
Dangerous actions, such as those that lose or destroy data.
-
Primary danger buttons should only be used when the dangerous action is the most likely action, such as the affirmative Delete action in a deletion confirmation dialog.
-
Secondary and Tertiary variants can also be used for actions related to current errors, such as resolving them or viewing their details.
Size Variants
The following size variants are available for Button instances whose size needs to be different from the default:
Variant | Usage recommendations |
---|---|
Large | For important call-to-action buttons, where more emphasis is needed. |
Normal | Default size. |
Small | Compact option for cramped parts of the UI, if a Tertiary variant isn’t deemed appropriate. |
Tip
|
Default button size can be customized
Size variants should only be used in special cases.
See Size and Space for details on how to change the default button size.
|
Miscellaneous Style Variants
The Tertiary Inline variant omits all white space around the label. This can be useful for embedding a Button as part of text content or another component. It shouldn’t be confused with a Link, however.
The Success and Contrast variants should provide additional color options for buttons.
The Tertiary + Contrast combination should be avoided because of its similarity to non-interactive text elements.
Tip
|
Default button colors can be customized
The standard Button colors can be adjusted using theme features. Therefore, these variants shouldn’t be used to replace standard buttons only to achieve a different color.
|
Buttons with Icons
Buttons can have icons instead of text, or on either side of the text:
Usage recommendations:
-
Use icons sparingly. Most actions are difficult to represent reliably with icons, and the benefit of icons plus text should be weighed against the visual clutter this creates.
-
Icon-only buttons should be primarily used for common recurring actions with highly standardized, universally understood icons, such as, a cross for close, and for actions that are repeated, such as in lists and tables.
-
Icon-only buttons should provide a textual alternative for screen readers using the
aria-label
attribute. See the first two buttons in the demo above for an example. -
Additionally tooltips can be added to provide a description of the action that the button triggers. See the Close button in the demo above for an example.
Note
|
Icon-only button style variant
Use the icon / LUMO_ICON theme variant on icon-only buttons to reduce the white space on either side of the icon.
The Flow Button component automatically applies the icon variant if the icon is the only child of the component.
|
Disabled
Buttons representing actions that aren’t currently available to the user should be either hidden or disabled. A disabled button is rendered as "dimmed", and is excluded from the focus order. This may be useful when you don’t want interactive UI elements to receive the focus using the tab key.
Hidden vs Disabled
Hiding an unavailable action entirely is often preferable to a disabled button, as this reduces UI clutter. However, in certain situations this can be problematic:
-
If the user expects a button to be present, such as at the end of a form, hiding the button can cause confusion, even if the form clearly shows the presence of one or more invalid fields.
-
As a hidden button doesn’t occupy any space in the UI, toggling its visibility can cause unwanted changes in the layout of other elements.
Showing an Error on Click
As an alternative to hiding or disabling buttons, unavailable actions can instead be configured to show an error message when the button is clicked by using a Notification or an adjacent inline text element. This approach is the most accessible option, but may be frustrating to users who expect unavailable actions to be distinguished somehow from available actions.
Prevent Multiple Clicks
Buttons can be configured to become disabled automatically when clicked.
This can be useful especially for actions that take a bit longer to perform. Not only does this avoid the need for special handling of clicks while the action is in progress, but it also communicates to the user that the action was received successfully and is being processed.
Focus
Similar to input fields, the focus ring is only rendered when the button is focused by keyboard or programmatically.
Best Practices
Button Labels
-
The label should describe the action, preferably using active verbs, such as "View Details" rather than "Details".
-
In cases of possible ambiguity, also specify the object of the verb, such as "Save Changes" instead of "Save".
-
Button groups representing options, such as the buttons of a Confirm Dialog, should state what each option represents, such as "Save Changes", instead of "Yes", as the latter requires the user to read the question being asked, and increases the risk of selecting the wrong option.
-
Keep labels short, ideally less than three words or 25 characters.
-
Use ellipsis (…) when an action is not immediate but requires more steps to complete. This is useful, for example, for destructive actions like "Delete…" when a Confirm Dialog is used to confirm the action before it’s executed.
ARIA Labels
The aria-label
attribute can be used to provide a separate label for accessibility technologies (AT), such as screen readers.
This is important, for example, for icon-only buttons that lack a visible label.
Buttons with regular, visible labels can also benefit from separate aria-label
to provide more context that may otherwise be difficult for the AT user to perceive.
In the example below, the buttons' aria-label
specifies which email address is removed:
Buttons in Forms
-
Buttons should be placed below the form with which they are associated.
-
Buttons should be aligned left.
-
Primary action should be first, followed by other actions, in order of importance.
Buttons in Dialogs
-
Buttons should be placed at the bottom of the dialog.
-
Buttons should be aligned right.
-
Primary action should be last, preceded by other actions.
-
Dangerous actions should be aligned left, to avoid accidental clicks, especially if no confirmation step is included.
Global vs. Selection-Specific Actions
In lists of selectable items — such as in a Grid — that provide actions applicable to the selected item, buttons for selection-specific actions should be placed apart from global, non-selection-specific actions. They should be located preferably below the list of selectable items. In the example below, the global Add User action is separated from the selection-specific actions below the Grid: