Bootstrap5 Popover
A popover control is similar to a tooltip; it is displayed after the mouse clicks on the element. Unlike a tooltip, it can display more content.
How to Create a Popover
Create a popover by adding data-bs-toggle="popover" to an element.
The content of the title attribute is the popover's title, and the data-bs-content attribute shows the popover's text content:
<button type="button" class=">btn btn-primary
"
data-bs-toggle
=
"
popover
"
title
=
"
Popover Title
"
data-bs-content
=
"
Popover Content
"
Click Me Multiple Times
button
Note: The popover should be written in the JavaScript initialization code.
The following example can use popovers anywhere in the document:
Example
var
popoverTriggerList
=
[
]
.
slice
.
call
(
document
.
querySelectorAll
(
'
[data-bs-toggle="popover"]
'
)
)
var
popoverList
=
popoverTriggerList
.
map
(
function
(
popoverTriggerEl
)
{
return
new
bootstrap
.
Popover
(
popoverTriggerEl
)
}
)
Try it »
Specifying the Popover Position
By default, the popover is displayed on the right side of the element.
You can use the data-bs-placement attribute to set the direction in which the popover displays: top, bottom, left or right:
Example
<a href="" title="Title" data-bs-toggle="popover" data-bs-placement="top" data-bs-content=">I am the content section
"
Click me
a
<a href="" title="Title" data-bs-toggle="popover" data-bs-placement="bottom" data-bs-content=">I am the content section
"
Click me
a
<a href="" title="Title" data-bs-toggle="popover" data-bs-placement="left" data-bs-content=">I am the content section
"
Click me
a
<a href="" title="Title" data-bs-toggle="popover" data-bs-placement="right" data-bs-content=">I am the content section
"
Click me
a
Try it »
Closing Popovers
By default, a popover closes after clicking the specified element again. You can use the data-bs-trigger="focus" attribute to close the popover when clicking outside the element:
Example
<a href="" title=">Dismiss Popover
"
data-bs-toggle
=
"
popover
"
data-bs-trigger
=
"
focus
"
data-bs-content
=
"
Click elsewhere in the document to close me
"
Click me
a
Try it »
**Tip:** If you want to achieve the effect of displaying when the mouse moves over an element and disappearing when it moves away, you can use the data-bs-trigger attribute and set its value to "hover":
Example
<a href="" title="Title" data-bs-toggle="popover" data-bs-trigger="hover" data-bs-content=">Some Content
"
Hover over me
a
Try it »