Skip to content

Icon button

Expressive

A compact icon-only action; requires an accessible name.

import { IconButton } from '@windmorph/react';

Props

By name or description, across the 33 props below

IconButton 33 props

  • icontype ReactElement<unknown, string | JSXElementConstructor<any>>Required

    The icon, e.g. a Material Symbols SVG. Hidden from assistive tech; aria-label names the button.

  • varianttype "standard" | "filled" | "tonal" | "outlined"default "filled"

    Colour style. Filled is the M3 default; toolbars and app bars default their icon buttons to standard through ButtonContext.

  • sizetype "xs" | "sm" | "md" | "lg" | "xl"default "sm"

    Container and icon size, from extra small to extra large.

  • widthtype "narrow" | "default" | "wide"default "default"

    Container width: narrow, default or wide, at the same height.

  • shapetype "round" | "square"default "round"

    Fully round corners, or square ones (still rounded, but less).

  • densitytype 0 | -1 | -2 | -3default 0

    Web density, 0 to -3: each step takes 4px off the container's height and width (an S button: 40px at 0, 28px at -3), never below the icon plus 4px; the touch target stays 48 × 48px. Left out, the button takes the density of the nearest ThemeProvider or ThemeScope; icon buttons in a field's icon slots, and in app bars, toolbars, search bars, a navigation rail's header and dialog and sheet headers, keep their size. M3 asks for density to be the reader's choice rather than a default, so prefer setting it there.

  • tooltiptype booleandefault true

    Shows the aria-label in a plain tooltip on hover and keyboard focus, as M3 asks of icon buttons on the web. The tooltip only repeats the name, so it isn't linked as a description (no double announcement). It steps aside when the button is already inside a TooltipTrigger or RichTooltipTrigger, and when it's named by aria-labelledby.

  • pendingtype booleandefault false

    Shows a loading indicator in place of the icon while an action runs, and blocks presses. The button keeps its size, its colours and keyboard focus; its accessible name gains labels.pending (the tooltip keeps showing only the aria-label), and a focused button announces it. The indicator appears after 200ms, so a quick action doesn't flash. Use it for actions that take a moment, not for every button in a list.

  • pendingIndicatortype ReactElement<unknown, string | JSXElementConstructor<any>>

    Replaces the loading indicator shown while pending, e.g. a CircularProgressIndicator for a wait that may pass five seconds. It's centred over the icon and takes the content colour; a progress indicator also loses its track, as M3 asks inside a button.

  • reftype Ref<HTMLButtonElement> | Ref<HTMLAnchorElement>

    Ref to the root element: the <button>, or the <a> with href.

  • disabledtype booleandefault false

    Disables the element: it can't be pressed or focused, and shows the disabled style.

  • valuetype string | number | readonly string[]

    The value a submit button sends with its form, under its name. On a toggle (toggle) it's a string naming the button in a selection group instead, required to take part in the group's selection.

  • draggedtype booleandefault false

    The element is being dragged (e.g. a card picked up to move it): sets data-dragged for the dragged state layer. A consumer's own data-dragged attribute counts too.

  • preventFocusOnPresstype booleandefault false

    Don't move focus to the element on press (set by menu triggers).

  • astype "button"default "button"

    The element rendered: a native <button>.

  • hreftype string

    Renders a link. Navigation goes through React Aria's RouterProvider when one is set.

  • toggletype booleandefault false

    Makes the button a toggle (aria-pressed) with selected and onSelectedChange.

  • selectedtype boolean

    Controlled selection. Ignored inside a selection group.

  • defaultSelectedtype boolean

    Initial selection when uncontrolled.

  • selectedIcontype ReactElement<unknown, string | JSXElementConstructor<any>>

    Icon shown while selected, e.g. the filled form of icon.

  • iconTransitiontype "swap" | "rotate"default "swap"

    How icon hands over to selectedIcon: swap changes it at once, rotate turns and crossfades the two (counter-clockwise as it selects, in LTR). rotate is an extension beyond the M3 spec, matching Google's Expressive showcase, like the FAB menu's. Reduced motion keeps only the crossfade. Needs selectedIcon.

Events

  • onSelectedChangetype ((selected: boolean) => void)

    Called with the new selection when the user toggles the button.

Text

  • labelstype Partial<ButtonLabels>

    Words the button announces. A LabelsProvider sets them for the whole app.

  • aria-labeltype string

    The button's accessible name, also shown in its tooltip. Required without aria-labelledby.

  • aria-labelledbytype string

    The id of an element that names the button, instead of aria-label.

Also accepts every <a> or <button> attribute.

