2.31.0
Buttons trigger interactions throughout the experience.
That combination of options is invalid.
Use for highest-priority actions that are required to complete the user’s task.
<!-- Default -->
<button class="mds-button mds-button--primary" type="button">
Button Text
</button>
<!-- Disabled -->
<button class="mds-button mds-button--primary" type="button" disabled>
Button Text
</button>
<!-- Default -->
<mds-button variation="primary"> Button Text </mds-button>
<!-- Disabled -->
<mds-button variation="primary" disabled> Button Text </mds-button>
Use for non-critical actions.
<!-- Default -->
<button class="mds-button mds-button--secondary" type="button">
Button Text
</button>
<!-- Disabled -->
<button class="mds-button mds-button--secondary" type="button" disabled>
Button Text
</button>
<!-- Default -->
<mds-button variation="secondary"> Button Text </mds-button>
<!-- Disabled -->
<mds-button variation="secondary" disabled> Button Text </mds-button>
Use for tertiary actions.
<!-- Default -->
<button class="mds-button mds-button--flat" type="button">
Button Text
</button>
<!-- Disabled -->
<button class="mds-button mds-button--flat" type="button" disabled>
Button Text
</button>
<!-- Default -->
<mds-button variation="flat"> Button Text </mds-button>
<!-- Disabled -->
<mds-button variation="flat" disabled> Button Text </mds-button>
Add Icons to provide additional affordance or meaning to a button.
<button class="mds-button mds-button--primary" type="button">
<svg class="mds-icon mds-button__icon mds-button__icon--left" aria-hidden="true">
<use xlink:href="#open-new--s">
</use>
</svg>
<span class="mds-button__text">
Copy Document
</span>
</button>
<button class="mds-button mds-button--secondary" type="button">
<svg class="mds-icon mds-button__icon mds-button__icon--left" aria-hidden="true">
<use xlink:href="#open-new--s">
</use>
</svg>
<span class="mds-button__text">
Copy Document
</span>
</button>
<button class="mds-button mds-button--flat" type="button">
<svg class="mds-icon mds-button__icon mds-button__icon--left" aria-hidden="true">
<use xlink:href="#open-new--s">
</use>
</svg>
<span class="mds-button__text">
Copy Document
</span>
</button>
<mds-button icon="open-new--s" variation="primary"> Copy Document </mds-button>
<mds-button icon="open-new--s" variation="secondary"> Copy Document </mds-button>
<mds-button icon="open-new--s" variation="flat"> Copy Document </mds-button>
Use for toolbars and displays where words won’t comfortably fit alongside icons.
<!-- Default -->
<button class="mds-button mds-button--icon-only" type="button" aria-label="User">
<svg class="mds-icon mds-button__icon mds-button__icon--right" aria-hidden="true">
<use xlink:href="#person-padless">
</use>
</svg>
</button>
<!-- Disabled -->
<button class="mds-button mds-button--icon-only mds-button--hover" type="button" disabled>
<svg class="mds-icon mds-button__icon mds-button__icon--right">
<use xlink:href="#person-padless">
<title>User</title>
</use>
</svg>
</button>
<!-- Default -->
<mds-button variation="icon-only" icon="person-padless"> User </mds-button>
<!-- Disabled -->
<mds-button variation="icon-only" icon="person-padless" disabled> User </mds-button>
Apply the mds-button__container
class to a wrapping parent element to add standard spacing between contained buttons.
<!-- Primary & Secondary -->
<div class="mds-button__container">
<button class="mds-button mds-button--primary mds-button--small" type="button">
Submit
</button>
<button class="mds-button mds-button--secondary mds-button--small" type="button">
Save
</button>
</div>
<!-- Icon-only Buttons -->
<div class="mds-button__container">
<button class="mds-button mds-button--icon-only" type="button" aria-label="Notifications">
<svg class="mds-icon mds-button__icon mds-button__icon--left" aria-hidden="true">
<use xlink:href="#bell-padless">
</use>
</svg>
</button>
<button class="mds-button mds-button--icon-only" type="button" aria-label="Create New">
<svg class="mds-icon mds-button__icon mds-button__icon--left" aria-hidden="true">
<use xlink:href="#create-padless">
</use>
</svg>
</button>
<button class="mds-button mds-button--icon-only" type="button" aria-label="Help">
<svg class="mds-icon mds-button__icon mds-button__icon--left" aria-hidden="true">
<use xlink:href="#question-circle-padless">
</use>
</svg>
</button>
<button class="mds-button mds-button--icon-only" type="button" aria-label="My Acccount">
<svg class="mds-icon mds-button__icon mds-button__icon--left" aria-hidden="true">
<use xlink:href="#person-padless">
</use>
</svg>
</button>
</div>
<!-- Primary & Secondary -->
<div class="mds-button__container">
<mds-button variation="primary" size="small"> Submit </mds-button>
<mds-button variation="secondary" size="small"> Save </mds-button>
</div>
<!-- Icon-only Buttons -->
<div class="mds-button__container">
<mds-button variation="icon-only" icon="bell-padless" text="Notifications"></mds-button>
<mds-button variation="icon-only" icon="create-padless" text="New"></mds-button>
<mds-button variation="icon-only" icon="question-circle-padless" text="Help"></mds-button>
<mds-button variation="icon-only" icon="person-padless" text="My Account"></mds-button>
</div>
Configure button size and icon size independently within the button.
Sizing affects text size, icon size, and internal padding. The default size is medium, and you can use modifier classes or props to make the button smaller or larger.
<button class="mds-button mds-button--small mds-button--primary" type="button">
<span class="mds-button__text">
Continue
</span>
<svg class="mds-icon mds-button__icon mds-button__icon--right" aria-hidden="true">
<use xlink:href="#caret-right--s">
</use>
</svg>
</button>
<button class="mds-button mds-button--small mds-button--secondary" type="button">
<span class="mds-button__text">
Continue
</span>
<svg class="mds-icon mds-button__icon mds-button__icon--right" aria-hidden="true">
<use xlink:href="#caret-right--s">
</use>
</svg>
</button>
<button class="mds-button mds-button--small mds-button--flat" type="button">
<span class="mds-button__text">
Continue
</span>
<svg class="mds-icon mds-button__icon mds-button__icon--right" aria-hidden="true">
<use xlink:href="#caret-right--s">
</use>
</svg>
</button>
<button class="mds-button mds-button--small mds-button--icon-only" type="button">
<svg class="mds-icon mds-button__icon mds-button__icon--right">
<use xlink:href="#heart--s">
<title>Favorite</title>
</use>
</svg>
</button>
<mds-button icon-right="caret-right--s" variation="primary" size="small"> Continue </mds-button>
<mds-button icon-right="caret-right--s" variation="secondary" size="small"> Continue </mds-button>
<mds-button icon-right="caret-right--s" variation="flat" size="small"> Continue </mds-button>
<mds-button variation="icon-only" icon="heart--s" text="Favorite" size="small"></mds-button>
mds-button--large
or size="large"
to an icon-only button.Icon size is predetermined and applied automatically to with icon and icon-only buttons. To avoid undesirable scaling of icon artwork, use the chart below to choose the correct icon size to use in your button.
Type
|
Small Button
|
Medium Button
|
Large Button
|
Touch Button
|
---|---|---|---|---|
Primary |
||||
Secondary |
||||
Flat |
Small OR Default Icon* |
|||
Icon Only |
— |
* Default size icon may be used within the medium flat button by applying the mds-button--flat-icon-m
modifier class to the block level.
Class
|
Applies to
|
Outcome
|
---|---|---|
|
|
Applies base button styles to an element. Always couple with a variant for semantics, though a standalone |
|
|
Shows primary button, to be coupled with |
|
|
Shows secondary button, to be coupled with |
|
|
Shows tertiary button, to be coupled with |
|
|
Applies the icon-only styles to a button element. Specifically, it removes the border strokes and background treatments found on primary and secondary buttons. |
|
|
Adjusts styling to render a small button. |
|
|
Adjusts styling to render a large button. |
|
|
Adjusts styling to render a touch button. |
|
|
Positions an icon to the left of a button label. |
|
|
Positions an icon to the right of a button label. |
|
|
Applies default size to the icon in a medium flat button. Never apply this class when using a small icon. |
Use this mixin to create media queries in your product styles to switch buttons to their touch variation.
@include mds-button-touch-properties();
For example, switching to the touch variation on screens with a max-width
of 500px
:
// Your product SCSS
@media screen and (max-width: 500px) {
@include mds-button-touch-properties();
}
size
and icon
props.max-width
, pointer: coarse
is another helpful method for targeting touch screen devices.When setting props as attributes on a custom HTML element, use kebab-case
instead of camelCase
.
Prop
|
Type
|
Validation
|
Default
|
Description
|
---|---|---|---|---|
|
String |
— |
— |
A space-separated list of class names that will be appended to the default |
|
String |
— |
— |
A space-separated list of element |
|
Boolean |
Only valid when |
|
Sets the |
|
Boolean |
— |
|
If |
|
String |
— |
— |
If provided, overrides |
|
String |
One of: |
— |
A string containing a valid MDS icon name. If |
|
String |
One of: |
— |
A string containing a valid MDS icon name. When passed, this prop will render an icon to the right of the button’s text. |
|
String |
Required when |
— |
Sets the |
|
String |
One of: |
|
Alters the size of the button. |
|
String |
Required |
— |
The text that appears in the button. Can also be passed via the default slot. |
|
String |
One of: |
|
Sets the HTML element for the button. |
|
String |
Required when |
— |
Sets the |
|
String |
One of: |
|
Sets the button variation. |
Pass text in between the <mds-button></mds-button>
tags to set the button’s text. This can be overridden with the text
prop.
aria-label
for Icon-Only ButtonsButtons using the icon-only
variation will automatically use their text
content as the element’s aria-label
. Icon-only buttons without text
prop content will trigger a validation warning and use undefined
as their aria-label
.
Setting size
and variation
via props. Using the default slot for text
content:
<mds-button size="large" variation="primary"> Contact Us </mds-button>
Setting variation
, icon
, and text
via props:
<mds-button variation="icon-only" icon="bell" text="Notifications"></mds-button>
Setting variation
and icon
via props. Using the default slot for text
content:
<mds-button variation="secondary" icon="person-plus--s"> Add Client </mds-button>
Setting icon
and iconRight
via props. Using the default slot for text
content:
<mds-button icon="gear--s" icon-right="caret-down--s"> Settings </mds-button>
When pairing buttons together, you’ll find that the extra space around inline-block
elements makes it difficult to add precise spaces between them. Remove this space by adding font-size: 0;
to the button’s parent container.
On touch screens, :hover
states “stick” after tapping an interactive element. To counter this behavior, MDS provides a mixin that resets component hover states to their default styles:
@include mds-sticky-hover-reset();
The mixin uses a media query based on hover: none
to target touch screen devices and includes resets for Buttons, Checkboxes, Inputs, List Groups, Radio Buttons, Search Fields, Selects, Switches, and Textareas. You can apply this mixin within your product’s media queries along with other MDS touch styles, for example:
// Your product SCSS
@media screen and (max-width: 500px) {
@include mds-sticky-hover-reset();
@include mds-componentName-touch-properties();
// The rest of your product’s responsive/touch styles...
}
box-shadow
property to create an outline. Internet Explorer and Safari have known issues rendering these outlines when using the browser's zoom functionality. This visual defect doesn't affect the functionality of the component.<button>
element type when displaying buttons.<a>
element cannot be triggered from a spacebar
press, only from an enter
or return
press.spacebar
, enter
, or return
.aria-label
attribute on the button tag to describe the button’s intent for icon-only buttons. See Iconography accessibility section.