Web · Components
Fab
Floating action button (FAB) and speed dial.
Live example
Preview
- Record 1Last edited: today
- Record 2Last edited: today
- Record 3Last edited: today
- Record 4Last edited: today
- Record 5Last edited: today
- Record 6Last edited: today
- Record 7Last edited: today
- Record 8Last edited: today
- Record 9Last edited: today
- Record 10Last edited: today
- Record 11Last edited: today
- Record 12Last edited: today
- Record 13Last edited: today
- Record 14Last edited: today
- Record 15Last edited: today
- Record 16Last edited: today
- Record 17Last edited: today
- Record 18Last edited: today
- Record 19Last edited: today
- Record 20Last edited: today
- Record 21Last edited: today
- Record 22Last edited: today
- Record 23Last edited: today
- Record 24Last edited: today
- Record 25Last edited: today
- Record 26Last edited: today
- Record 27Last edited: today
- Record 28Last edited: today
- Record 29Last edited: today
- Record 30Last edited: today
Code
Events
- Events appear here when you interact with the preview.
By area: stays in place in a scrolled list, shrinks when scrolling down
- Record 1Last edited: today
- Record 2Last edited: today
- Record 3Last edited: today
- Record 4Last edited: today
- Record 5Last edited: today
- Record 6Last edited: today
- Record 7Last edited: today
- Record 8Last edited: today
- Record 9Last edited: today
- Record 10Last edited: today
- Record 11Last edited: today
- Record 12Last edited: today
- Record 13Last edited: today
- Record 14Last edited: today
- Record 15Last edited: today
- Record 16Last edited: today
- Record 17Last edited: today
- Record 18Last edited: today
- Record 19Last edited: today
- Record 20Last edited: today
- Record 21Last edited: today
- Record 22Last edited: today
- Record 23Last edited: today
- Record 24Last edited: today
- Record 25Last edited: today
Narrow card: opens sideways if there's no room above, labels move to tooltips
Centered, with backdrop, surface appearance
Import
Floating action button (FAB) and speed dial. Sits in the corner of the screen or of the area you put it in; with actions, small action buttons open one after another with a spring on press.
- Area-relative position: With the default
scope="container", it sits in the corner of whatever element you put the Fab in (astaticelement is maderelativeautomatically). If the element scrolls, the button doesn't scroll with the content; in supporting browsers it follows scrolling off the main thread, without jitter. For the screen corner, usescope="viewport". - Smart direction:
direction="auto"picks the direction where the actions fit; in the corner of a small card with no room above, it opens sideways. - Keyboard: The arrow key in the opening direction opens the menu and moves to the first action; arrows move between actions, Esc closes and returns focus to the main button. The menu closes when focus leaves it.
- Mobile: Action names appear as thumb-readable labels, tapping outside and the back button close the menu, touch targets are at least 44 px, and with
scrollBehaviorit hides or shrinks while scrolling. - Animations are disabled with the "reduced motion" preference.
Examples
FabPosition
typeCorner or edge midpoint of the area the Fab is in.
FabDirection
typeDirection the actions open in. "auto" tries vertical first (a bottom button opens up, a top one down); if there is not enough room it goes sideways (left in the right corner, right in the left corner). The direction is re-chosen on each open and whenever the area size changes.
FabScope
typeWhat the button is positioned relative to.
"container": The corner of the element you put the Fab in (its parent). If the element scrolls, the button does not scroll with the content and stays in the corner of the visible area."viewport": The corner of the screen (position: fixed); notch and home indicator insets (safe area) are added automatically.
FabActionLabels
typeHow action names are shown.
"visible": A name label appears next to each small button (clearest on mobile)."tooltip": The name appears only as a tooltip."auto": Label when opening vertically, tooltip when opening sideways.
Behavior of the button when the page scrolls.
"none": Stays in place."hide": Shrinks away while scrolling down, comes back when scrolling up; it doesn't cover content."shrink": Anextendedbutton shrinks to just the icon while scrolling down; its text comes back when scrolling up.
FabVariant
typeAppearance of the button: solid is the theme's filled color, surface a colored icon on a light surface (calmer).
FabAction
interfaceOne of the small action buttons that appear when the Fab opens.
| Name | Type | Default | Description |
|---|---|---|---|
label | string | Name of the action; shown in the label or tooltip, read by screen readers. | |
icon | IconProp | Icon on the small button: a name ("pencil") or an element. | |
tone? | Tone | "neutral" | Color of the icon. |
disabled? | boolean | Cannot be selected. | |
tooltip? | TooltipProp | Extra hint. When actionLabels="tooltip" and this is omitted, label is shown. See TooltipProp. | |
onSelect? | (event: MouseEvent<HTMLElement>) => void | Called when selected (click, Enter, Space); then the menu closes. Call event.preventDefault() to keep it open. | |
href? | string | If given, the action becomes a link; rendered with the link component given to UIProvider (e.g. Next.js Link). |
FabProps
interfaceProps of the Fab component.
| Name | Type | Default | Description |
|---|---|---|---|
label | string | Name of the button. Read by screen readers; with extended it is written on the button, otherwise it appears as a tooltip. | |
icon? | IconProp | Plus (+) | Icon of the button. |
openIcon? | IconProp | Icon that replaces the icon while the menu is open. The default plus icon rotates into a cross (×) when opened; if you gave your own icon, it swaps with the cross. | |
extended? | boolean | The button also writes label next to the icon (extended, pill-shaped FAB). | |
actions? | readonly FabAction[] | Small action buttons that open with an animation on press (speed dial). The first action is the one closest to the main button. If omitted, the button is a single action (onClick or href). | |
onClick? | (event: MouseEvent<HTMLElement>) => void | Called on click when there are no actions. | |
href? | string | If given when there are no actions, the button becomes a link. | |
position? | FabPosition | "bottom-right" | Position in the area. See FabPosition. |
direction? | FabDirection | "auto" | Direction the actions open in. See FabDirection. |
scope? | FabScope | "container" | What it is positioned relative to. See FabScope. |
offset? | number | string | 16 | Distance from the edges: pixels or a CSS length ("1.5rem"). If there is a navigation bar at the bottom, increase it by its height. |
variant? | FabVariant | CustomVariant<"fab"> | "solid" | Appearance: built-in or a custom style added with defineAppearance. If omitted, UIProvider appearance.defaults.fab.variant. See FabVariant. |
effect? | EffectProp | Effect or effects of the main button (e.g. "ripple", ["pulse", "glow"]). If omitted, UIProvider appearance.defaults.fab.effect, or shrink on press (scale) if that is missing too. See BuiltinEffect. | |
tone? | Tone | "primary" | Color. See Tone. |
size? | Size | "md" | Size: sm 40 px, md 56 px, lg 64 px. |
actionLabels? | FabActionLabels | "auto" | How action names are shown. See FabActionLabels. |
scrim? | boolean | false | Draws a semi-transparent scrim over the area while the menu is open. |
scrollBehavior? | FabScrollBehavior | "none" | Behavior on scroll. See FabScrollBehavior. |
tooltip? | TooltipProp | Tooltip. If omitted, label is shown on a button without text; disable with false. See TooltipProp. | |
open? | boolean | Whether the menu is open when controlled. | |
defaultOpen? | boolean | false | Is it initially open when uncontrolled? |
onOpenChange? | (open: boolean) => void | Called with the new state when the menu opens or closes. | |
disabled? | boolean | Disabled. | |
className? | string | Classes added to the main button. |