totn HTML

HTML: <map> tag

This HTML tutorial explains how to use the HTML element called the <map> tag with syntax and examples.

Description

The HTML <map> tag is used to define an image map with clickable areas (or hotspots). Within the <map> tag, clickable areas are created using the <area> tag and each clickable area can have a hyperlink associated with it. This tag is also commonly referred to as the <area> element.

Syntax

In HTML, the syntax for the <map> tag is: (example creates an image map using chem.png with two clickable areas with hyperlinks to the Helium and Neon pages)

<body>

  <img src="chem.png" width="500" height="500" alt="Elements" usemap="#chemistry">
  
  <map name="chemistry">
    <area shape="rect" coords="0,0,35,50" href="he.php" alt="Helium">
    <area shape="circle" coords="140,165,50" href="ne.php" alt="Neon">
  </map>

</body>

Attributes

Only the Global Attributes apply to the <map> tag. There are no attributes that are specific to the <map> tag.

Note

  • The HTML <map> element is found within the <body> tag.
  • The usemap attribute for the <img> tag is must be the same as the name attribute for the <map> tag creating a relationship between these two elements.

Browser Compatibility

The <map> tag has basic support with the following browsers:

  • Chrome
  • Android
  • Firefox (Gecko)
  • Firefox Mobile (Gecko)
  • Internet Explorer (IE)
  • Edge Mobile
  • Opera
  • Opera Mobile
  • Safari (WebKit)
  • Safari Mobile

Example

We will discuss the <map> tag below, exploring examples of how to use the <map> tag in HTML5, HTML 4.01 Transitional, XHTML 1.0 Transitional, XHTML 1.0 Strict, and XHTML 1.1.