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

Icon button

A compact action with room for expression. Try its shape, width, and toggle state.

FactoryWeb ComponentsReactVueSvelteSolidJS
PublishedUpdated

An icon button is a button whose whole label is its icon: for an action people recognize without words, where space is tight, as in a toolbar, an app bar or media controls. As a toggle, it holds a binary state, such as favorited or muted, and swaps its icon to show it.

Usage

ariaLabel is required: it is the button's only name.

Vanilla
import { createIconButton } from 'material';

const iconButton = createIconButton({ icon: menuIcon, ariaLabel: 'Open menu' });
iconButton.on('click', () => openMenu());
document.body.append(iconButton.element);
Web Components
<m-icon-button aria-label="Open menu"></m-icon-button>

<script type="module">
  const iconButton = document.querySelector('m-icon-button');
  iconButton.setAttribute('icon', menuIcon);
  iconButton.addEventListener('click', () => openMenu());
</script>
React
import { IconButton } from 'material/react';
import { openMenu, menuIcon } from './app';

export function Example() {
  return (
    <IconButton onClick={() => openMenu()} icon={menuIcon} ariaLabel="Open menu" />
  );
}
Vue
<script setup lang="ts">
import { MIconButton } from 'material/vue';
import { openMenu, menuIcon } from './app';
</script>

<template>
  <MIconButton @click="openMenu()" :icon="menuIcon" aria-label="Open menu" />
</template>
Svelte
<script lang="ts">
  import { IconButton } from 'material/svelte';
  import { openMenu, menuIcon } from './app';
</script>

<IconButton onclick={() => openMenu()} icon={menuIcon} ariaLabel="Open menu" />
SolidJS
import { IconButton } from 'material/solid';
import { openMenu, menuIcon } from './app';

export function Example() {
  return (
    <IconButton onClick={() => openMenu()} icon={menuIcon} ariaLabel="Open menu" />
  );
}

Examples

Variant, size, shape and width

variant sets the emphasis, from filled, tonal and outlined to standard; size runs from xs to xl, shape is round or square, and width is narrow, default or wide.

Vanilla
import { createIconButton } from 'material';

const iconButton = createIconButton({
  icon: editIcon,
  ariaLabel: 'Edit',
  variant: 'tonal',
  size: 'm',
  shape: 'square',
  width: 'wide',
});
document.body.append(iconButton.element);
Web Components
<m-icon-button variant="tonal" size="m" shape="square" width="wide" aria-label="Edit"></m-icon-button>

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

export function Example() {
  return (
    <IconButton variant="tonal" size="m" shape="square" width="wide" icon={editIcon} ariaLabel="Edit" />
  );
}
Vue
<script setup lang="ts">
import { MIconButton } from 'material/vue';
import { editIcon } from './app';
</script>

<template>
  <MIconButton variant="tonal" size="m" shape="square" width="wide" :icon="editIcon" aria-label="Edit" />
</template>
Svelte
<script lang="ts">
  import { IconButton } from 'material/svelte';
  import { editIcon } from './app';
</script>

<IconButton variant="tonal" size="m" shape="square" width="wide" icon={editIcon} ariaLabel="Edit" />
SolidJS
import { IconButton } from 'material/solid';
import { editIcon } from './app';

export function Example() {
  return (
    <IconButton variant="tonal" size="m" shape="square" width="wide" icon={editIcon} ariaLabel="Edit" />
  );
}

A toggle

With toggle, a click flips the selected state and emits change; selectedIcon is shown while selected. Make the unselected icon outlined and the selected one filled, so the state reads without the color. selectedIcon alone does not turn toggle mode on.

Vanilla
import { createIconButton } from 'material';

const iconButton = createIconButton({
  icon: heartOutlineIcon,
  selectedIcon: heartFilledIcon,
  toggle: true,
  selected: false,
  ariaLabel: 'Add to favorites',
});
iconButton.on('change', ({ selected }) => setFavorite(selected));
document.body.append(iconButton.element);
Web Components
<m-icon-button toggle aria-label="Add to favorites"></m-icon-button>

<script type="module">
  const iconButton = document.querySelector('m-icon-button');
  iconButton.setAttribute('icon', heartOutlineIcon);
  iconButton.setAttribute('selected-icon', heartFilledIcon);
  iconButton.addEventListener('change', (event) => setFavorite(event.detail.selected));
</script>
React
import { useState } from 'react';
import { IconButton } from 'material/react';
import { setFavorite, heartOutlineIcon, heartFilledIcon } from './app';

export function Example() {
  const [selected, setSelected] = useState(false);
  return (
    <IconButton selected={selected} onChange={(event) => { setSelected(event.detail.selected); setFavorite(event.detail.selected); }} icon={heartOutlineIcon} selectedIcon={heartFilledIcon} toggle ariaLabel="Add to favorites" />
  );
}
Vue
<script setup lang="ts">
import { ref } from 'vue';
import { MIconButton } from 'material/vue';
import { setFavorite, heartOutlineIcon, heartFilledIcon } from './app';

