#1 India's Top IT Training Institute
×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
Mentors

Mentors

Meet the industry experts who train and guide you through your course.

Read More →
Free Resources

Free Resources

Free tutorials, interview questions, tools and calculators to help you learn.

Explore →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →

Add Floating Action Buttons to Improve UX

A floating action button (FAB) is a single round or rounded-square button that floats above the content for the screen's most important action, such as "compose" or "add". Used for the right action it saves users a search; used for the wrong one, it covers content and adds clutter.

Add Floating Action Buttons to Improve UX

The FAB pattern was popularised by Google's Material Design for Android and is now common on the web too: Gmail's compose button, a "new chat" button in messaging apps, or an "add expense" button in a finance app. Its job is simple. It makes one primary action reachable from anywhere on the screen, usually with a thumb.

When a FAB improves UX

  • The screen has one clearly dominant action that users take often: create, compose, add, start.
  • The page scrolls, so a normal button at the top would disappear.
  • The action is constructive (create or start something), not destructive.
  • Users are mostly on phones, where the bottom-right corner is easy to reach with the right thumb.

When it hurts

  • No single main action. If the screen has three equally important actions, a FAB forces a false priority. Use a toolbar or normal buttons instead.
  • Minor or destructive actions. "Settings", "Share" or "Delete" do not belong in a FAB.
  • Covering content. A FAB over the last row of a list or over a "Next" button blocks it. Add bottom padding to the content equal to the FAB's height plus margin.
  • Conflicts with other floating elements. Chat widgets, cookie banners and bottom navigation bars can collide with it. Pick one floating element per corner.
  • Speed-dial menus with many options. A FAB that expands into six actions is a menu in disguise. Material guidance suggests keeping speed-dial options to a small number (three to six).

Design guidelines

AspectGuideline
Size (Material Design 3)The standard FAB is 56 × 56 dp, with smaller and larger variants (40 dp and 96 dp in the original M3 spec). Google revised the size set in its 2025 "Expressive" update, so check m3.material.io for the current list. An extended FAB adds a text label and is wider.
PlacementUsually bottom-right, about 16 dp from the screen edges; above any bottom navigation bar
IconOne clear icon (plus, pencil); add a label (extended FAB) if the icon alone is ambiguous
NumberOne FAB per screen
ContrastStrong colour contrast against both the page and content scrolling underneath
Touch targetAt least 24 × 24 CSS px to meet WCAG 2.2 (success criterion 2.5.8); 44–48 px is a common, more comfortable minimum
MotionHiding on scroll-down and showing on scroll-up is fine; respect reduced-motion settings

Building an accessible FAB on the web

HTML

Use a real <button> (or a link if it navigates), so it works with keyboard and screen readers. An icon-only button needs an accessible name.

<button class="fab" type="button" aria-label="Create new note">
  <svg aria-hidden="true" width="24" height="24" viewBox="0 0 24 24">
    <path d="M11 5h2v14h-2zM5 11h14v2H5z"/>
  </svg>
</button>

CSS

.fab {
  position: fixed;
  right: calc(16px + env(safe-area-inset-right));
  bottom: calc(16px + env(safe-area-inset-bottom));
  width: 56px;
  height: 56px;
  border: none;
  border-radius: 16px;
  background: #6750a4;
  color: #fff;
  fill: currentColor;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.25);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.2s ease;
  z-index: 10;
}
.fab:focus-visible { outline: 3px solid #1d1b20; outline-offset: 3px; }
.fab.is-hidden { transform: translateY(96px); }
@media (prefers-reduced-motion: reduce) {
  .fab { transition: none; }
}
/* keep the last items of the page reachable */
main { padding-bottom: 88px; }

The env(safe-area-inset-*) values keep the button clear of the iPhone home indicator. They only take effect when the page's viewport meta tag includes viewport-fit=cover; otherwise they are 0 and the 16 px margin still applies.

JavaScript: hide on scroll down, show on scroll up

const fab = document.querySelector(".fab");
let lastY = window.scrollY;

window.addEventListener("scroll", () => {
  const y = window.scrollY;
  fab.classList.toggle("is-hidden", y > lastY && y > 200);
  lastY = y;
}, { passive: true });

fab.addEventListener("click", () => {
  // open the editor, a dialog, or navigate
});

The button hides only after the user has scrolled past the first 200 px and is moving down, and comes back as soon as they scroll up. If the FAB opens a dialog, move keyboard focus into the dialog and return it to the FAB when the dialog closes. For related front-end patterns, see building a responsive navbar and CSS animated progress bars.

Android with Jetpack Compose

In Compose, Scaffold has a slot for the FAB and positions it for you:

Scaffold(
    floatingActionButton = {
        FloatingActionButton(onClick = { /* open editor */ }) {
            Icon(Icons.Filled.Add, contentDescription = "Create new note")
        }
    }
) { innerPadding ->
    NoteList(modifier = Modifier.padding(innerPadding))
}

Use ExtendedFloatingActionButton when you want an icon plus a text label. If you are learning Android, our Android development roadmap covers Compose basics.

Designing it in Figma first

Mock up the FAB on both a short screen and a long scrolling screen, and check what it covers at the bottom of the list. Make it a component with variants for default, pressed and extended states. Our guide to designing web layouts in Figma explains components and variants.

How to know whether it actually helped

  • Track clicks on the FAB and how often the action is completed (for example, notes created per session) before and after adding it.
  • If you have enough traffic, run an A/B test against a normal button in the header.
  • Watch session recordings or run a few usability tests to see whether users notice it and whether it blocks anything.
  • Check accessibility with a keyboard and a screen reader (TalkBack, VoiceOver or NVDA).

FAQs

Where should a floating action button go?

Usually bottom-right, about 16 px or dp from the edges, and above any bottom navigation bar. For right-to-left languages, mirror it to bottom-left.

Can a page have more than one FAB?

Generally no. One FAB signals one primary action. If you need more, reconsider whether a FAB is the right pattern.

Is a FAB good for desktop websites?

It can be, but on wide screens a clear button in the page header or next to the content is often easier to find. FABs work best on mobile.

Uncodemy's UI/UX and front-end courses cover interaction patterns like this, from Figma mock-ups to accessible code.

Placed Students

Our Clients

Partners

...