Search
MaterialComponentsDocs
Components overviewApp barBadgeButtonsButton groupButtonExtended FABFAB menuFABIcon buttonSplit buttonCardCarouselCheckboxChipsDate & time pickersDate pickerTime pickerDialogDividerListLoading & progressLoading indicatorProgressMenuNavigationNavigation barNavigation drawerNavigation railRadio buttonsSearchSelectSheetsBottom sheetSide sheetSliderSnackbarSwitchTabsText fieldToolbarTooltip

Button

One action, many expressions. Find the right fit for yours.

BackEditNext
FactoryWeb ComponentsReactVueSvelteSolidJS
PublishedUpdated

A button lets people take an action with one tap: save, send, add to cart. M3 has five, from most to least emphasis: filled for the one main action, tonal, elevated, outlined, and text for the least.

Usage

Vanilla
import { createButton } from 'material';

const button = createButton({ text: 'Save' });
button.on('click', () => save());
document.body.append(button.element);
Web Components
<m-button>Save</m-button>

<script type="module">
  const button = document.querySelector('m-button');
  button.addEventListener('click', () => save());
</script>
React
import { Button } from 'material/react';
import { save } from './app';

export function Example() {
  return (
    <Button onClick={() => save()}>Save</Button>
  );
}
Vue
<script setup lang="ts">
import { MButton } from 'material/vue';
import { save } from './app';
</script>

<template>
  <MButton @click="save()">Save</MButton>
</template>
Svelte
<script lang="ts">
  import { Button } from 'material/svelte';
  import { save } from './app';
</script>

<Button onclick={() => save()}>Save</Button>
SolidJS
import { Button } from 'material/solid';
import { save } from './app';

export function Example() {
  return (
    <Button onClick={() => save()}>Save</Button>
  );
}

Examples

Emphasis, size and shape

variant sets the emphasis, size runs from xs to xl, and shape is round (a pill) or square (corners that grow with the size).

Vanilla
import { createButton } from 'material';

const button = createButton({ text: 'Discard', variant: 'outlined', size: 'm', shape: 'square' });
document.body.append(button.element);
Web Components
<m-button variant="outlined" size="m" shape="square">Discard</m-button>
React
import { Button } from 'material/react';

export function Example() {
  return (
    <Button variant="outlined" size="m" shape="square">Discard</Button>
  );
}
Vue
<script setup lang="ts">
import { MButton } from 'material/vue';
</script>

<template>
  <MButton variant="outlined" size="m" shape="square">Discard</MButton>
</template>
Svelte
<script lang="ts">
  import { Button } from 'material/svelte';
</script>

<Button variant="outlined" size="m" shape="square">Discard</Button>
SolidJS
import { Button } from 'material/solid';

export function Example() {
  return (
    <Button variant="outlined" size="m" shape="square">Discard</Button>
  );
}

An icon

An icon goes with the label or alone. Alone, the button needs ariaLabel to name it.

Vanilla
import { createButton } from 'material';

const button = createButton({ text: 'Add to cart', variant: 'tonal', icon: addIcon });
document.body.append(button.element);
Web Components
<m-button variant="tonal">Add to cart</m-button>

<script type="module">
  const button = document.querySelector('m-button');
  button.setAttribute('icon', addIcon);
</script>
React
import { Button } from 'material/react';
import { addIcon } from './app';

export function Example() {
  return (
    <Button variant="tonal" icon={addIcon}>Add to cart</Button>
  );
}
Vue
<script setup lang="ts">
import { MButton } from 'material/vue';
import { addIcon } from './app';
</script>

<template>
  <MButton variant="tonal" :icon="addIcon">Add to cart</MButton>
</template>
Svelte
<script lang="ts">
  import { Button } from 'material/svelte';
  import { addIcon } from './app';
</script>

<Button variant="tonal" icon={addIcon}>Add to cart</Button>
SolidJS
import { Button } from 'material/solid';
import { addIcon } from './app';

export function Example() {
  return (
    <Button variant="tonal" icon={addIcon}>Add to cart</Button>
  );
}

Disabled while it works

An action changes the button: here its label and disabled.

Vanilla
import { createButton } from 'material';

const button = createButton({ text: 'Send' });
button.on('click', () => sending());
document.body.append(button.element);

function sending() {
  button.setText('Sending');
  button.disable();
}
Web Components
<m-button>Send</m-button>

