I have an image and I want to add a tooltip. this is the code:
<img src='info.svg' width='20' height='20' />
how do I add a tooltip?
I have an image and I want to add a tooltip. this is the code:
<img src='info.svg' width='20' height='20' />
how do I add a tooltip?
You can use title
attribute for any html tags:
<img src='info.svg' width='20' height='20' title='Hello'/>
While SergeiMinaev's answer is absolutely great and it is evidently true that you can have a tooltip with the title
attribute, I will focus on customizable alternatives. We can wrap a div
around the image and a hidden div with absolute
position that will only be displayed on hover
.
.hoverable-image {
position: absolute;
}
.hoverable-image > div {
position: absolute;
left: 40%;
top: 40%;
}
.hoverable-image:not(:hover) > div {
display: none;
}
<div class="hoverable-image">
<img src="https://image.shutterstock.com/image-illustration/3d-small-people-jumped-pleasure-260nw-67359301.jpg">
<div><span style="background-color: gray; color: purple;">Some Tooltip</span></div>
</div>