Category Β· Interactive Difficulty Level Β· Intermediate Published on Β· January 22, 2024

Floating Action Button

Modern floating action button with smooth animations, expandable menu options, and elegant hover effects. Perfect for mobile-first applications and quick actions.

#fab #floating #button #menu #mobile

Responsive Design

Yes

Dark Mode Support

Yes

lines

629

Browser Compatibility

No

Live Preview

Interact with the component without leaving the page.

400px

Floating Action Button

A modern and accessible floating action button (FAB) component with expandable menu options, smooth animations, and comprehensive interaction support. Perfect for mobile-first applications and quick access to primary actions.

Features

  • Expandable Menu: Smooth animation with staggered item appearance
  • Multiple Actions: Support for message, call, email, and share functions
  • Hover Tooltips: Contextual labels for better user experience
  • Ripple Effects: Material Design-inspired touch feedback
  • Keyboard Navigation: Full accessibility with arrow key support
  • Screen Reader Support: ARIA labels and live announcements
  • Mobile Optimized: Touch-friendly sizing and responsive design
  • Dark Mode Support: Automatic adaptation to system preferences

Interaction States

  • Idle State: Subtle pulse animation to draw attention
  • Hover Effects: Scale and shadow transformations
  • Active State: Rotation animation and menu expansion
  • Focus States: Keyboard navigation indicators
  • Loading States: Smooth transitions during actions

Accessibility Features

  • WCAG 2.1 AA compliant
  • Keyboard navigation with arrow keys
  • Screen reader announcements
  • Focus management
  • High contrast support
  • Touch target sizing (44px minimum)

Customization Options

/* Custom colors */
.fab-main {
  background: linear-gradient(135deg, #your-primary, #your-secondary);
}

/* Custom positioning */
.fab-container {
  bottom: 1rem; /* Adjust vertical position */
  left: 2rem;   /* Move to left side */
}

/* Custom menu direction */
.fab-menu {
  bottom: auto;
  top: 70px;    /* Menu appears above button */
}

Action Handlers

The component includes built-in handlers for common actions:

  • Message: Opens messaging interface
  • Call: Initiates phone call
  • Email: Opens email client
  • Share: Uses Web Share API with clipboard fallback

Browser Support

  • Chrome 60+ (full support)
  • Firefox 55+ (full support)
  • Safari 12+ (full support)
  • Edge 79+ (full support)
  • iOS Safari 12+ (full support)
  • Android Chrome 60+ (full support)

Performance Features

  • Hardware-accelerated animations
  • Efficient event delegation
  • Minimal DOM manipulation
  • Optimized for 60fps animations
  • Lazy-loaded notification system

Integration Examples

// Custom action handler
const fab = new FloatingActionButton();
fab.addCustomAction('download', () => {
  console.log('Download initiated');
});

// Programmatic control
fab.open();  // Open menu
fab.close(); // Close menu
fab.toggle(); // Toggle state

HTML

33

lines

CSS

292

lines

JavaScript

304

lines


                <div class="fab-container">
  <!-- Main FAB Button -->
  <button class="fab-main" id="fabMain" aria-label="Main action menu">
    <span class="fab-icon main-icon">+</span>
    <span class="fab-icon close-icon">Γ—</span>
  </button>
  
  <!-- FAB Menu Items -->
  <div class="fab-menu" id="fabMenu">
    <button class="fab-item" data-action="message" aria-label="Send message">
      <span class="fab-icon">πŸ’¬</span>
      <span class="fab-tooltip">Message</span>
    </button>
    
    <button class="fab-item" data-action="call" aria-label="Make a call">
      <span class="fab-icon">πŸ“ž</span>
      <span class="fab-tooltip">Call</span>
    </button>
    
    <button class="fab-item" data-action="email" aria-label="Send email">
      <span class="fab-icon">βœ‰οΈ</span>
      <span class="fab-tooltip">Email</span>
    </button>
    
    <button class="fab-item" data-action="share" aria-label="Share content">
      <span class="fab-icon">πŸ”—</span>
      <span class="fab-tooltip">Share</span>
    </button>
  </div>
  
  <!-- Background Overlay -->
  <div class="fab-overlay" id="fabOverlay"></div>
</div>

              
33lines
1108characters
HTMLLanguage

Related Code Snippets

Explore template packs

Need larger building blocks? Browse responsive landing pages and component bundles.

Open HTML Template Library β†’