<script type="module">
  const button = document.querySelector('m-button');
  button.addEventListener('click', () => sending());

  function sending() {
    button.textContent = "Sending";
    button.toggleAttribute('disabled', true);
  }
</script>
React
import { useState } from 'react';
import { Button } from 'material/react';

export function Example() {
  const [text, setText] = useState("Send");
  const [disabled, setDisabled] = useState(false);
  const sending = () => {
    setText("Sending");
    setDisabled(true);
  };

  return (
    <Button onClick={() => sending()} disabled={disabled}>{text}</Button>
  );
}
Vue
<script setup lang="ts">
import { ref } from 'vue';
import { MButton } from 'material/vue';

const text = ref("Send");
const disabled = ref(false);

function sending() {
  text.value = "Sending";
  disabled.value = true;
}
</script>

<template>
  <MButton @click="sending()" :disabled="disabled">{{ text }}</MButton>
</template>
Svelte
<script lang="ts">
  import { Button } from 'material/svelte';

  let text = $state("Send");
  let disabled = $state(false);

  function sending() {
    text = "Sending";
    disabled = true;
  }
</script>

<Button onclick={() => sending()} disabled={disabled}>{text}</Button>
SolidJS
import { createSignal } from 'solid-js';
import { Button } from 'material/solid';

export function Example() {
  const [text, setText] = createSignal("Send");
  const [disabled, setDisabled] = createSignal(false);
  const sending = () => {
    setText("Sending");
    setDisabled(true);
  };

  return (
    <Button onClick={() => sending()} disabled={disabled()}>{text()}</Button>
  );
}

The factory can also show progress in the icon slot (progress, setProgress(), setLoading()); the web component does not take it yet. A button created with loading: true is busy from the start — the loading state shows immediately, including on server-rendered buttons, and setLoading(true) disables it synchronously, before the progress chunk arrives. The lazily created progress instance is exposed as progress, so the public progress API controls the displayed indicator. An optional lean stylesheet, material/styles/button-filled-small-round, covers buttons configured variant: 'filled', size: 's' and shape: 'round'; other variants, sizes or shapes, including changes through setters, need material/styles/button. Recipes built on buttons, such as an upload with progress, a form submission or a multi-step process, are planned for Showcase.

API

Options

variant

Visual style of the button (filled, outlined, text, elevated, tonal)

Typestring
Default'filled'
size

Size of the button (xs, s, m, l, xl)

Typestring
Default's'
shape

Shape of the button (round, square)

Typestring
Default'round'
disabled

Whether the button is initially disabled

Typeboolean
Defaultfalse
text

Text content displayed inside the button

Typestring
Defaultundefined
icon

HTML content (typically SVG) for the button icon

Typestring
Defaultundefined
iconSize

Accepted but not applied. The value is appended to a CSS class (mtrl-icon--<value>) rather than used as a length, and the stylesheet defines no such modifier, so it has no effect. Size the icon from your own CSS, or size the SVG itself

Typestring
Defaultundefined
class

Additional CSS classes to add to the button

Typestring
Defaultundefined
value

Button value attribute

Typestring
Defaultundefined
type

Button type attribute (button, submit, reset)

Typestring
Default'button'
ripple

Whether a press shows the ripple, which is the pressed state layer (0.10) as in Compose; without it, a static 0.10 layer shows the press

Typeboolean
Defaulttrue
prefix

Prefix for CSS class names

Typestring
Default'mtrl'
rippleConfig

How long, in ms, a released wave lingers before it is removed: the wave is the 0.10 pressed state layer, drawn by the stylesheet

Type{ duration? }
Defaultundefined
ariaLabel

ARIA label for accessibility (important for icon-only buttons)

Typestring
Defaultundefined
progress

Progress indicator configuration

Typeboolean|object
Defaultundefined
showProgress

Whether to show progress initially

Typeboolean
Defaultfalse
loading

Creates the button busy: the loading state shows from the start, including server-rendered buttons

Typeboolean
Defaultfalse

Methods

Value Methods

getValue()

Gets the button's current value attribute

Parametersnone
Returnsstring
setValue(value)

Sets the button's value attribute

Parametersvalue: string
ReturnsButtonComponent

State Methods

enable()

Enables the button, making it interactive

Parametersnone
ReturnsButtonComponent
disable()

