Tek Eye Logo

Tek Eye

HTML Image Hover Effects Using Onmouseover

This article shows a quick and easy way to add a hover effect to a graphic used for a link (anchor). The HTML anchor element, <a></a>, is used to jump, i.e. link, to another web page or location. The hover HTML method used in this article is also called the mouse over effect, because it uses the images's onmouseover event to manipulate the link's graphic. For this hover effect example no cascading style sheets (CSS) are used.

What is a web page link in HTML?

As an example, to link to the home page of this website the HTML code would be:

<a href="https://tekeye.uk">Tek Eye Home Page</a>

It shows in the browser as a link like this:

Tek Eye Home Page

How do I use an image for a link?

Instead of a simple text link the HTML img element can be used to replace the text. Set the HTML image src attribute to the image address (URL) or the path on the web server to the image:

<a href="https://tekeye.uk"><img src="images/home.png" alt="Tek Eye Home"/></a>

In this case the link now shows as a home graphic:

Tek Eye Home

How do I generated a HTML hover image effect?

The mouse over image effect uses a tiny bit of JavaScript on two mouse events, onmouseover and onmouseout. The image hover effects are activated as the events fire when the mouse moves over the graphic and then away from the graphic. Firstly two graphics are required for the effect, usually the same image in different colors. Here are the images used for this example:

Home Icon Green Home Icon

The HTML hover image effect code sets the image src (for source) attribute to the correct graphic using the onmouseover and onmouseout events. This is the code:

<a href="https://tekeye.uk"><img src="images/home.png" alt="Tek Eye Home" onmouseover="this.src='images/home-g.png';" onmouseout="this.src='images/home.png';"/></a>

With this code when the mouse hovers over the home image it turns green:

Tek Eye Home

If the images used are button graphics then you can get button hover effects in a similar way:

Play Button

Author:  Published:  Updated:  

ShareSubmit to TwitterSubmit to FacebookSubmit to LinkedInSubmit to redditPrint Page

Do you have a question or comment about this article?

(Alternatively, use the email address at the bottom of the web page.)

 This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

markdown CMS Small Logo Icon ↓markdown↓ CMS is fast and simple. Build websites quickly and publish easily. For beginner to expert.

Articles on:

Android Programming and Android Practice Projects, HTML, VPS, Computing, IT, Computer History, ↓markdown↓ CMS, C# Programming, Using Windows for Programming

Free Android Projects and Samples:

Android Examples, Android List Examples, Android UI Examples

Tek Eye Published Projects