Embedding an Image in a Hyperlink

Description

A common use of the img element is to create an image-based hyperlink in conjunction with the a element.

Example

The following code shows how you can use the img and a elements together.


<!DOCTYPE HTML>
<html>
<body>
  <p>
    <a href="http://java2s.com/page.html">
       <img ismap src="http://www.java2s.com/style/download.png"/>
    </a><!--from   www . j  av  a2 s  .  c  o  m-->
  </p>
</body>
</html>

Click to view the demo

Note

If you apply ismap attribute to the img element, you create a server-side image map, which means that the position you clicked on the image is appended to the URL.

For example, if you clicked 4 pixels from the top and 10 pixels from the left edges of the images, the browser will navigate to the following:

http://java2s.com/page.html?10,4




















Home »
  HTML CSS »
    HTML »




HTML Introduction
HTML Document
HTML Section
HTML Group Content
HTML Text Marker
HTML Table
HTML Form
HTML Embed