Skip to content
Tutorials Center
My learning

Topics

Lesson 5 of 36 ยท Components and Props

Buttons and Icon Buttons

Learn the Material UI Button, IconButton, ButtonGroup and Fab: variants, colors, sizes, start and end icons, loading state, links and accessibility labels.

The button is the component you will use more than any other. Material UI offers several: Button for labeled actions, IconButton for compact icon-only actions, ButtonGroup for related actions and Fab (floating action button) for the primary action of a screen. They share the same prop vocabulary, which is the key idea of this chapter: learn variant, color and size once and reuse them everywhere.

The Button component

Real MUI code (read-only):

JSX
import Button from '@mui/material/Button';

<Button>Text</Button>
<Button variant="contained">Contained</Button>
<Button variant="outlined">Outlined</Button>

The three variants express emphasis:

  • text (default): lowest emphasis, good for secondary actions like Cancel.
  • outlined: medium emphasis.
  • contained: highest emphasis, usually one per view (Save, Buy now).

Labels are uppercase by default (text-transform: uppercase in the theme's button typography). Turn it off for a single button with sx={{ textTransform: 'none' }} or globally in the theme, which you will do in the theming chapter.

Color and size

JSX
<Button variant="contained" color="secondary">Secondary</Button>
<Button variant="contained" color="success">Success</Button>
<Button variant="outlined" color="error">Delete</Button>
<Button size="small">Small</Button>
<Button size="medium">Medium</Button>
<Button size="large">Large</Button>

The color prop accepts primary (default), secondary, success, error, info, warning and inherit, plus any custom palette color you add to the theme. size is small, medium or large. Disable with disabled, and make the button fill its container with fullWidth.

Icons inside buttons

startIcon and endIcon place an icon before or after the label with correct spacing, so you do not have to wrap or position anything:

JSX
import SendIcon from '@mui/icons-material/Send';
import DeleteIcon from '@mui/icons-material/Delete';

<Button variant="contained" endIcon={<SendIcon />}>Send</Button>
<Button variant="outlined" color="error" startIcon={<DeleteIcon />}>Delete</Button>

Try the ideas

The first runnable example is a stand-in Button with variant, color, size, startIcon and fullWidth. Change props and watch the result.

Stand-in: Button variants, colors, sizes and icons

A button that navigates should be a real link. Give Button an href and MUI renders an <a> element with the button look. With a router, use the component prop (covered in the next-but-one lesson):

JSX
<Button href="https://example.com" target="_blank" rel="noopener">External</Button>
<Button component={RouterLink} to="/settings">Settings</Button>

Links for navigation, buttons for actions: it matters for keyboard users, screen readers and middle-click behavior.

Loading buttons

For async actions, show progress on the button itself. In current MUI versions the Button accepts loading and loadingPosition props (older versions used a separate LoadingButton from @mui/lab):

JSX
<Button loading variant="outlined">Submit</Button>
<Button loading loadingPosition="start" startIcon={<SaveIcon />}>Save</Button>

While loading is true the button is disabled and shows a spinner, which prevents double submits. If you use an older version, check the docs for LoadingButton.

IconButton

An IconButton is a round button that holds only an icon. It is the right control for toolbar actions and table row actions. Because there is no visible text, you must provide an accessible name with aria-label:

JSX
import IconButton from '@mui/material/IconButton';
import DeleteIcon from '@mui/icons-material/Delete';

<IconButton aria-label="delete" color="error">
  <DeleteIcon />
</IconButton>
<IconButton size="small" aria-label="settings"><SettingsIcon fontSize="small" /></IconButton>

It supports color, size (small, medium, large) and edge="start" | "end", which pulls it toward the container edge so it lines up in an app bar. Pair it with Tooltip to show the label on hover for sighted users.

ButtonGroup and Fab

ButtonGroup joins buttons visually and shares props:

JSX
<ButtonGroup variant="outlined" aria-label="text alignment">
  <Button>Left</Button><Button>Center</Button><Button>Right</Button>
</ButtonGroup>

Fab is a circular (or variant="extended") button for the main action, often fixed to a corner:

JSX
<Fab color="primary" aria-label="add" sx={{ position: 'fixed', right: 16, bottom: 16 }}>
  <AddIcon />
</Fab>

Use at most one Fab per screen.

Stand-in: accessible icon buttons and a group

This second stand-in shows two things: icon buttons must expose an accessible name, and a group of buttons can track the selected value through state. Hover to see the tooltip (the browser's title), and read the aria-label in the output line.

Stand-in: IconButton with aria-label and a button group

Common mistakes

  • No aria-label on an IconButton. Screen readers announce just "button".
  • A Button inside a <form> that should not submit. Buttons default to type="submit" in forms like any HTML button; set type="button".
  • Several contained buttons side by side. They compete for attention; keep one primary action.
  • Using Button for navigation without href/component. You lose link semantics.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which variant gives a Button the highest emphasis?

    contained buttons have a filled background and shadow and are meant for the primary action.
  2. 2. What must every IconButton have?

    An icon-only control has no text, so screen readers need aria-label (or similar) to announce it.
  3. 3. How do you place an icon before the label of a Button?

    startIcon and endIcon handle the spacing and alignment for you.
  4. 4. A button should take the user to another page. What is the best approach?

    href renders an anchor element, which keeps link semantics, middle-click and right-click behavior.

Summary

  • Button has three variants (text, outlined, contained), semantic colors and three sizes.
  • Use startIcon/endIcon for icons inside buttons and loading (or LoadingButton in older versions) for pending actions.
  • IconButton needs aria-label; Fab is for the single primary action; ButtonGroup joins related buttons.
  • Navigation should use href or the component prop so the element is a real link.

Next: Typography