Sentry Logo Debug Microservices & Distributed Systems

Join my free newsletter to get my latest articles and updates.

2 min read
Up to date

Trevor I. Lasn

My day-job is Staff Software Engineer & Engineering Manager. Building courses.reviews as a hobby

Native Popover Element with HTML

Create overlays and dropdowns easily with the native HTML popover API

Building overlay UI elements like tooltips and dropdowns has always required complex JavaScript libraries. The new HTML Popover API changes this with native browser support for floating elements.

What is Lorem Ipsum?

Lorem Ipsum is simply dummy text of the printing and typesetting industry.

The Popover API introduces a new popover attribute that transforms any HTML element into a floating overlay.

The browser handles all the complex positioning, stacking order, and focus management automatically. This means we can create interactive UI elements without wrestling with z-index, click-outside handling, or managing focus states.

We can control popovers through two modes: auto and manual

Auto popovers dismiss themselves when clicking outside or when another auto popover opens, perfect for simple tooltips or dropdowns. Manual popovers give us more control over their behavior, useful for complex dialogs or multi-step flows.

The JavaScript API provides three methods to control popovers programmatically: showPopover(), hidePopover(), and togglePopover()

These methods return promises, allowing us to react to state changes and coordinate animations. The API also provides the :popover-open CSS pseudo-class for styling popovers based on their visibility state.

The Popover API represents a significant step forward in web platform capabilities. Instead of relying on complex positioning libraries or managing overlay states manually, we now have a native solution that handles these challenges elegantly. This means simpler code, better performance, and improved accessibility out of the box.

Browser support for the Popover API is growing. Chrome already supports it, and Safari has implemented the feature behind a flag. As adoption increases, we can expect this native solution to become the standard way of creating overlay UI elements on the web.

If you enjoyed reading this article, you might enjoy using my new web app too!

courses.reviews: In-depth reviews and exclusive discounts for high-quality coding courses.



This article was originally published on https://www.trevorlasn.com/blog/native-popover-with-html. It was written by a human and polished using grammar tools for clarity.

Interested in a partnership? Shoot me an email at hi [at] trevorlasn.com with all relevant information.