Skip to content

Material 3

Components

Icon button

Icon buttons help people take actions with a single tap.

9:30

Moraine Lake

An icon button is a button with an icon and no label. Icon buttons are typically placed in places like:

For an action that needs a visible label, use a button instead.

import { Icon, IconButton } from '@material-web/react'

Basic icon button

Write the icon as the button's child. An icon button has no visible text, so an aria-label or an aria-labelledby is required.

import { Icon, IconButton } from '@material-web/react'

export default function Basic() {
  return (
    <>
      <IconButton aria-label="Search">
        <Icon name="search" />
      </IconButton>
      <IconButton variant="tonal" aria-label="Share">
        <Icon name="share" />
      </IconButton>
      <IconButton variant="filled" aria-label="Send message">
        <Icon name="send" className="rtl:icon-mirrored" />
      </IconButton>
    </>
  )
}

The IconButton comes in four variants. Set variant to filled, tonal, outlined or standard (the default), from the most emphasis to the least.

import { Icon, IconButton } from '@material-web/react'

export default function Variants() {
  return (
    <>
      <IconButton variant="filled" aria-label="Edit, filled">
        <Icon name="edit" />
      </IconButton>
      <IconButton variant="tonal" aria-label="Edit, tonal">
        <Icon name="edit" />
      </IconButton>
      <IconButton variant="outlined" aria-label="Edit, outlined">
        <Icon name="edit" />
      </IconButton>
      <IconButton variant="standard" aria-label="Edit, standard">
        <Icon name="edit" />
      </IconButton>
    </>
  )
}

Each variant is shown below enabled, disabled with isDisabled, and as a link with elementType="a". A disabled button cannot be pressed or focused.

Filled icon button

A filled icon button is for visual impact and key actions that require high emphasis. Use it sparingly.

import { Icon, IconButton } from '@material-web/react'

export default function Filled() {
  return (
    <>
      <IconButton variant="filled" aria-label="Edit">
        <Icon name="edit" />
      </IconButton>
      <IconButton variant="filled" aria-label="Edit, disabled" isDisabled>
        <Icon name="edit" />
      </IconButton>
      <IconButton variant="filled" elementType="a" href="#filled-icon-button" aria-label="Link">
        <Icon name="link" />
      </IconButton>
    </>
  )
}

Tonal icon button

A tonal icon button is a middle ground between filled and outlined, useful for a secondary action paired with a high emphasis one.

import { Icon, IconButton } from '@material-web/react'

export default function Tonal() {
  return (
    <>
      <IconButton variant="tonal" aria-label="Edit">
        <Icon name="edit" />
      </IconButton>
      <IconButton variant="tonal" aria-label="Edit, disabled" isDisabled>
        <Icon name="edit" />
      </IconButton>
      <IconButton variant="tonal" elementType="a" href="#tonal-icon-button" aria-label="Link">
        <Icon name="link" />
      </IconButton>
    </>
  )
}

Outlined icon button

An outlined icon button is for medium emphasis, when the button is not the main focus of the interaction.

import { Icon, IconButton } from '@material-web/react'

export default function Outlined() {
  return (
    <>
      <IconButton variant="outlined" aria-label="Edit">
        <Icon name="edit" />
      </IconButton>
      <IconButton variant="outlined" aria-label="Edit, disabled" isDisabled>
        <Icon name="edit" />
      </IconButton>
      <IconButton variant="outlined" elementType="a" href="#outlined-icon-button" aria-label="Link">
        <Icon name="link" />
      </IconButton>
    </>
  )
}

Standard icon button

A standard icon button is for low emphasis, or for buttons placed on a colorful surface. It has no container.

import { Icon, IconButton } from '@material-web/react'

export default function Standard() {
  return (
    <>
      <IconButton variant="standard" aria-label="Edit">
        <Icon name="edit" />
      </IconButton>
      <IconButton variant="standard" aria-label="Edit, disabled" isDisabled>
        <Icon name="edit" />
      </IconButton>
      <IconButton variant="standard" elementType="a" href="#standard-icon-button" aria-label="Link">
        <Icon name="link" />
      </IconButton>
    </>
  )
}

