Create Image-Map Quickly Using Online Tools and Code

Create Image-Map for Responsive Layouts: Tips & ExamplesAn image map lets you define clickable regions on an image so different parts of the same image link to different destinations. Historically implemented with HTML

and

elements, image maps remain useful for diagrams, floor plans, product images, and interactive illustrations. Making image maps responsive ensures they work correctly across screen sizes and input methods. This article explains how responsive image maps work, when to use them, practical techniques, accessibility considerations, and several working examples you can adapt.


Why use image maps in responsive designs?

  • Maintain a single image: Instead of slicing an image into multiple elements, an image map preserves one visual asset while allowing multiple interactive areas.
  • Semantic links: Each area can have its own href, title, and aria attributes, making it straightforward to represent different links.
  • Useful for complex shapes: Polygons and circles let you target irregular regions that would be difficult to recreate with separate HTML elements.

Key challenges for responsive image maps

  1. Coordinates scale differently: HTML image maps use pixel coordinates tied to the image’s intrinsic size. When the displayed image size changes (e.g., on mobile), coordinates no longer match.
  2. Touch vs. mouse: Small target areas can be hard to tap on touch devices.
  3. Accessibility: Screen readers and keyboard users need clear, descriptive labels and proper focus behavior.
  4. Performance: Scripts that recompute coordinates on resize must be efficient.

Techniques to make image maps responsive

Below are several approaches, from pure HTML/CSS solutions to JavaScript-assisted methods.

1) Using the HTML and

with a scaling script

The classic solution keeps the native

and

markup but recalculates coordinates when the image resizes. This approach preserves semantics and works with standard anchors.

Example strategy:

  • Store the original dimensions of the image (naturalWidth/naturalHeight).
  • On load and on resize, compute the scale factor between the current rendered width/height and the natural size.
  • Multiply all original area coordinates by the scale factor and set the area coords attribute.

JavaScript example:

<img id="floorplan" src="floorplan.jpg" usemap="#fpmap" alt="Office floor plan"> <map name="fpmap">   <area shape="poly" coords="50,60,120,60,120,130,50,130" href="/room1" alt="Room 1">   <area shape="circle" coords="200,200,30" href="/stairwell" alt="Stairwell"> </map> <script> function resizeMap(img, mapName) {   const map = document.querySelector(`map[name="${mapName}"]`);   if (!map) return;   const origWidth = img.naturalWidth;   const origHeight = img.naturalHeight;   const scaleX = img.clientWidth / origWidth;   const scaleY = img.clientHeight / origHeight;   map.querySelectorAll('area').forEach(area => {     const original = area.dataset.origCoords;     if (!original) {       area.dataset.origCoords = area.getAttribute('coords');     }     const coords = area.dataset.origCoords.split(',').map(Number);     const scaled = coords.map((n, i) => (i % 2 === 0 ? n * scaleX : n * scaleY));     area.setAttribute('coords', scaled.join(','));   }); } const img = document.getElementById('floorplan'); if (img.complete) resizeMap(img, 'fpmap'); img.addEventListener('load', () => resizeMap(img, 'fpmap')); window.addEventListener('resize', () => resizeMap(img, 'fpmap')); </script> 

Notes:

  • Use data-orig-coords to preserve original values.
  • Consider debouncing the resize handler for performance.

SVG scales naturally and supports shapes (rect, circle, polygon) that can be given links and ARIA attributes. Place an SVG over the image (or use the image as an SVG ) so the shapes scale with the container.

Basic HTML structure:

<div class="responsive-map" style="position:relative; max-width:800px;">   <img src="product.jpg" alt="Product" style="width:100%; height:auto; display:block;">   <svg viewBox="0 0 1000 600" preserveAspectRatio="xMidYMid meet"        style="position:absolute; left:0; top:0; width:100%; height:100%;">     <a href="/part1"><polygon points="50,60 120,60 120,130 50,130" aria-label="Part 1"></polygon></a>     <a href="/part2"><circle cx="800" cy="300" r="30" aria-label="Handle"></circle></a>   </svg> </div> 