const selected = ref(false);
</script>

<template>
  <MIconButton v-model="selected" @change="setFavorite($event.detail.selected)" :icon="heartOutlineIcon" :selected-icon="heartFilledIcon" toggle aria-label="Add to favorites" />
</template>
Svelte
<script lang="ts">
  import { IconButton } from 'material/svelte';
  import { setFavorite, heartOutlineIcon, heartFilledIcon } from './app';

  let selected = $state(false);
</script>

<IconButton bind:selected onchange={(event) => setFavorite(event.detail.selected)} icon={heartOutlineIcon} selectedIcon={heartFilledIcon} toggle ariaLabel="Add to favorites" />
SolidJS
import { createSignal } from 'solid-js';
import { IconButton } from 'material/solid';
import { setFavorite, heartOutlineIcon, heartFilledIcon } from './app';

export function Example() {
  const [selected, setSelected] = createSignal(false);
  return (
    <IconButton selected={selected()} onChange={(event) => { setSelected(event.detail.selected); setFavorite(event.detail.selected); }} icon={heartOutlineIcon} selectedIcon={heartFilledIcon} toggle ariaLabel="Add to favorites" />
  );
}

Changing it

An action changes the icon and the label together.

Vanilla
import { createIconButton } from 'material';

const iconButton = createIconButton({ icon: playIcon, ariaLabel: 'Play', variant: 'filled' });
iconButton.on('click', () => playing());
document.body.append(iconButton.element);

function playing() {
  iconButton.setIcon(pauseIcon);
  iconButton.setAriaLabel('Pause');
}
Web Components
<m-icon-button variant="filled" aria-label="Play"></m-icon-button>

<script type="module">
  const iconButton = document.querySelector('m-icon-button');
  iconButton.setAttribute('icon', playIcon);
  iconButton.addEventListener('click', () => playing());

  function playing() {
    iconButton.setAttribute('icon', pauseIcon);
    iconButton.setAttribute('aria-label', "Pause");
  }
</script>
React
import { useState } from 'react';
import { IconButton } from 'material/react';
import { playIcon, pauseIcon } from './app';

export function Example() {
  const [icon, setIcon] = useState(playIcon);
  const [ariaLabel, setAriaLabel] = useState("Play");
  const playing = () => {
    setIcon(pauseIcon);
    setAriaLabel("Pause");
  };

  return (
    <IconButton onClick={() => playing()} variant="filled" icon={icon} ariaLabel={ariaLabel} />
  );
}
Vue
<script setup lang="ts">
import { ref } from 'vue';
import { MIconButton } from 'material/vue';
import { playIcon, pauseIcon } from './app';

const icon = ref(playIcon);
const ariaLabel = ref("Play");

function playing() {
  icon.value = pauseIcon;
  ariaLabel.value = "Pause";
}
</script>

<template>
  <MIconButton @click="playing()" variant="filled" :icon="icon" :aria-label="ariaLabel" />
</template>
Svelte
<script lang="ts">
  import { IconButton } from 'material/svelte';
  import { playIcon, pauseIcon } from './app';

  let icon = $state(playIcon);
  let ariaLabel = $state("Play");

  function playing() {
    icon = pauseIcon;
    ariaLabel = "Pause";
  }
</script>

<IconButton onclick={() => playing()} variant="filled" icon={icon} ariaLabel={ariaLabel} />
SolidJS
import { createSignal } from 'solid-js';
import { IconButton } from 'material/solid';
import { playIcon, pauseIcon } from './app';

export function Example() {
  const [icon, setIcon] = createSignal(playIcon);
  const [ariaLabel, setAriaLabel] = createSignal("Play");
  const playing = () => {
    setIcon(pauseIcon);
    setAriaLabel("Pause");
  };

  return (
    <IconButton onClick={() => playing()} variant="filled" icon={icon()} ariaLabel={ariaLabel()} />
  );
}

API

Options

icon

The icon, as an HTML string

Typestring
Defaultundefined
ariaLabel

Accessible name; describes the action, not the icon

Typestring
Defaultrequired
variant

Visual style, in descending order of emphasis

Type'filled' | 'tonal' | 'outlined' | 'standard'
Default'standard'
size

Container size

Type'xs' | 's' | 'm' | 'l' | 'xl'
Default's'
shape

Resting corner shape

Type'round' | 'square'
Default'round'
width

Width relative to the size's container

Type'narrow' | 'default' | 'wide'
Default'default'
toggle

Toggle mode: a click selects and deselects, and emits change

Typeboolean
Defaultfalse
selectedIcon