Tokens

M3's component tokens as CSS variables. Each is unset until you set it, on :root, a theme or any ancestor, and falls back to the default shown. The root carries data-variant (and data-size where it has sizes), which picks the variables that apply. See Component tokens in the Customisation guide.

Icon button tokens (md-comp-icon-button)
VariableDefaultPaintsCompose
Standard (variant)
--md-comp-icon-button-standard-icon-colorvar(--md-comp-icon-button-icon-color, var(--md-sys-color-on-surface-variant))The icon, and an unselected toggle’s. Falls back to `--md-comp-icon-button-icon-color`.StandardIconButtonTokens.Color
--md-comp-icon-button-standard-selected-icon-colorvar(--md-sys-color-primary)The icon of a selected toggle.StandardIconButtonTokens.SelectedColor
Filled (variant)
--md-comp-icon-button-filled-container-colorvar(--md-sys-color-primary)The container.FilledIconButtonTokens.ContainerColor
--md-comp-icon-button-filled-icon-colorvar(--md-sys-color-on-primary)The icon.FilledIconButtonTokens.Color
--md-comp-icon-button-filled-selected-container-colorvar(--md-sys-color-primary)The container of a selected toggle.FilledIconButtonTokens.SelectedContainerColor
--md-comp-icon-button-filled-selected-icon-colorvar(--md-sys-color-on-primary)The icon of a selected toggle.FilledIconButtonTokens.ToggleSelectedColor
--md-comp-icon-button-filled-unselected-container-colorvar(--md-sys-color-surface-container)The container of an unselected toggle.FilledIconButtonTokens.UnselectedContainerColor
--md-comp-icon-button-filled-unselected-icon-colorvar(--md-sys-color-on-surface-variant)The icon of an unselected toggle.FilledIconButtonTokens.ToggleUnselectedColor
Tonal (variant)
--md-comp-icon-button-tonal-container-colorvar(--md-sys-color-secondary-container)The container.FilledTonalIconButtonTokens.ContainerColor
--md-comp-icon-button-tonal-icon-colorvar(--md-sys-color-on-secondary-container)The icon.FilledTonalIconButtonTokens.Color
--md-comp-icon-button-tonal-selected-container-colorvar(--md-sys-color-secondary)The container of a selected toggle.FilledTonalIconButtonTokens.SelectedContainerColor
--md-comp-icon-button-tonal-selected-icon-colorvar(--md-sys-color-on-secondary)The icon of a selected toggle.FilledTonalIconButtonTokens.ToggleSelectedColor
--md-comp-icon-button-tonal-unselected-container-colorvar(--md-sys-color-secondary-container)The container of an unselected toggle.FilledTonalIconButtonTokens.UnselectedContainerColor
--md-comp-icon-button-tonal-unselected-icon-colorvar(--md-sys-color-on-secondary-container)The icon of an unselected toggle.FilledTonalIconButtonTokens.ToggleUnselectedColor
Outlined (variant)
--md-comp-icon-button-outlined-outline-colorvar(--md-sys-color-outline-variant)The outline.OutlinedIconButtonTokens.OutlineColor
--md-comp-icon-button-outlined-icon-colorvar(--md-comp-icon-button-icon-color, var(--md-sys-color-on-surface-variant))The icon, and an unselected toggle’s. Falls back to `--md-comp-icon-button-icon-color`.OutlinedIconButtonTokens.Color
--md-comp-icon-button-outlined-selected-container-colorvar(--md-sys-color-inverse-surface)The container of a selected toggle, which has no outline.OutlinedIconButtonTokens.SelectedContainerColor
--md-comp-icon-button-outlined-selected-icon-colorvar(--md-sys-color-inverse-on-surface)The icon of a selected toggle.OutlinedIconButtonTokens.SelectedColor
Xs (size)
--md-comp-icon-button-xsmall-container-shape-roundvar(--md-sys-shape-corner-full)The round shape: full corners, at most half the height.XSmallIconButtonTokens.ContainerShapeRound
--md-comp-icon-button-xsmall-container-shape-squarevar(--md-sys-shape-corner-medium)The square shape, which a selected round toggle also takes.XSmallIconButtonTokens.ContainerShapeSquare
Sm (size)
--md-comp-icon-button-small-container-shape-roundvar(--md-sys-shape-corner-full)The round shape: full corners, at most half the height.SmallIconButtonTokens.ContainerShapeRound
--md-comp-icon-button-small-container-shape-squarevar(--md-sys-shape-corner-medium)The square shape, which a selected round toggle also takes.SmallIconButtonTokens.ContainerShapeSquare
Md (size)
--md-comp-icon-button-medium-container-shape-roundvar(--md-sys-shape-corner-full)The round shape: full corners, at most half the height.MediumIconButtonTokens.ContainerShapeRound
--md-comp-icon-button-medium-container-shape-squarevar(--md-sys-shape-corner-large)The square shape, which a selected round toggle also takes.MediumIconButtonTokens.ContainerShapeSquare
Lg (size)
--md-comp-icon-button-large-container-shape-roundvar(--md-sys-shape-corner-full)The round shape: full corners, at most half the height.LargeIconButtonTokens.ContainerShapeRound
--md-comp-icon-button-large-container-shape-squarevar(--md-sys-shape-corner-extra-large)The square shape, which a selected round toggle also takes.LargeIconButtonTokens.ContainerShapeSquare
Xl (size)
--md-comp-icon-button-xlarge-container-shape-roundvar(--md-sys-shape-corner-full)The round shape: full corners, at most half the height.XLargeIconButtonTokens.ContainerShapeRound
--md-comp-icon-button-xlarge-container-shape-squarevar(--md-sys-shape-corner-extra-large)The square shape, which a selected round toggle also takes.XLargeIconButtonTokens.ContainerShapeSquare

