HTML - <map> Tag



HTML offers excellent assistance for enhancing the interactivity of websites. HTML offers the image mapping feature when we want to make the graphics more interactive. Using image mapping, we can navigate between images within the same frame and interact with the image. When we wish to accomplish a feature like zooming in on the website's image, this feature is helpful. There will be a clickable area on each image, and we can set the URLs or other images to redirect when the user clicks on that area.

An image map is defined by the combination of the HTML <area> and <map> tags. An image map consists of an image with clickable portions; by clicking the image, a new window or the specified location will open. The <area> element, which specifies the location and type of the area, may contain more than one instance. Without separating the image, you may quickly link any portion of image to other documents using the <map> element.

Syntax

Following is the syntax for HTML <map> tag −

<map name="">...</map>

Specific Attributes

The HTML <map> tag also supports the following additional attributes −

Supported attribute for the <html> tag −

S.No. Attribute & Description
1

name

Defines a unique name for the map tag.

Example

Let’s look at the following example, where we are going to use the <map> tag and navigate to another page by specifying the link.

<!DOCTYPE html>
<html>
   <body style="background-color:#EAFAF1">
   <img src="https://www.tutorialspoint.com/cg/images/logo.png" alt="Workplace" usemap="#workmap" width="200" height="100">
   <map name="workmap">
      <area shape="rectangle" coords="33,45,271,300" alt="tutorial" href="https://www.tutorialspoint.com/index.htm">
   </map>
</body>
</html>

When we execute the above code, it will generate an output consisting of an image along with CSS applied to the webpage. When the user clicks the image, it will navigate to the link we have mentioned in the code.

Example

Consider another scenario where we are going to use the <map> tag to navigate to another image within the same frame.

<!DOCTYPE html>
<html>
<body>
   <center>
      <p>Click on Images where the cursor clickable.
      </p>
      <img src="https://www.tutorialspoint.com/cg/images/logo.png" alt="logo" usemap="#tutorial">
      <map name="tutorial">
         <area shape="rect"
         coords="0, 0, 52, 52"
         alt="tutorial"
         href="https://www.tutorialspoint.com/html/images/html.jpg">
      </map>
   </center>
</body>
</html>

On running the above code, the output window will pop up, displaying the image uploaded to the webpage. When the user clicks on the image, it navigates within the same frame and displays another image.

html_tags_reference.htm
Advertisements