Icons

Any icon works as the button's child: Icon, an icon from an SVG library, or your own component. Give an icon that is not an Icon the size listed under Sizes, as size-6 and size-8 do in this example. See Composition.

import { IconButton } from '@material-web/react'

function Heart({ className }: { className?: string }) {
  return (
    <svg viewBox="0 0 24 24" fill="currentColor" aria-hidden="true" className={className}>
      <path d="m12 21.35-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54z" />
    </svg>
  )
}

export default function SvgIcon() {
  return (
    <>
      <IconButton variant="tonal" aria-label="Favorite">
        <Heart className="size-6" />
      </IconButton>
      <IconButton variant="tonal" size="l" aria-label="Favorite, large">
        <Heart className="size-8" />
      </IconButton>
    </>
  )
}

Handling presses

Handle a press with onPress, in place of onClick. An icon button takes the same press events as a Button. See Handling presses.

Toggle button

A toggle icon button lets a single choice be selected or deselected, such as adding or removing something from favorites. Set isSelectable to make one. Control its selection with isSelected and onChange, or set its initial state with defaultSelected.

A selected button changes its colors and swaps its shape: a round button becomes square, and a square one round. Every variant can be a toggle. A selected standard button changes only its icon color.

The button does not change its icon when it is selected. Show a filled icon for the selected state yourself, from the state you hold or from the isSelected passed to a function as children. If the icon has no filled version, use a semibold weight instead.

import { Icon, IconButton } from '@material-web/react'
import { useState } from 'react'

export default function Toggle() {
  const [isSaved, setSaved] = useState(true)
  return (
    <>
      <IconButton
        variant="filled"
        aria-label="Bookmark"
        isSelectable
        isSelected={isSaved}
        onChange={setSaved}
      >
        <Icon name="bookmark" className={isSaved ? 'icon-filled' : undefined} />
      </IconButton>
      <IconButton variant="tonal" aria-label="Favorite" isSelectable defaultSelected>
        {({ isSelected }) => (
          <Icon name="favorite" className={isSelected ? 'icon-filled' : undefined} />
        )}
      </IconButton>
      <IconButton variant="outlined" aria-label="Pin" isSelectable>
        {({ isSelected }) => (
          <Icon name="keep" className={isSelected ? 'icon-filled' : undefined} />
        )}
      </IconButton>
      <IconButton variant="standard" shape="square" aria-label="Star" isSelectable>
        {({ isSelected }) => (
          <Icon name="star" className={isSelected ? 'icon-filled' : undefined} />
        )}
      </IconButton>
      <IconButton variant="outlined" aria-label="Like" isSelectable isSelected isDisabled>
        <Icon name="thumb_up" className="icon-filled" />
      </IconButton>
    </>
  )
}
  • Without isSelectable, isSelected, defaultSelected and onChange are type errors.
  • A disabled toggle keeps the shape of its selection, as the last button of the example does.
  • To let people choose among several toggle buttons, put them in a button group.

Loading

Set isPending while the button's action is in progress, as on a button. A pending icon button shows a loading indicator in place of its icon, sized to the button. It keeps its size and colors, so the layout around it does not shift.

import { Icon, IconButton } from '@material-web/react'
import { useState } from 'react'

export default function Loading() {
  const [isSending, setSending] = useState(false)
  const send = async () => {
    setSending(true)
    await new Promise((resolve) => setTimeout(resolve, 3000))
    setSending(false)
  }
  return (
    <IconButton variant="filled" size="m" aria-label="Send" isPending={isSending} onPress={send}>
      <Icon name="send" className="rtl:icon-mirrored" />
    </IconButton>
  )
}
  • Presses: A pending icon button ignores presses and shows no hover. As a submit button, it does not submit its form, and as a link, it does not navigate.
  • Focus: It keeps the focus, so a keyboard user stays on it while the action runs.
  • Children: Its children are hidden while it is pending. See Pending content.

