Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP C C++ C# AWS W3.CSS HOW TO BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST TOOLS

HTML Tutorial

HTML HOME HTML Introduction HTML Editors HTML Basic HTML Elements HTML Attributes HTML Headings HTML Paragraphs HTML Styles HTML Formatting HTML Quotations HTML Comments HTML Colors HTML CSS HTML Links HTML Images HTML Project HTML Favicon HTML Page Title HTML Tables HTML Lists HTML Block & Inline HTML Div HTML Classes HTML Id HTML Buttons HTML Iframes HTML JavaScript HTML File Paths HTML Head HTML Layout HTML Responsive HTML Computercode HTML Semantics HTML Style Guide HTML Entities HTML Symbols HTML Emojis HTML Charsets HTML URL Encode HTML vs. XHTML

HTML Forms

HTML Forms HTML Form Attributes HTML Form Elements HTML Input Types HTML Input Attributes Input Form Attributes

HTML Graphics

HTML Canvas HTML SVG

HTML Media

HTML Media HTML Video HTML Audio HTML Plug-ins HTML YouTube

Web APIs

Web APIs Geolocation API Drag and Drop API Popover API Web Storage API Web Workers API Server-Sent Events API

HTML Cert

HTML Certificate

HTML Examples

HTML Examples HTML Editor HTML Quiz HTML Exercises HTML Challenges HTML Website HTML Syllabus HTML Study Plan HTML Interview Prep HTML Summary HTML Accessibility

HTML References

HTML Tag List HTML Attributes HTML Global Attributes HTML Browser Support HTML Events HTML Colors HTML Canvas HTML Audio/Video HTML Doctypes HTML Character Sets HTML URL Encode HTML Lang Codes HTTP Messages HTTP Methods PX to EM Converter Keyboard Shortcuts

Popover API


Share

Popover API

The Popover API is a built-in HTML feature for making things that pop up on top of the page, like menus, tooltips, info boxes, or small notifications, without writing any JavaScript.

Before it existed, developers had to write their own code to:

  • show and hide the element
  • keep it on top of everything else (the z-index problem)
  • close it when you click outside it or press Esc

The browser now handles all of that for you. The Popover API works in all modern browsers.

Here, we show a simple Popover API example:

Example

A simple popover:

<button popovertarget="tip1">Show Tip</button>

<div id="tip1" popover>
Here we can show a helpful tip.
</div>
Try it Yourself »

How it Works

  • The popovertarget attribute in <button>, connects the button to the popover by its id
  • The popover attribute in <div>, turns the div into a popover. It stays hidden until something opens it
  • Click the button and the popover appears. Click outside it, or press Esc, and it closes

In one sentence: Add popovertarget to a button and popover to an element, and the browser gives you a working pop-up that shows, hides, stays on top, and closes on its own.

Tip: There are two popover types:

  • popover (same as popover="auto") closes when you click outside it, and opening one closes any other open auto popover.
  • popover="manual" stays open until you close it yourself. This suits things like toast notifications.


Browser Support

The numbers in the table specify the first browser version that fully supports Popover API.

API
Popover 114 114 125 17 100

Useful Extras

It is possible to choose what the button should do, with the popovertargetaction attribute.

In the following example we create two buttons, one for "Show" popover and one for "Hide" popover:

Example

Show and hide popover:

<button popovertarget="tip1" popovertargetaction="show">Show</button>
<button popovertarget="tip1" popovertargetaction="hide">Hide</button>

<div id="tip1" popover>
Here we can show a helpful tip.
</div>
Try it Yourself »

The default value of the popovertargetaction attribute is toggle, which toggles between open and close.


Style Popover with CSS

Here we style the popover with some padding and rounded borders. We also style the viewbox behind the popover with the CSS ::backdrop pseudo-element:

Example

Style a popover:

[popover] {
  padding: 1rem;
  border-radius: 8px;
}
  [popover]::backdrop {
  background: rgb(0 0 0 / 0.3); /* dim the page behind popover */
}
Try it Yourself »

Use Popover or <dialog>?

  • Use a popover for light, non-blocking things like menus, tooltips, and hints. You can still use the rest of the page while it is open
  • Use a modal <dialog> when the user has to deal with it before doing anything else, like a "Are you sure you want to delete?" box

Free account

Track your progress

XP earned 0 Day streak 0 Spaces 0 League —

New

Learn in Adventure Mode W3Schools Adventure App

Coding fundamentals as bite-sized lessons and challenges.

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.