Bootstrap5 Tooltip
A tooltip is a small pop-up displayed when the mouse moves over an element and disappears when the mouse moves away.
How to Create a Tooltip
Create a tooltip by adding data-bs-toggle="tooltip" to an element.
The content of the title attribute is what the tooltip displays:
<button type="button" class=">btn btn-primary
"
data-bs-toggle
=
"
tooltip
"
title
=
"
I am the tooltip content!
"
Hover over me
button
Note: The tooltip should be written in the JavaScript initialization code: then call the tooltip() method on the specified element.
The following example can use tooltips anywhere in the document:
Example
var
tooltipTriggerList
=
[
]
.
slice
.
call
(
document
.
querySelectorAll
(
'
[data-bs-toggle="tooltip"]
'
)
)
var
tooltipList
=
tooltipTriggerList
.
map
(
function
(
tooltipTriggerEl
)
{
return
new
bootstrap
.
Tooltip
(
tooltipTriggerEl
)
}
)
Try it »
Specifying the Tooltip Position
By default, the tooltip is displayed above the element.
You can use the data-bs-placement attribute to set the direction in which the tooltip displays: top, bottom, left or right:
Example
<a href="" data-bs-toggle="tooltip" data-bs-placement="top" title=">I am the tooltip content!
"
Hover over me
a
<a href="" data-bs-toggle="tooltip" data-bs-placement="bottom" title=">I am the tooltip content!
"
Hover over me
a
<a href="" data-bs-toggle="tooltip" data-bs-placement="left" title=">I am the tooltip content!
"
Hover over me
a
<a href="" data-bs-toggle="tooltip" data-bs-placement="right" title=">I am the tooltip content!
"
Hover over me
a
Try it »