top of page
Writer's picturecompnomics

Creating Image Maps in HTML: Clickable Regions on Your Images



Image maps allow you to transform a single image into multiple clickable areas, each leading to different destinations. Here's the HTML code to create an image map:


1. Define the Image:

Start with the basic <img> tag to display your image:

<img src="image.jpg" alt="Image description" usemap="#myMap">
  • Replace image.jpg with the actual path to your image file.

  • Add a descriptive alt text for accessibility.

  • The usemap attribute specifies the name of the image map you'll define next.


2. Create the Image Map:

Use the <map> element with a unique name attribute (matching the one used in usemap):

HTML

<map name="myMap">
  </map>

3. Define Clickable Areas:

Within the <map> element, use the <area> tag to specify clickable regions:

<area shape="rect" coords="x1,y1,x2,y2" href="link_url" alt="Area description">
  • shape: Defines the shape of the clickable area (e.g., "rect" for rectangle, "circle" for circle).

  • coords: Specifies the coordinates of the shape's boundaries (e.g., "x1,y1" for top-left corner, "x2,y2" for bottom-right corner).

  • href: Defines the URL where users are directed when clicking the area.

  • alt: Provides alternative text for the clickable area, important for accessibility.


Example:

<img src="image.jpg" alt="World map" usemap="#worldMap">

<map name="worldMap">
  <area shape="rect" coords="0,0,200,100" href="europe.html" alt="Europe">
  <area shape="circle" coords="350,150,50" href="asia.html" alt="Asia">
  <area shape="rect" coords="500,50,600,200" href="africa.html" alt="Africa">
</map>

Remember:

  • You can define multiple <area> tags within a single <map> for various clickable regions.

  • Use descriptive alt text for both the image and each clickable area.

  • Consider using image editing software to create accurate coordinates for complex shapes.


By using image maps effectively, you can create interactive and engaging experiences on your webpages, allowing users to explore different sections within an image with a single click.

22 views0 comments

Recent Posts

See All

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
bottom of page