Alt text, short for alternative text, is added to an image tag in HTML. This text appears inside the image container when the image cannot be displayed. It helps with accessibility and SEO.
However, by default, browsers do not display the alt text on hovering over the image. If you want to show a tooltip containing some text (like the alt text or something else) when a user hovers over an image, you can use the
title attribute of the
img tag in HTML.
Here's how you can do it:
In this code snippet, when you hover over the image, the 'Alternative Text' will be shown as a tooltip.
Note: While the
title attributes can contain the same text, they serve different purposes. The
alt attribute provides alternative information for an image if a user for some reason cannot view it. The
title attribute provides advisory information about the element for which it is set.