Certified HTML Designer Learning Resources Applying Image Maps

Learning Resources
 

Applying Image Maps


An image map allows you to create an image with multiple clickable areas, each linking to different destinations. Here’s a step-by-step guide to creating and applying image maps:


1. Image

First, select a suitable image for your map. Ideally, choose an image with clear, distinct sections that can be easily defined with coordinates. For example, a map of a country with well-defined borders or an infographic with clearly marked sections works well. For more abstract images or images with less distinct boundaries, consider the image’s practicality for your needs.


2. Coordinates

Once you have your image, you need to determine the coordinates of the areas you want to make clickable. Use an image editor like MS Paint or a more advanced tool to find these coordinates. Here’s a basic approach:


Open the image in your editor.

Use the editor's tools to pinpoint the coordinates for the clickable areas. You can write down or save these coordinates for later use in your HTML code.


3. Hot Spots

With your coordinates ready, you can define clickable areas on your image using HTML. There are three common shapes for defining hot spots:


Rectangle (rect): Requires two coordinates — the top-left and bottom-right corners.

Circle (circle): Requires the center coordinate and radius. Remember, the radius is half of the diameter.

Polygon (poly): Uses multiple coordinates for each vertex of the polygon. List these coordinates in order to define the shape.


4. Map Name

Each image map should have a unique name to link it with the corresponding image. This is crucial if you have multiple maps on the same page. The <map> tag in HTML uses the name attribute to assign this identifier.


5. Area & Anchor Tags

<area> Tag: Defines the clickable areas within the image map. It includes attributes like shape, coords, href, and alt.

shape specifies the shape of the clickable area (rect, circle, poly).

coords provides the coordinates for the shape.

href specifies the URL or anchor to navigate to when the area is clicked.

alt provides alternative text for the clickable area.

<a> Tag: Although not used directly within the image map, it’s worth noting that you can use the href attribute to define links, which can be applied similarly in other contexts.


6. Final Code

Combine all the elements into your final HTML code. Here’s an example:

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Image Map Example</title>

</head>

<body>

    <h1>Interactive Image Map Example</h1>

    <img src="world-map.jpg" alt="World Map" usemap="#worldmap">


    <map name="worldmap">

        <!-- Define a rectangular area -->

        <area shape="rect" coords="34,44,270,350" href="https://en.wikipedia.org/wiki/United_States" alt="United States">


        <!-- Define a circular area -->

        <area shape="circle" coords="150,150,60" href="https://en.wikipedia.org/wiki/France" alt="France">


        <!-- Define a polygonal area -->

        <area shape="poly" coords="200,200,300,200,300,300,200,300" href="https://en.wikipedia.org/wiki/Spain" alt="Spain">

    </map>


    <p>Click on different regions of the map to learn more about each country.</p>

</body>

</html>


7. Other Tips

Use Anchors for Bookmarks: You can link to different sections on the same page using anchors, e.g., <a href="#section1">.

Mailto Links: Create email links with mailto: e.g., <a href="mailto:[email protected]">Email Us</a>.

Specify Target: Use the target attribute to control where the link opens, e.g., target="_blank" to open in a new tab.


By following these steps and guidelines, you can effectively apply image maps to create interactive and engaging web pages.

 For Support