Spec status

Built to the M3 Expressive icon button spec. Each item of its variants and configurations links to a live example; where the M3 Expressive column of the spec differs from the original M3 one, it wins.

  • Default icon button

    Built

    Variant · Variants

  • Toggle (selection)

    Built

    Variant · Toggle, Toggle variants

  • Size: XS, S, M, L, XL

    Built

    Configuration · Sizes

  • Shape: round and square

    Built

    Configuration · Shapes

  • Color: filled, tonal, outlined, standard

    Built

    Configuration · Variants, Toggle variants

  • Width: narrow, default, wide

    Built

    Configuration · Sizes

  • Density (web, chosen by the reader)

    Built

    Use case · Density

  • Loading indicator in a button

    Built

    Use case · Pending

  • Links

    Extension

    href renders an <a> that routes through React Aria’s RouterProvider.

  • iconTransition="rotate"

    Extension

    Not in the M3 spec, which swaps icon for selectedIcon: the icon turns and crossfades into the other, counter-clockwise as it selects (mirrored in RTL). Matches Google's Expressive showcase motion; reduced motion keeps only the crossfade.

  • pending

    Extension

    M3 guidance with no icon button prop or token: the core LoadingIndicator takes the icon’s place after 200ms, at least 24px, and the button keeps its size and focus.

  • Content colour token

    Extension

    A container can set --md-comp-icon-button-icon-color for its standard and outlined icon buttons, as the vibrant toolbar and the app bars do.

Bundle size

Gzipped, as published: the component and the library code it imports. React, React Aria, Motion and the other dependencies aren't counted, and your bundler's minifier makes it smaller still. CI fails a change that grows it past its budget.

  • IconButton: 26.1 kB

M3 Expressive specs

Sizes
xs, sm, md, lg, xl
Shape
rounded-corner-full
Variants
standard, filled, tonal, outlined

Differences from Compose

  • Variants are filled | tonal | outlined | standard — no elevated or text. Filled is the default, as in the M3 Expressive specs (Compose's plain IconButton is standard). Toolbars and app bars make their icon buttons standard by default through ButtonContext. A dialog, menu or sheet opened from one isn't part of it: its icon buttons are filled again unless they say otherwise.
  • width (narrow / default / wide) is the icon size plus leading and trailing space; Compose's Uniform option is the default width.
  • Standard icons are on-surface-variant, and outlined ones are too, inside an outline-variant outline (the spec's colour table). A container that needs its own content colour, like a vibrant toolbar, sets --md-comp-icon-button-icon-color (to currentColor to inherit it), which the standard and outlined icon colour tokens fall back to.
  • Selected toggles: standard turns primary, filled primary/on-primary, tonal secondary/on-secondary, outlined inverse-surface with no border, disabled or not; shape swaps round ↔ square.
  • A disabled outlined icon button's outline dims to outline-variant at 10%, the same as a disabled outlined button (Compose's code draws it at 38% of the content colour).
  • Reads size / shape / disabled and its default iconButtonVariant from ButtonContext, but not the Button variant, because the variant sets differ.
  • pending follows M3's guidance on loading indicators in buttons (no Compose parameter): the LoadingIndicator at the icon's size, 24px at least, in the icon's colour. The name gains “Loading” (labels.pending); the tooltip keeps showing the aria-label.