Up to date
Published
2 min read

Trevor I. Lasn

Staff Software Engineer, Engineering Manager

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.

index.html
<button popovertarget="info">Toggle Popover</button>
<div id="info" popover>
<p>Popover content appears above other elements</p>
</div>

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.


Found this article helpful? You might enjoy my free newsletter. I share dev tips and insights to help you grow your coding skills and advance your tech career.

Interested in supporting this blog in exchange for a shoutout? Get in touch.


Liked this post?

Check out these related articles that might be useful for you. They cover similar topics and provide additional insights.

Webdev
6 min read

Integrating Docker with React

Streamline your development and deployment processes

Jul 16, 2020
Read article
Webdev
4 min read

Self-Taught Developer's Guide to Thriving in Tech

How to turn your non-traditional background into your biggest asset

Sep 28, 2024
Read article
Webdev
4 min read

Mental Toughness is the Best Quality a Developer Can Have

Mental toughness gets developers through challenges like debugging, picking up new tools, and hitting tight deadlines. It’s about staying calm and pushing through when things get tough.

Sep 12, 2024
Read article
Webdev
4 min read

Understanding Vue's Suspense

How the Suspense component manages async dependencies and improves loading states in Vue apps

Aug 23, 2024
Read article
Webdev
4 min read

Speed Up Your Website With rel='preconnect' and increase PageSpeed Insights Score

Using link rel='preconnect' can improve your website's performance by reducing connection setup times to key external domains.

Sep 13, 2024
Read article
Webdev
4 min read

How To Implement Content Security Policy (CSP) Headers For Astro

Content Security Policy (CSP) acts like a shield against XSS attacks. These attacks are sneaky - they trick your browser into running malicious code by hiding it in content that seems trustworthy. CSP's job is to spot these tricks and shut them down, while also alerting you to any attempts it detects.

Oct 16, 2024
Read article
Webdev
4 min read

The What, Why, and How of Using a Skeleton Loading Screen

Skeleton loading screens enhance user experience and make your app feel faster

Nov 12, 2020
Read article
Webdev
3 min read

CVE-2025-29927 - Next.js Middleware Bypass Explained In Simple Terms

The vulnerability skips Next.js middleware security checks by adding a single HTTP header

Apr 6, 2025
Read article
Webdev
5 min read

WebAssembly (Wasm): When (and When Not) to Use It

Understanding the real use cases for WebAssembly beyond the performance hype

Nov 25, 2024
Read article

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.