Table of Contents
tag with the usemap attribute" > 1. Use the How to implement a basic client-side image map in HTML tag with the usemap attribute
2. Define the element
3. Add clickable regions with
Example with multiple areas
Key Points to Remember
Full Working Example
Home Web Front-end HTML Tutorial How to implement a basic client-side image map in HTML

How to implement a basic client-side image map in HTML

Aug 26, 2025 am 08:08 AM
html image mapping

To implement basic client image mapping, you need to follow the following steps: 1. Use the <img src="/static/imghw/default1.png" data-src="floor-plan.png" class="lazy" alt="How to implement a basic client-side image map in HTML" > tag with the usemap attribute, whose value is "#map name", such as Office Floor Plan; 2. Define the <map> element, whose name attribute corresponds to the usemap value (excluding #), such as ; 3. Use the <area> tag to create clickable areas, set shape, coords, href and alt properties, such as rectangular areas coords="left, upper, right, lower", circular coords="center x, center y, radius", polygons are multiple x, y coordinate pairs, and each area should contain alt text to ensure accessibility, and ultimately form a full-featured image map, which can work normally in modern browsers without JavaScript.

How to implement a basic client-side image map in HTML

To implement a basic client-side image map in HTML, you use the <img src="/static/imghw/default1.png" data-src="floor-plan.png" class="lazy" alt="How to implement a basic client-side image map in HTML" > element in combination with the <map></map> and <area> elements. This allows you to define clickable regions (called "hotspots") on an image that can act as links to other pages or resources.

Here's how to do it step by step:

1. Use the <img src="/static/imghw/default1.png" data-src="floor-plan.png" class="lazy" alt="How to implement a basic client-side image map in HTML" > tag with the usemap attribute

Start by adding an image to your page and include the usemap attribute. The value of usemap should be a hash ( # ) followed by the name of the map you'll define.

 <img src="/static/imghw/default1.png"  data-src="floor-plan.png"  class="lazy" alt="Office Floor Plan" usemap="#officemap">

This tells the browser that this image uses an image map named officemap .

2. Define the <map> element

Below or near the image, define the <map> element with a name attribute that matches the value in usemap (without the # ).

 <map name="officemap">
  <!-- clickable areas go here -->
</map>

3. Add clickable regions with <area>

Inside the <map> element, use one or more <area> tags to define clickable shapes. Each <area> specifications:

  • shape : the shape of the region ( rect , circle , poly , or default )
  • coords : coordinates that define the region
  • href : the link destination
  • alt : alternative text (important for accessibility)

Example with multiple areas

 <map name="officemap">
  <!-- Rectangle: coordinates="left, top, right, bottom" -->
  <area shape="rect" coordinates="0,0,100,100" href="reception.html" alt="How to implement a basic client-side image map in HTML">

  <!-- Circle: coordinates="center_x, center_y, radius" -->
  <area shape="circle" coordinates="200,200,50" href="kitchen.html" alt="Kitchen">

  <!-- Polygon: list of x,y pairs -->
  <area shape="poly" coordinates="300,100,400,100,400,200,300,200" href="conference.html" alt="Conference Room">
</map>

Key Points to Remember

  • Coordinate system : The top-left corner of the image is (0,0). Coordinates are in pixels.
  • Image size matters : If the image is resized using CSS, the coords values ​​(which are based on the original image dimensions) may no longer align correctly. Use the actual displayed size or scale coordinates accordingly.
  • Accessibility : Always include the alt attribute in each <area> to help screen readers.
  • Default fallback : You can include a default area that covers the whole image:
     <area shape="default" href="home.html" alt="Home">

Full Working Example

 


  
  Image Map Example

<img src="/static/imghw/default1.png" data-src="floor-plan.png" class="lazy" alt="Office Floor Plan" usemap="#officemap"> How to implement a basic client-side image map in HTML Kitchen Conference Room

That's it — you now have a fully functional client-side image map. No JavaScript required, and it works across all modern browsers. Just make sure your coordinates match the image dimensions and test the links to ensure they work as expected.

The above is the detailed content of How to implement a basic client-side image map in HTML. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to create subscript and superscript in HTML How to create subscript and superscript in HTML Aug 20, 2025 am 11:37 AM

TocreatesubscriptandsuperscripttextinHTML,usetheandtags.1.Usetoformatsubscripttext,suchasinchemicalformulaslikeH₂O.2.Usetoformatsuperscripttext,suchasinexponentslike10²orordinalslike1ˢᵗ.3.Combinebothtagswhenneeded,asinscientificnotationlike²³⁵₉₂U.The

How to center a div in HTML5? How to center a div in HTML5? Aug 21, 2025 pm 05:32 PM

Tocenteradivhorizontally,usemargin:0autowithadefinedwidth.2.Forhorizontalandverticalcentering,applydisplay:flexontheparentwithjustify-content:centerandalign-items:center.3.Alternatively,useCSSGridwithplace-items:centerforbothdirections.4.Asafallback,

How to disable a form element in HTML How to disable a form element in HTML Aug 30, 2025 am 08:45 AM

To disable HTML form elements, you can use the disabled attribute, which can prevent user interaction and the element value will not be submitted with the form. This attribute is of a Boolean type and can be directly added to form element tags such as input, textarea, select, or button. For example, it can also be dynamically controlled through JavaScript, such as document.getElementById("myInput").disabled=true. If the element cannot be edited but the value is still submitted, you should use the readonly attribute. The disabled attribute is simple and effective and widely supported.

How to restrict file types for an upload input in HTML How to restrict file types for an upload input in HTML Aug 24, 2025 am 02:57 AM

Use the accept attribute to limit the upload type of HTML file, such as accept="image/*" only allows images, accept=".pdf" only allows PDF, accept=".doc,.docx,.pdf,.txt" allows multiple specified types, and can combine JavaScript to verify file types to improve user experience, but security verification must be performed on the server side, because the accept attribute is not secure and the browser supports are different, and it is only used to improve availability rather than replace server verification.

How to link to a specific part of a page using anchors in HTML How to link to a specific part of a page using anchors in HTML Aug 31, 2025 am 06:52 AM

TolinktoaspecificpartofapageusinganchorsinHTML,assignauniqueidtothetargetelement,suchas,thencreateahyperlinkwithhref="#section1"toscrolltothatsection,andforcross-pagelinking,usethefullURLlikepage.html#section1,ensuringsmoothnavigationwithou

How to implement a basic client-side image map in HTML How to implement a basic client-side image map in HTML Aug 26, 2025 am 08:08 AM

To implement basic client image mapping, you need to follow the following steps: 1. Use a tag with the usemap attribute, whose value is "#map name", such as

What is ARIA in HTML for accessibility? What is ARIA in HTML for accessibility? Aug 27, 2025 am 04:57 AM

ARIAisneededtoenhancewebaccessibilityfordynamiccontentandcustomUIcomponentsthatlacknativeHTMLsemantics.1)ARIArolesdefineanelement’spurpose(e.g.,role="dialog").2)ARIApropertiesdescribecharacteristics(e.g.,aria-label,aria-describedby).3)ARIAs

What are bull markets and bear markets? How to judge whether a bull market or a bear market? What are bull markets and bear markets? How to judge whether a bull market or a bear market? Sep 05, 2025 am 10:33 AM

How to identify the market bull and bear conversion in the directory? Changes in trading volume. Pay attention to the potential risks in the market. This article will explain in detail what a bull market is and bear market, and how to simply and effectively determine what state the current market is. I will use the Binance platform's operation interface as an example to demonstrate. If you have not registered with Binance Exchange, you can complete the registration through the registration link and APP download address provided below to cooperate with the video tutorial. Binance official website registration: https://static.jbzj.com/qkl/ba/bazc.html (copy the link to the browser to open) Binance Android version APP download: https://static.jbzj.com/qkl/ba/baxz.ht

See all articles