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

FAB

Give your primary action a place to stand out. Explore color, size, and floating positions.

FactoryWeb ComponentsReactVueSvelteSolidJS
PublishedUpdated

A floating action button (FAB) carries the one action a screen is for: compose, add, start. It floats above the content, holds an icon and no label, and there is at most one in view. When the action needs a word, use the extended FAB.

Usage

ariaLabel is required: a FAB has no visible text.

Vanilla
import { createFab } from 'material';

const fab = createFab({ icon: addIcon, ariaLabel: 'Create new item' });
fab.on('click', () => createItem());
document.body.append(fab.element);
Web Components
<m-fab aria-label="Create new item"></m-fab>

<script type="module">
  const fab = document.querySelector('m-fab');
  fab.setAttribute('icon', addIcon);
  fab.addEventListener('click', () => createItem());
</script>
React
import { Fab } from 'material/react';
import { createItem, addIcon } from './app';

export function Example() {
  return (
    <Fab onClick={() => createItem()} icon={addIcon} ariaLabel="Create new item" />
  );
}
Vue
<script setup lang="ts">
import { MFab } from 'material/vue';
import { createItem, addIcon } from './app';
</script>

<template>
  <MFab @click="createItem()" :icon="addIcon" aria-label="Create new item" />
</template>
Svelte
<script lang="ts">
  import { Fab } from 'material/svelte';
  import { createItem, addIcon } from './app';
</script>

<Fab onclick={() => createItem()} icon={addIcon} ariaLabel="Create new item" />
SolidJS
import { Fab } from 'material/solid';
import { createItem, addIcon } from './app';

export function Example() {
  return (
    <Fab onClick={() => createItem()} icon={addIcon} ariaLabel="Create new item" />
  );
}

Examples

Color and size

variant is one of the container styles primary-container (the default), secondary-container and tertiary-container, or the tone styles primary, secondary and tertiary; each takes its color and the matching on- color from the theme. size is default, medium or large, and the icon grows with it, so one SVG serves every size. small and surface are deprecated.

Vanilla
import { createFab } from 'material';

const fab = createFab({
  icon: editIcon,
  ariaLabel: 'Edit',
  variant: 'tertiary',
  size: 'large',
});
document.body.append(fab.element);
Web Components
<m-fab variant="tertiary" size="large" aria-label="Edit"></m-fab>

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

export function Example() {
  return (
    <Fab variant="tertiary" size="large" icon={editIcon} ariaLabel="Edit" />
  );
}
Vue
<script setup lang="ts">
import { MFab } from 'material/vue';
import { editIcon } from './app';
</script>

<template>
  <MFab variant="tertiary" size="large" :icon="editIcon" aria-label="Edit" />
</template>
Svelte
<script lang="ts">
  import { Fab } from 'material/svelte';
  import { editIcon } from './app';
</script>

<Fab variant="tertiary" size="large" icon={editIcon} ariaLabel="Edit" />
SolidJS
import { Fab } from 'material/solid';
import { editIcon } from './app';

export function Example() {
  return (
    <Fab variant="tertiary" size="large" icon={editIcon} ariaLabel="Edit" />
  );
}

In a corner

position fixes the FAB to a corner of the viewport, 16dp from both edges. Leave it unset to place the FAB yourself, as in a card, a sheet or a docked toolbar.

Vanilla
import { createFab } from 'material';

const fab = createFab({
  icon: addIcon,
  ariaLabel: 'Create new item',
  position: 'bottom-right',
});
document.body.append(fab.element);
Web Components
<m-fab position="bottom-right" aria-label="Create new item"></m-fab>

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

export function Example() {
  return (
    <Fab icon={addIcon} position="bottom-right" ariaLabel="Create new item" />
  );
}
Vue
<script setup lang="ts">
import { MFab } from 'material/vue';
import { addIcon } from './app';
</script>

<template>
  <MFab :icon="addIcon" position="bottom-right" aria-label="Create new item" />
</template>
Svelte
<script lang="ts">
  import { Fab } from 'material/svelte';
  import { addIcon } from './app';
</script>

<Fab icon={addIcon} position="bottom-right" ariaLabel="Create new item" />
SolidJS
import { Fab } from 'material/solid';
import { addIcon } from './app';

export function Example() {
  return (
    <Fab icon={addIcon} position="bottom-right" ariaLabel="Create new item" />
  );
}

A FAB rests at elevation level 3 and rises to 4 on hover; lower() moves it to the lowered levels, 1 and 2, and raise() restores them. animate: true scales it in when it is added to the page.