Disables the button, making it non-interactive

Parametersnone
ReturnsButtonComponent
setActive(active)

Sets the active state of the button (e.g., when a related menu is open)

Parametersactive: boolean
ReturnsButtonComponent

Variant Methods

setVariant(variant)

Changes the button's visual style variant

Parametersvariant: string
ReturnsButtonComponent
getVariant()

Gets the button's current variant

Parametersnone
Returnsstring

Size Methods

setSize(size)

Sets the button's size (xs, s, m, l, xl)

Parameterssize: string
ReturnsButtonComponent
getSize()

Gets the button's current size

Parametersnone
Returnsstring

Shape Methods

setShape(shape)

Sets the button's shape (round, square)

Parametersshape: string
ReturnsButtonComponent
getShape()

Gets the button's current shape

Parametersnone
Returnsstring

Content Methods

setText(content)

Sets the button's text content

Parameterscontent: string
ReturnsButtonComponent
getText()

Gets the button's current text content

Parametersnone
Returnsstring
setIcon(icon)

Sets the button's icon HTML content (empty string removes icon)

Parametersicon: string
ReturnsButtonComponent
getIcon()

Gets the button's current icon HTML content

Parametersnone
Returnsstring
hasIcon()

Checks if the button has an icon

Parametersnone
Returnsboolean
setAriaLabel(label)

Sets the button's aria-label attribute for accessibility

Parameterslabel: string
ReturnsButtonComponent

Progress Methods (when progress is configured)

showProgress()

Shows the progress indicator

Parametersnone
ReturnsPromise<ButtonComponent>
showProgressSync()

Shows the progress indicator synchronously

Parametersnone
ReturnsButtonComponent
hideProgress()

Hides the progress indicator

Parametersnone
ReturnsPromise<ButtonComponent>
hideProgressSync()

Hides the progress indicator synchronously

Parametersnone
ReturnsButtonComponent
setProgress(value)

Sets progress value (0-100)

Parametersvalue: number
ReturnsPromise<ButtonComponent>
setProgressSync(value)

Sets progress value synchronously

Parametersvalue: number
ReturnsButtonComponent
setIndeterminate(indeterminate)

Sets indeterminate mode

Parametersindeterminate: boolean
ReturnsPromise<ButtonComponent>
setIndeterminateSync(indeterminate)

Sets indeterminate mode synchronously

Parametersindeterminate: boolean
ReturnsButtonComponent
setLoading(loading, text?)

Shows progress and disables the button; restores the previous text on false unless new text is given

Parametersloading: boolean, text?: string
ReturnsPromise<ButtonComponent>
setLoadingSync(loading, text?)

The same, without awaiting the lazy progress import

Parametersloading: boolean, text?: string
ReturnsButtonComponent

Event Methods

on(event, handler)

Adds an event listener

Parametersevent: string, handler: Function
ReturnsButtonComponent
off(event, handler)

Removes an event listener

Parametersevent: string, handler: Function
ReturnsButtonComponent

Style Methods

addClass(...classes)

Adds CSS classes to the button element

Parameters...classes: string[]
ReturnsButtonComponent

Lifecycle Methods

destroy()

Destroys the button component and cleans up resources

Parametersnone
Returnsvoid

Events

click

Fires when the button is clicked

Payload{ event, element, originalEvent }
focus

Fires when the button receives focus

Payload{ event, element, originalEvent }
blur

Fires when the button loses focus

Payload{ event, element, originalEvent }

event and originalEvent are the same DOM event; element is the button element. Handlers are not called while the button is disabled.

Styling

The custom property reaches the factory's button and the web component alike; the classes are the factory's, inside the web component's shadow root.

.mtrl-button { }
.mtrl-button--filled, .mtrl-button--tonal, .mtrl-button--elevated,
.mtrl-button--outlined, .mtrl-button--text { }
.mtrl-button--xs, .mtrl-button--s, .mtrl-button--m, .mtrl-button--l, .mtrl-button--xl { }
.mtrl-button--square { }
.mtrl-button__icon, .mtrl-button__text { }
.mtrl-button--progress, .mtrl-button__progress { }

.checkout {
  --mtrl-button-shape: 8px;  /* the corner radius */
}

Measurements

Size Height
xs 32dp
s (default) 40dp
m 56dp
l 96dp
xl 136dp