Bootstrap 4 Tooltips
A tooltip is a small pop-up that appears when the mouse is moved over an element and disappears when the mouse is moved away.
How to Create a Tooltip
Create a tooltip by adding data-toggle="tooltip"
to an element.
The content of the title
attribute is what will be displayed in the tooltip:
<a href="#" data-toggle="tooltip" title="I am the tooltip content!">Hover over me</a>
Note: Tooltips must be initialized with jQuery: call the tooltip()
method on the specified element.
The following example allows tooltips to be used anywhere in the document:
Example
$(document).ready(function(){
$('[data-toggle="tooltip"]').tooltip();
});
Specifying Tooltip Position
By default, the tooltip appears above the element.
You can use the data-placement
attribute to set the direction of the tooltip: top, bottom, left, or right:
Example
<a href="#" data-toggle="tooltip" data-placement="top" title="I am the tooltip content!">Hover over me</a>
<a href="#" data-toggle="tooltip" data-placement="bottom" title="I am the tooltip content!">Hover over me</a>
<a href="#" data-toggle="tooltip" data-placement="left" title="I am the tooltip content!">Hover over me</a>
<a href="#" data-toggle="tooltip" data-placement="right" title="I am the tooltip content!">Hover over me</a>
Using tooltips in buttons:
Example
<button type="button" class="btn btn-secondary" data-toggle="tooltip" data-placement="top" title="Tooltip on top">
Tooltip on top
</button>
<button type="button" class="btn btn-secondary" data-toggle="tooltip" data-placement="right" title="Tooltip on right">
Tooltip on right
</button>
<button type="button" class="btn btn-secondary" data-toggle="tooltip" data-placement="bottom" title="Tooltip on bottom">
Tooltip on bottom
</button>
<button type="button" class="btn btn-secondary" data-toggle="tooltip" data-placement="left" title="Tooltip on left">
Tooltip on left
</button>
To add HTML tags to the tooltip content, set data-html="true"
and place the content inside the title
attribute:
Example
<button type="button" class="btn btn-secondary" data-toggle="tooltip" data-html="true" title="<em>Tooltip</em> <u>with</u> <b>HTML</b>">
Tooltip with HTML
</button>
Disabling a button:
Example
<span class="d-inline-block" tabindex="0" data-toggle="tooltip" title="Disabled tooltip">
<button class="btn btn-primary" style="pointer-events: none;" type="button" disabled>Disabled button</button>
</span>