Wikidown

Home / Getting Started / Clickable Maps

Clickable Maps with Inline SVG

Make any image clickable, with areas that link to wiki pages, using a plain inline <svg>. You don't need JavaScript, plugins or a special Wikidown feature.

What it is and when to use it

Wikidown passes raw HTML and inline SVG in markdown straight through. Since 0.12, export-html also rewrites relative .md hrefs to .html inside them (see Format § Raw HTML and inline SVG). So an <svg> that draws an image and wraps shapes in <a href="Page.md"> links works as an image map, both in the wiki on GitHub and on the exported site.

Use it for any image whose areas should link to pages:

This pattern already runs in production on a Wikidown-built site, as a continent map with zoomable region pages.

Minimal example

Put the image in .attachments like any other wiki image, then add the SVG to the page. This example assumes the page is one folder below the wiki root, so the image path starts with ../:

<svg class="map" viewBox="0 0 1000 600" xmlns="http://www.w3.org/2000/svg"
     role="img" aria-label="Map of the region">
  <image href="../.attachments/region-map.png" width="1000" height="600"/>
  <a href="Places/North-Town.md" aria-label="North Town">
    <path class="area" d="M120,80 L380,60 L400,260 L140,280 Z"/>
  </a>
  <a href="Places/Harbor.md" aria-label="Harbor">
    <circle class="pin" cx="720" cy="430" r="14"/>
    <circle class="hit" cx="720" cy="430" r="60"/>
  </a>
</svg>

Then add the matching CSS to the site's stylesheet, assets/wikidown.css (see Customizing the Theme):

.content svg.map { width: 100%; height: auto; display: block; }
.map .area { fill: #fff; fill-opacity: 0; stroke: none; cursor: pointer; }
.map a:hover .area, .map a:focus .area { fill-opacity: 0.2; }
.map .pin { fill: #fff; stroke: #222; stroke-width: 4; }
.map a:hover .pin { fill: #f5c542; }
.map .hit { fill: transparent; }   /* big invisible touch target for phones */

Areas are invisible until you hover over them or focus them with the keyboard. Pins are always visible.

Tips

Limitations