Advantages:

  • No need to recalculate coordinates on resize — SVG coordinate system scales automatically.
  • Styling, hover effects, transitions, and pointer-events are easy to manage with CSS.
  • Better support for complex interactions, tooltips, and animations.

Accessibility tips for SVG:

3) CSS positioned hotspots

Create absolutely positioned elements (buttons or links) over the image, sized using percentages so they scale responsively with the container.

Example:

<div class="image-wrap" style="position:relative; width:100%; max-width:800px;">   <img src="diagram.jpg" alt="Diagram" style="width:100%; height:auto; display:block;">   <a href="/detail1" class="hotspot" style="position:absolute; left:12%; top:20%; width:10%; height:8%;">Part 1</a>   <a href="/detail2" class="hotspot" style="position:absolute; left:60%; top:45%; width:8%; height:8%;">Handle</a> </div> <style> .image-wrap .hotspot{   background:rgba(255,255,255,0.001); /* make area clickable but invisible */   outline: none; } .image-wrap .hotspot:focus, .image-wrap .hotspot:hover {   background: rgba(255,255,0,0.2); } </style> 

Pros:

  • Simple to implement with HTML/CSS.
  • Works well with CSS focus styles for accessibility.
    Cons:
  • Harder to match irregular shapes unless using many small elements or clip-paths.

Accessibility considerations

  • Provide clear alt text for the image describing its overall content.
  • Each interactive area needs an alt or aria-label describing the target (e.g., “View Room 1 details”).
  • Ensure keyboard users can tab to each area or hotspot; add tabindex where necessary.
  • Make touch targets large enough (WCAG recommends 44×44 CSS pixels). If regions are small, increase hit area with padding or invisible edges.
  • Announce state changes with ARIA live regions if clicking opens overlays/modals.

Tips for authoring and testing

  • Work from a high-resolution master image with known natural dimensions; record original coords for scaling or for translating to SVG viewBox coordinates.
  • Use percentage-based coordinates or an SVG viewBox to avoid repeated recalculation.
  • Test across browsers and devices (mobile, tablet, desktop) and with keyboard-only navigation and screen readers.
  • If using JS to resize coords, debounce resize events (e.g., 100–200ms) to avoid excessive recalculation.
  • For touch devices, add visual feedback on tap and consider slightly expanding clickable areas.

Examples and patterns

  1. Product detail page: SVG overlay on a product photo showing parts that link to specs, each with hover tooltips.
  2. Campus map: An SVG map where each building is a polygon with a link; accessible labels provide building info.
  3. Interactive diagram: Use CSS hotspots for general areas and SVG for complex shapes like irregular equipment outlines.
  4. Floor plan with zoom: Combine responsive SVG with pan/zoom (via viewBox or libraries like panzoom) for mobile-friendly navigation.

Libraries and tools

  • image-map-resizer — small script to scale HTML image maps (works with
    /

    ).
  • jQuery.rwdImageMaps — older jQuery plugin for responsive image maps.
  • panzoom / svg-pan-zoom — for interactive zooming/panning of SVGs.
  • Figma/Illustrator — for creating precise regions and exporting coordinates.

Troubleshooting common issues

  • Clicks land in the wrong spot: ensure coords were scaled from the image’s natural size, not the displayed size.
  • Small touch targets: increase area size or provide an alternate list of links below the image.
  • Overlapping areas: order matters — later areas may receive events first; use pointer-events CSS or separate SVG layers.

Quick checklist

  • Use SVG overlays when possible for scalability and interactivity.
  • If using
    , store original coords and recalculate on resize.
  • Ensure each region has clear accessible labels and is keyboard-focusable.
  • Make touch targets at least ~44×44 CSS pixels.
  • Test on multiple devices and screen sizes.

A responsive image map keeps your interactive visuals usable on any device. Choose SVG for flexibility and scaling, use scripts to adapt HTML image maps when necessary, and always prioritize accessibility and touch usability when designing hotspots.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *