Moraine Lake
An icon button is a button with an icon and no label. Icon buttons are typically placed in places like:
- App bars
- Toolbars
- Search bars
- Input chips, as the remove button
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,defaultSelectedandonChangeare 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.
| Size | Height | Icon |
|---|---|---|
xs | 32dp | 20dp |
s | 40dp | 24dp |
m | 56dp | 24dp |
l | 96dp | 32dp |
xl | 136dp | 40dp |
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.
| Size | Narrow | Default | Wide |
|---|---|---|---|
xs | 28dp | 32dp | 40dp |
s | 32dp | 40dp | 52dp |
m | 48dp | 56dp | 72dp |
l | 64dp | 96dp | 128dp |
xl | 104dp | 136dp | 184dp |
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.
Links
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
slotto place an icon button in a slot of another component. The remove button of an input chip is anIconButtonwithslot="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:orselected:. In your own CSS, select the same states by their data attributes:data-hovered,data-pressed,data-focused,data-focus-visibleanddata-disabled, anddata-selectedon 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
Link role
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.
Use cases
Material lists what people should be able to do with assistive technology:
- Understand meaning of the icon
- Navigate to and activate an icon button
- When applicable, a tooltip should be available to help describe the icon button's purpose
Interaction and style
- States: Hovering shows a state layer, and a press shows a ripple. Keyboard focus shows a focus ring, and a press with a mouse or touch does not.
- Touch target: Every size and width has a touch target of at least 48dp, an extra small or narrow button included, at every density.
- Color contrast: The icon needs 3:1 contrast with its container, or with the background for a
standardbutton. Every variant has it in its default colors, selected or not, in the light and dark schemes at every contrast level. Keep that contrast when you change its colors. - Density: Material advises against applying density to icon buttons by default. Add a density class where people have chosen a denser layout, such as with a setting.
- Motion: With reduced motion, the changes of shape and color are instant.
- Forced colors: In forced colors, every variant but
standardkeeps an edge, and a selected toggle button is filled with the system's highlight color. - Tooltip: On the web, Material advises a tooltip that shows the button's label on hover. Put the icon button first in a
TooltipTrigger, and write the text of itsaria-labelin the tooltip.
Focus
- A disabled icon button cannot be focused.
- A pending button keeps the focus, so a keyboard user stays on it while the action runs.
Keyboard navigation
| Keys | Actions |
|---|---|
| Tab | Move the focus to an icon button |
| Space or Enter | Press the focused icon button, or select or deselect a toggle button |
Labeling elements
- An icon button has no visible text, so an
aria-labelor anaria-labelledbyis required. Set anaria-labelthat describes the action the button performs, such as Add to favorites, Bookmark or Send message, as Material advises. - An
Iconchild is hidden from assistive technology, so the label alone names the button. - A tooltip describes the button and does not name it, so an icon button with a tooltip still needs its
aria-label. See Labels and descriptions. - A toggle button reports whether it is selected with
aria-pressed. Keep its label the same in both states. - A pending button reports that it is unavailable with
aria-disabled. Its loading indicator is hidden from assistive technology, so thearia-labelstill names the button. - When a focused button becomes pending, or stops being pending, screen readers announce it.
variant'filled' | 'tonal' | 'outlined' | 'standard'Default'standard'There are four icon button color styles, in order of emphasis: filled, tonal, outlined, standard
For the highest emphasis, use the filled style. For the lowest emphasis, use standard.
filled: Use the filled style for visual impact and key actions that require high emphasis. Avoid overusing the filled style on a screen. Use them sparingly.tonal: Use the tonal style as a middle ground between filled and outlined icon buttons. It’s useful for secondary actions paired with a high emphasis action.outlined: Use the outlined style for medium-emphasis buttons. It’s useful when the button isn’t the main focus of the interaction, such as browsing through sets of cards.standard: Use the standard style for low-emphasis buttons, or when placing buttons on a colorful surface.
size's' | 'xs' | 'm' | 'l' | 'xl'Default's'Icon buttons are available in five different sizes:
- Extra small - 32dp
- Small - 40dp (default)
- Medium - 56dp
- Large - 96dp
- Extra large - 136dp
width'narrow' | 'default' | 'wide'Default'default'Three widths: narrow, default, and wide
Container widths in dp:
- XS: narrow 28, default 32, wide 40
- S: narrow 32, default 40, wide 52
- M: narrow 48, default 56, wide 72
- L: narrow 64, default 96, wide 128
- XL: narrow 104, default 136, wide 184
shape'round' | 'square'Default'round'Two shapes: round and square
Corner sizes of a square button: XS 12dp, S 12dp, M 16dp, L 28dp, XL 28dp.
In addition to changing shape when pressed, toggle icon buttons also change the resting shape from round (unselected) to square (selected) by default. If the resting shape is square, the selected shape should be round.
hasShapeMorphbooleanDefaultfalseShape morphs when pressed
While pressed, icon buttons can morph to become more square. Both round and square icon buttons should have the same pressed shape radius.
Corner sizes of the pressed state: XS 8dp, S 8dp, M 12dp, L 16dp, XL 16dp.
aria-labelstringDefines a string value that labels the current element.
isPendingbooleanWhether the button is in a pending state. This disables press and hover events while retaining focusability, and announces the pending state to screen readers.
isSelectablebooleanDefaultfalseTwo variants: default and toggle
Toggle icon buttons allow a single choice to be selected or deselected, such as adding or removing something from favorites.
The default (left) and toggle (right) icon buttons are available in all four color styles
The icon should become filled to represent selection.
If a filled version of the icon doesn't exist, use semibold weight instead.
Props of IconButton (49)
formstringThe
<form>element to associate the button with. The value of this attribute must be the id of a<form>in the same document. See MDN.idstringThe element's unique identifier. See MDN.
aria-labelledbystringIdentifies the element (or elements) that labels the current element.
aria-describedbystringIdentifies the element (or elements) that describes the object.
aria-detailsstringIdentifies the element (or elements) that provide a detailed, extended description for the object.
onClick(e: MouseEvent<FocusableElement>) => voidNot recommended – use
onPressinstead.onClickis an alias foronPressprovided for compatibility with other libraries.onPressprovides additional event details for non-mouse interactions.isDisabledbooleanWhether the button is disabled.
onPress(e: PressEvent) => voidHandler that is called when the press is released over the target.
onPressStart(e: PressEvent) => voidHandler that is called when a press interaction starts.
onPressEnd(e: PressEvent) => voidHandler that is called when a press interaction ends, either over the target or when the pointer leaves the target.
onPressChange(isPressed: boolean) => voidHandler that is called when the press state changes.
onPressUp(e: PressEvent) => voidHandler that is called when a press is released over the target, regardless of whether it started on the target or not.
autoFocusbooleanWhether the element should receive focus on render.
onFocus(e: FocusEvent<Target>) => voidHandler that is called when the element receives focus.
onBlur(e: FocusEvent<Target>) => voidHandler that is called when the element loses focus.
onFocusChange(isFocused: boolean) => voidHandler that is called when the element's focus status changes.
onKeyDown(e: KeyboardEvent) => voidHandler that is called when a key is pressed.
onKeyUp(e: KeyboardEvent) => voidHandler that is called when a key is released.
hrefstringA URL to link to if elementType="a".
targetstringThe target window for the link.
relstringThe relationship between the linked resource and the current page. See MDN.
elementTypeT | JSXElementConstructor<any>Default'button'The HTML element or React element used to render the button, e.g. 'div', 'a', or
RouterLink.aria-disabled'true' | 'false' | booleanIndicates whether the element is disabled to users of assistive technology.
aria-expanded'true' | 'false' | booleanIndicates whether the element, or another grouping element it controls, is currently expanded or collapsed.
aria-haspopup'dialog' | 'menu' | 'true' | 'false' | 'grid' | 'listbox' | 'tree' | booleanIndicates the availability and type of interactive popup element, such as menu or dialog, that can be triggered by an element.
aria-controlsstringIdentifies the element (or elements) whose contents or presence are controlled by the current element.
aria-pressed'true' | 'false' | 'mixed' | booleanIndicates the current "pressed" state of toggle buttons.
aria-current'time' | 'true' | 'false' | 'page' | 'step' | 'location' | 'date' | booleanIndicates whether this element represents the current item within a container or set of related elements.
type'button' | 'submit' | 'reset'Default'button'The behavior of the button when used in an HTML form.
preventFocusOnPressbooleanWhether to prevent focus from moving to the button when pressing it.
Caution, this can make the button inaccessible and should only be used when alternative keyboard interaction is provided, such as ComboBox's MenuTrigger or a NumberField's increment/decrement control.
formActionButtonHTMLAttributes<HTMLButtonElement>['formAction']The URL that processes the information submitted by the button. Overrides the action attribute of the button's form owner.
formEncTypestringIndicates how to encode the form data that is submitted.
formMethodstringIndicates the HTTP method used to submit the form.
formNoValidatebooleanIndicates that the form is not to be validated when it is submitted.
formTargetstringOverrides the target attribute of the button's form owner.
namestringSubmitted as a pair with the button's value as part of the form data.
valuestringThe value associated with the button's name when it's submitted with the form data.
excludeFromTabOrderbooleanWhether to exclude the element from the sequential tab order. If true, the element will not be focusable via the keyboard by tabbing. This should be avoided except in rare scenarios where an alternative means of accessing the element or its functionality via the keyboard is available.
onHoverStart(e: HoverEvent) => voidHandler that is called when a hover interaction starts.
onHoverEnd(e: HoverEvent) => voidHandler that is called when a hover interaction ends.
onHoverChange(isHovering: boolean) => voidHandler that is called when the hover state changes.
slotstring | nullA slot name for the component. Slots allow the component to receive props from a parent component. An explicit
nullvalue indicates that the local props completely override all props received from a parent.refRef<ComponentRef<T> & Element>classNameClassNameOrFunction<ButtonRenderProps>styleStyleOrFunction<ButtonRenderProps>childrenChildrenOrFunction<ButtonRenderProps>isSelectedbooleandefaultSelectedbooleanonChangenever