Display Text on Mouseover for Image in Html

I would like to display text when the user mouseovers the image.

How can I do this in HTML/JS?

You can use title attribute.

<img src="smiley.gif"  title="Smiley face"/>

You can change the source of image as you want.

And as @Gray commented:

You can also use the title on other things like <a ... anchors, <p>, <div>, <input>, etc. See: this

1

You can use CSS hover:

div {
  display: none;
  border: 1px solid #000;
  height: 30px;
  width: 290px;
  margin-left: 10px;
}

a:hover+div {
  display: block;
}
<a><img src='
<div>text</div>
0

You can do like this also:

HTML:

<a><img src=' onmouseover="somefunction();"></a>

In javascript:

function somefunction()
{
  //Do somethisg.
}

​

You can use CSS hover in combination with an image background.

.image {
  background: url();
  height: 100px;
  width: 100px;
  display: block;
  float: left;
}

.image a {
  display: none;
}

.image a:hover {
  display: block;
}
<div class="image"><a href="#">Text you want on mouseover</a></div>
0
Maya Lin-Takahashi

Maya Lin-Takahashi

Consumer Tech & Gadget Reviewer

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.

Share this article
Twitter Facebook Pinterest