API

Options

icon

Icon as an HTML string, usually an SVG

Typestring
Defaultundefined
ariaLabel

Accessible name

Typestring
Defaultrequired
variant

Color style

Type'primary-container' | 'secondary-container' | 'tertiary-container' | 'primary' | 'secondary' | 'tertiary'
Default'primary-container'
size

Container, icon and corner

Type'default' | 'medium' | 'large'
Default'default'
position

Fixes the FAB to a corner of the viewport

Type'top-right' | 'top-left' | 'bottom-right' | 'bottom-left'
Defaultundefined
disabled

Creates it disabled

Typeboolean
Defaultfalse
iconSize

Adds an mtrl-icon--<value> class to the icon, for your own CSS; the stylesheet has no rules for it

Typestring
Defaultundefined
animate

Scales the FAB in when it is added to the page

Typeboolean
Defaultfalse
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
type

The button's type attribute

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

The button's value attribute, for forms

Typestring
Defaultundefined
class

Extra classes on the element

Typestring
Defaultundefined
prefix

Prefix for CSS class names

Typestring
Default'mtrl'

Methods

setIcon(icon) / getIcon()

The icon HTML

Parametersicon: string
ReturnsFabComponent / string
setPosition(position)

Moves it to another corner

Parametersposition: string
ReturnsFabComponent
getPosition()

The current corner, or null when unpositioned

Parametersnone
Returnsstring | null
lower() / raise()

The lowered or the normal elevation levels

Parametersnone
ReturnsFabComponent
enable() / disable()

The disabled state

Parametersnone
ReturnsFabComponent
setValue(value) / getValue()

The value attribute

Parametersvalue: string
ReturnsFabComponent / string
addClass(...classes)

Adds classes to the element

Parameters...classes: string[]
ReturnsFabComponent
getClass(name)

Prefixes a name: 'fab' gives 'mtrl-fab'

Parametersname: string
Returnsstring
on(event, handler) / off(event, handler)

Adds or removes a listener

Parametersevent: string, handler: Function
ReturnsFabComponent
destroy()

Removes the element and its listeners

Parametersnone
Returnsvoid
element

The button

TypeHTMLButtonElement
icon

The icon manager

Type{ setIcon, getIcon, getElement }
disabled

The disabled-state manager

Type{ enable, disable, isDisabled }
lifecycle

The lifecycle manager

Type{ destroy }

Events

click

Pressed; not fired while disabled

Payload{ event, element, originalEvent }
focus / blur

Took or lost focus

Payload{ event, element, originalEvent }

event and originalEvent are the same DOM event; element is the button.

Styling

Colors are the theme's roles: each style is the role it is named after, on its on- role, and the state layer takes the icon color.

.mtrl-fab { }
.mtrl-fab--primary-container, .mtrl-fab--secondary-container, .mtrl-fab--tertiary-container { }
.mtrl-fab--primary, .mtrl-fab--secondary, .mtrl-fab--tertiary { }
.mtrl-fab--default, .mtrl-fab--medium, .mtrl-fab--large { }
.mtrl-fab--lowered, .mtrl-fab--disabled, .mtrl-fab--animate-enter { }
.mtrl-fab--top-left, .mtrl-fab--top-right, .mtrl-fab--bottom-left, .mtrl-fab--bottom-right { }
.mtrl-fab__icon { }

Measurements

From the Compose M3 token files named in the last column.

Attribute Value Source
Container, default 56dp FabBaselineTokens
Container, medium 80dp FabMediumTokens
Container, large 96dp FabLargeTokens
Container, small (deprecated) 40dp FabSmallTokens
Corner, default 16dp (large) FabBaselineTokens
Corner, medium 20dp (large-increased) Android fab_tokens.xml
Corner, large 28dp (extra-large) FabLargeTokens
Corner, small 12dp (medium) FabSmallTokens
Icon, default and small 24dp FabBaselineTokens, FabSmallTokens
Icon, medium 28dp FabMediumTokens
Icon, large 32dp FabLargeTokens; Android says 36dp
Elevation, rest / hover / focus / pressed levels 3 / 4 / 3 / 3 FabPrimaryContainerTokens
Lowered, rest / hover / focus / pressed levels 1 / 2 / 1 / 1 ExtendedFabPrimaryTokens
Disabled on-surface at 12% container and 38% icon, level 0 library policy; the FAB tokens define no disabled state
Offset from the corner 16dp the position rules in _fab.scss
Entrance 0.3s, emphasized decelerate the fab-enter keyframes in _fab.scss