Tooltip is a small box that appears near an element in the DOM when the user hovers over the element. It is used to provide information to the user about the element or component.
We can create a tooltip with bootstrap 4 by adding the data-toggle="tooltip"
attribute to the element.
<element data-toggle="tooltip" title="displays text in tooltip">
</element>
In the title
attribute, we provide the text that needs to be displayed in the tooltip.
In the code written above:
data-toggle="tooltip"
attribute. We also provide the text Hi, I am tooltip
as the title
attribute. This text will be displayed when the user hovers over the element.We can display the tooltip in the positions top
, bottom
, left
, or right
of the element. We can achieve this by providing the data-placement
attribute to the element.
Note: While positioning the tooltip, if there isn’t sufficient space to show the tooltip in the desired position, then it will be displayed in another position.