Floating UI Gains Traction for Positioning

A library called Floating UI is gaining popularity as a modern engine for positioning elements like tooltips, dropdowns, and popovers. It uses intelligent algorithms to keep elements visible and avoid viewport collisions, reducing layout bugs for developers.

Floating UI is the direct successor to Popper.js, a library that became a staple for positioning elements in popular frameworks like Bootstrap and Material UI. The creator of Popper, Federico Zivolo, evolved it into Floating UI to provide a more modern, flexible, and powerful positioning engine. One of its key advantages is its minuscule size; at only 600 bytes, it's significantly smaller than its 3kb predecessor, Popper. This is achieved through a modular, tree-shakeable architecture, meaning developers only bundle the code they actually use, which is a major plus for performance-conscious web applications. Unlike Popper, which was limited to the web DOM, Floating UI is platform-agnostic. This allows developers to use the same logic for positioning elements not just on the web, but also in React Native, Canvas, and WebGL environments, making it a versatile tool for a variety of projects. The library gives developers more direct control through its middleware system. While Popper came with default modifiers, Floating UI requires developers to explicitly import and apply middleware like `flip`, `shift`, and `offset`. This "bare-bones" approach prevents unexpected behavior and makes the positioning logic more predictable. Adoption of Floating UI is growing within the headless UI component ecosystem. Headless UI, from the creators of Tailwind CSS, integrated Floating UI directly into its v2.0 for React to handle all anchor positioning. This signals a strong endorsement from a major player in the modern frontend landscape. For those building with React and Next.js, Floating UI provides a `useFloating` hook that simplifies the process of attaching a floating element to a reference element. The package also offers interaction hooks for building complex and accessible components like dropdowns, menus, and comboboxes. A new library called Base UI, from the creators of Radix, Material UI, and Floating UI itself, is built upon Floating UI's positioning capabilities. This further solidifies its position as the go-to foundation for new, modern component systems focused on accessibility and developer experience.

Get your own daily briefing

Scout delivers personalized news, insights, and conversations tailored to your role and industry.

Download on the App Store

Shared from Scout - Be the smartest in the room.