A toggle button can be pending too. It keeps its selection, and the colors and shape that show it, and pressing it does not toggle it. Here, a press makes the button pending while the change is saved, and the button shows its new state once it is.

import { Icon, IconButton } from '@material-web/react'
import { useState } from 'react'

export default function ToggleLoading() {
  const [isFavorite, setFavorite] = useState(false)
  const [isSaving, setSaving] = useState(false)
  const favorite = async (isSelected: boolean) => {
    setSaving(true)
    await new Promise((resolve) => setTimeout(resolve, 3000))
    setFavorite(isSelected)
    setSaving(false)
  }
  return (
    <IconButton
      variant="filled"
      size="m"
      aria-label="Favorite"
      isSelectable
      isSelected={isFavorite}
      isPending={isSaving}
      onChange={favorite}
    >
      <Icon name="favorite" className={isFavorite ? 'icon-filled' : undefined} />
    </IconButton>
  )
}

Color

A variant sets the button's colors. To use other color roles, pass their classes in className: a container color, and the on-color of that container for the icon. A standard button has no container, so it takes the icon color alone. The hover, focus and press states follow the icon color.

import { Icon, IconButton } from '@material-web/react'

export default function Colors() {
  return (
    <>
      <IconButton className="text-tertiary" aria-label="Favorite, tertiary">
        <Icon name="favorite" />
      </IconButton>
      <IconButton
        variant="tonal"
        className="bg-tertiary-container text-on-tertiary-container"
        aria-label="Favorite, tertiary container"
      >
        <Icon name="favorite" />
      </IconButton>
      <IconButton variant="filled" className="bg-error text-on-error" aria-label="Delete">
        <Icon name="delete" />
      </IconButton>
    </>
  )
}

Sizes

For larger or smaller icon buttons, set size to xs, s (the default), m, l or xl. An Icon child is sized to match.

SizeHeightIcon
xs32dp20dp
s40dp24dp
m56dp24dp
l96dp32dp
xl136dp40dp
import { Icon, IconButton } from '@material-web/react'

const sizes = ['xs', 's', 'm', 'l', 'xl'] as const

export default function Sizes() {
  return (
    <>
      {sizes.map((size) => (
        <IconButton key={size} variant="tonal" size={size} aria-label={`Add, ${size}`}>
          <Icon name="add" />
        </IconButton>
      ))}
    </>
  )
}

Shapes

Set shape to round (the default) or square. With hasShapeMorph, the corners tighten while the button is pressed. Press and hold the last two buttons to see it.

import { Icon, IconButton } from '@material-web/react'

export default function Shapes() {
  return (
    <>
      <IconButton variant="filled" size="m" shape="round" aria-label="Round">
        <Icon name="edit" />
      </IconButton>
      <IconButton variant="filled" size="m" shape="square" aria-label="Square">
        <Icon name="edit" />
      </IconButton>
      <IconButton variant="filled" size="m" shape="round" hasShapeMorph aria-label="Round, morphs">
        <Icon name="edit" />
      </IconButton>
      <IconButton
        variant="filled"
        size="m"
        shape="square"
        hasShapeMorph
        aria-label="Square, morphs"
      >
        <Icon name="edit" />
      </IconButton>
    </>
  )
}

Widths

Set width to narrow, default or wide. It changes only how wide the button is: size sets the height, and the default width makes a square.

SizeNarrowDefaultWide
xs28dp32dp40dp
s32dp40dp52dp
m48dp56dp72dp
l64dp96dp128dp
xl104dp136dp184dp
import { Icon, IconButton } from '@material-web/react'

export default function Widths() {
  return (
    <>
      <IconButton variant="tonal" size="m" width="narrow" aria-label="Add, narrow">
        <Icon name="add" />
      </IconButton>
      <IconButton variant="tonal" size="m" width="default" aria-label="Add, default">
        <Icon name="add" />
      </IconButton>
      <IconButton variant="tonal" size="m" width="wide" aria-label="Add, wide">
        <Icon name="add" />
      </IconButton>
    </>
  )
}