Icon shown while selected, in toggle mode

Typestring
Defaultundefined
selected

Whether the button starts selected; only read when toggle is true

Typeboolean
Defaultfalse
toggleOnClick

Whether a click flips the selected state; false when a container, such as a button group, owns the selection

Typeboolean
Defaulttrue
disabled

Whether the button starts disabled

Typeboolean
Defaultfalse
type

The underlying button's type attribute

Type'button' | 'submit' | 'reset'
Default'button'
value

Value attribute, for use in a form

Typestring
Defaultundefined
ripple

Whether a press shows the ripple

Typeboolean
Defaulttrue
rippleConfig

How long, in ms, a released wave lingers before it is removed

Type{ duration? }
Defaultundefined
class

Additional CSS classes

Typestring
Defaultundefined
prefix

Prefix for CSS class names

Typestring
Default'mtrl'
tooltip

Accepted but not applied: no tooltip is rendered. Use the tooltip component beside the button

Typeboolean
Defaulttrue

Methods

Content

setIcon(icon)

Replaces the icon

Parametersicon: string
ReturnsIconButtonComponent
getIcon()

The icon's HTML

Parametersnone
Returnsstring
setSelectedIcon(icon)

Replaces the selected-state icon

Parametersicon: string
ReturnsIconButtonComponent
getSelectedIcon()

The selected-state icon's HTML, or an empty string

Parametersnone
Returnsstring
setAriaLabel(label)

Sets the accessible name

Parameterslabel: string
ReturnsIconButtonComponent
setValue(value)

Sets the value attribute

Parametersvalue: string
ReturnsIconButtonComponent
getValue()

The value attribute

Parametersnone
Returnsstring

Appearance

setVariant(variant) / getVariant()

The variant

Parametersvariant: string
ReturnsIconButtonComponent / string
setSize(size) / getSize()

The size

Parameterssize: string
ReturnsIconButtonComponent / string
setShape(shape) / getShape()

The shape

Parametersshape: string
ReturnsIconButtonComponent / string
setWidth(width) / getWidth()

The width

Parameterswidth: string
ReturnsIconButtonComponent / string

State

select() / deselect()

Selects or deselects it, in toggle mode, without emitting change

Parametersnone
ReturnsIconButtonComponent
toggleSelected()

Flips the selected state

Parametersnone
ReturnsIconButtonComponent
isSelected()

Whether it is selected

Parametersnone
Returnsboolean
isToggle()

Whether toggle mode is on

Parametersnone
Returnsboolean
enable() / disable()

The disabled state

Parametersnone
ReturnsIconButtonComponent

Events, styles and lifecycle

on(event, handler) / off(event, handler)

Adds or removes a listener

Parametersevent: string, handler: Function
ReturnsIconButtonComponent
addClass(...classes) / removeClass(...classes)

Adds or removes CSS classes

Parameters...classes: string[]
ReturnsIconButtonComponent
destroy()

Takes it off the page and releases its listeners

Parametersnone
Returnsvoid
element

The button element

TypeHTMLButtonElement
icon

The icon slot: setIcon, getIcon, getElement

TypeIconAPI
disabled

The disabled feature: enable, disable, isDisabled

Typeobject
lifecycle

The lifecycle feature: destroy

Typeobject

Events

change

A click changed a toggle button's selected state

Payload{ selected, value }
click

The button was activated; not fired while disabled

Payload{ event, element, originalEvent }
focus / blur

The button took or lost focus

Payload{ event, element, originalEvent }

The web component's change carries { selected, value }.

Styling

The press morph is driven by :active, so it has no state class. The custom properties are shared with the button: --mtrl-button-shape sets the resting radius of both shapes.

.mtrl-icon-button { }
.mtrl-icon-button__icon { }
.mtrl-icon-button--filled, .mtrl-icon-button--tonal, .mtrl-icon-button--outlined,
.mtrl-icon-button--standard { }
.mtrl-icon-button--xs, .mtrl-icon-button--m, .mtrl-icon-button--l, .mtrl-icon-button--xl { }
.mtrl-icon-button--square, .mtrl-icon-button--narrow, .mtrl-icon-button--wide { }
.mtrl-icon-button--toggle, .mtrl-icon-button--selected, .mtrl-icon-button--disabled { }

.toolbar {
  --mtrl-button-shape: 12px;          /* at rest */
  --mtrl-button-shape-pressed: 8px;   /* while pressed */
  --mtrl-button-shape-selected: 12px; /* while selected */
}

Measurements

In dp. s is the default size and default width equals the container; a round button's radius is half its height.

Size Container Icon Square radius Pressed radius Narrow width Wide width
xs 32 20 12 8 28 40
s 40 24 12 8 32 52
m 56 24 16 12 48 72
l 96 32 28 16 64 128
xl 136 40 28 16 104 184