--- url: "https://web.dev/learn/css/popover-and-dialog" titulek: "Popover and dialog | web.dev" h1: "Popover and dialog Stay organized with collections Save and categorize content based on your preferences." popis: "A popover is any element with a popover attribute, and is useful for a wide range of interactive patterns, including tooltips, alerts, toasts and more." jazyk: "en" kanonicka: "https://web.dev/learn/css/popover-and-dialog" drobecky: ["web.dev", "Resources", "CSS"] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-14 00:55:28" znaku: 10752 slov: 1797 kodovani: "iso-8859-2" sha256: "43ffd4612a4a3af9e13c4412ea741e285a0ed5adc5cdf2fa037267729b6d54c1" --- Popover and dialog Stay organized with collections Save and categorize content based on your preferences. A popover is any element with a `popover` attribute, and is useful for a wide range of interactive patterns, including tooltips, alerts, toasts and more. `
My popover content
` The `popover` attribute hides the element by default, and you have to provide a way for users to open it. While popovers are placed in the top layer, above all other content, they are not modal. This means you can still interact with content outside of the popover. Controlling popovers Before we explore the different kinds of popovers and how they behave, look at how to open and close your popovers. Declaratively Popovers can be controlled entirely in HTML, without needing to use JavaScript, using buttons (and inputs with the `button` type) and the `popovertarget` attribute. The popover in the previous code snippet has an `id` of `my-popover`, and you can use this to refer to the popover. `` You can also specify if a button should open or close a popover using `popovertargetaction="show"` and `popovertargetaction="hide"`. With JavaScript You can also control a popover using JavaScript, which is useful when you want to show a popover in response to something besides a user's click a button. To do this, you need to get the popover element, and then call `showPopover()`, `hidePopover()`, or `togglePopover()`. Types of popovers When you add a popover to your site, there are a lot of interactions to consider. How does it open? How can users dismiss it? What happens to other open popovers? There are three types of popovers, and you can choose the type that provides behavior and interactions required by your use case. Auto popovers Auto popovers have the most functionality built in, and are the default if you don't specify a type. `
My popover
` In many cases, you don't want to have multiple popovers open at the same time, so auto popovers close other auto popovers when they are opened. They also support "light dismiss", meaning if you click outside of the popover, it closes automatically. It can also be closed with the Esc key. Manual popovers While the auto popover behavior covers a lot of use cases, there are instances where you may need more control of your popovers. With manual popovers, you have a lot more control, and are also responsible for a lot more of the behavior. `
My popover
` This popover will only close when you explicitly close it–it can't be closed by light dismiss or the `Esc` key. It does allow you to open multiple popovers simultaneously. Hint popovers You may also want to use popovers to add tooltips to your page. In this pattern, you want to be able to hover over an item, and see a description. Only one should be open at a time. If you use auto popovers, opening one will close any other open auto popovers. If you use manual popovers, you need to manually implement a lot of the behavior, including closing other popovers. Hint popovers provide a third option with behavior similar to auto popovers. However, opening a hint popover doesn't close auto popovers. `
My popover
` Hint popovers are useful for supplementary information that is secondary to the primary content. You'll often want to trigger hint popovers with non-click events like hover or focus. Positioning your popover By default, your popovers will open up in the middle of the screen. They are added to the top layer, above all your other content, and can be positioned relative to the viewport. This isn't always ideal, as you often want to place your popover close to the item that triggers them. [Anchor positioning](/learn/css/anchor-positioning) provides a way to do that. There are two steps to anchor positioning- defining the anchor element and placing your element relative to that anchor. Popovers can handle the first step, by setting an implicit anchor for you. When you open a popover using `