Rendering non-native buttons

Set elementType to render the icon button as an element other than a <button>. The element gets the button role and a tab stop, as on a button.

Set elementType="a" to render the button as a link, with href, target and rel. The browser follows it as a native link, without a client-side router. To follow it through a router, see Third-party routing library.

import { Icon, IconButton } from '@material-web/react'

export default function LinkIconButton() {
  return (
    <IconButton
      variant="tonal"
      elementType="a"
      href="https://m3.material.io/components/icon-buttons"
      target="_blank"
      rel="noreferrer"
      aria-label="Read the spec"
    >
      <Icon name="open_in_new" />
    </IconButton>
  )
}

Triggers and slots

An icon button can be the button of a trigger. In a MenuTrigger, put it first, before the menu's MenuPopover.

import { Icon, IconButton, Menu, MenuItem, MenuPopover } from '@material-web/react'
import { MenuTrigger } from 'react-aria-components'

export default function MenuButton() {
  return (
    <MenuTrigger>
      <IconButton aria-label="More options">
        <Icon name="more_vert" />
      </IconButton>
      <MenuPopover placement="bottom end">
        <Menu>
          <MenuItem>Rename</MenuItem>
          <MenuItem>Duplicate</MenuItem>
          <MenuItem>Move to trash</MenuItem>
        </Menu>
      </MenuPopover>
    </MenuTrigger>
  )
}
  • Tooltips: In a TooltipTrigger, put the icon button first, before the tooltip.
  • Files: To choose files with an icon button, wrap it in React Aria's FileTrigger. See File upload.
  • Slots: Set slot to place an icon button in a slot of another component. The remove button of an input chip is an IconButton with slot="remove".

See Triggers for the other triggers.

Customization

Pass classes in className to restyle one icon button. A class of yours replaces the button's own class for the same property. See Styling for the classes, the states and the theme.

  • States: Style a state with its variant, such as hover:, pressed: or selected:. In your own CSS, select the same states by their data attributes: data-hovered, data-pressed, data-focused, data-focus-visible and data-disabled, and data-selected on a toggle. See States.
  • Every icon button: To restyle all the icon buttons at once, change the theme.

Density

Add one of the theme's density classes, density-1, density-2 or density-3, to the button or to an element around it. Each step makes the button 4dp shorter. Its width does not change.

import { Icon, IconButton } from '@material-web/react'

const densities = ['', 'density-1', 'density-2', 'density-3']

export default function Density() {
  return (
    <>
      {densities.map((density) => (
        <IconButton
          key={density}
          variant="tonal"
          className={density}
          aria-label={density ? `Edit, ${density}` : 'Edit'}
        >
          <Icon name="edit" />
        </IconButton>
      ))}
    </>
  )
}

Children as a function

Pass a function as children to render the icon from the button's state: isHovered, isPressed, isFocused, isFocusVisible, isDisabled and isPending. A toggle also has isSelected. isFocused is any focus, and isFocusVisible is keyboard focus only.

import { Icon, IconButton } from '@material-web/react'
import { useState } from 'react'

export default function FunctionChildren() {
  const [isFavorite, setFavorite] = useState(false)
  return (
    <IconButton
      size="m"
      aria-label="Favorite"
      isSelectable
      isSelected={isFavorite}
      onChange={setFavorite}
    >
      {({ isSelected, isHovered }) => (
        <Icon name="favorite" className={isSelected || isHovered ? 'icon-filled' : undefined} />
      )}
    </IconButton>
  )
}

className and style can be functions of the same state. See Children as a function.

Limitations

An icon button rendered as an <a> keeps the button role, so assistive technology announces it as a button and not as a link. A disabled one has no href.

Disabled buttons

A disabled icon button cannot be focused and reports no hover, so it shows no tooltip.

Pending content

A pending icon button shows only its loading indicator. Children written for the pending state, such as a different icon, are hidden too. For a button that shows other content while pending, build a complex button.