How to implement a basic client-side image map in HTML
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 ; 2. Define the <map> element, whose name attribute corresponds to the usemap value (excluding #), such as
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
, ordefault
) -
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">
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!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

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

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

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.

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.

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

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

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

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
