Floating Action Button (FAB) Template
Provide users with constant access to a primary action using this elegant floating button.
This button stays in a fixed position as the user scrolls, making it an excellent choice for actions like creating a new item, composing a message, or starting a chat.
About the Floating Action Button
The Floating Action Button (FAB) is a UI pattern popularized by Google's Material Design. It's a circular, icon-only button that "floats" above the main content of the page, typically anchored to a corner. Its purpose is to present a promoted, primary action in a way that is immediately accessible, regardless of where the user is on the page. This template is particularly effective on mobile interfaces where space is at a premium.
Features
- Fixed Positioning: Uses
position: fixedto ensure the button is always visible in the same spot on the screen. - Floating Effect: A carefully crafted
box-shadowmakes the button appear to be levitating over the page content. - Essential for Accessibility: Since the button has no visible text, it includes a descriptive
aria-labelto announce its function to screen reader users. - Pure CSS and HTML: The entire component is built without any JavaScript, making it fast and simple to integrate.
- Interactive Feedback: A subtle animation on hover lifts the button and enhances its shadow, providing a satisfying micro-interaction.
Code Breakdown
The CSS uses position: fixed combined with the bottom and right properties to lock the button to the bottom-right corner. A high z-index value ensures it stays above other content. The circular shape is created with a border-radius: 50%. Inside the button, Flexbox is used to perfectly center the SVG icon.
Code
Here is the complete, self-contained code for the Floating Action Button.