r/HTML • • Oct 01 '26

Question how do i make a map where clicking on the different countries leads to different pages?

i would also like the country to turn red when you hover over it. the superbad site does something like this on some of its pages.

apologies if i sound like a noob in over my head, but it's for a personal project.

10 Upvotes

16 comments sorted by

4

u/armahillo Expert Oct 01 '26

3

u/sunkist-sucker Oct 01 '26

mozilla my dearly beloved! i'll try this out, ty

4

u/AshleyJSheridan Oct 01 '26

Please don't do this, these are not very accessible and they don't scale well in a responsive layout.

A better option is to just use an SVG (one presumes the map is already SVG, but if not, there are a ton of good SVG maps out there for any area). The SVG format can contain regular links.

2

u/armahillo Expert Oct 01 '26

Agreed SVGs are better, albeit more complicated.

OP provided little context about their experience level or other specifics. .

1

u/AshleyJSheridan Oct 01 '26

They don't have to be complicated at all. Their syntax is very similar to HTML, and they do share many tags and attributes. You can even do it all from within something like Inkscape if you want, you don't need to edit or even look at the raw SVG code.

I'd say that's even easier than an image map.

1

u/armahillo Expert Oct 01 '26

I don’t know how many newer HTML users you’ve encountered on here, but I often see people
struggle with even the most basic of things, like knowing how to structure a document or where and how to use attributes.

Doing an SVG based map is more complicated than an image map. I would not personally use an image map, but I’ve also been writing HTML since 1995, when image maps were novel.

1

u/AshleyJSheridan Oct 01 '26

I really think that opening a map image in Inkscape and adding links is far easier than crafting an image map. The Inkscape approach doesn't even require touching any code, the image map does.

3

u/brisray Oct 01 '26

One of the easiest methods is by using an image map. There are several ways of making those. I recently made something similar using an SVG of the United States from Wikimedia Commons which already had the various states already mapped. I created the links in Inkscape.

Wikimedia Commons has some world maps with the countries already mapped for you or you could use one of the others around.

3

u/Spnkmyr Oct 01 '26 edited Oct 01 '26

You can use the ai2html plugin created by The New York Times. It generates an SVG from an illustrator file (if you have it). You can target IDs in the SVG code corresponding to your country shapes to achieve mouse over hover effects. Each shape can link to an external resource, and you can use simple JS to include a simple hover tooltip.

Example of one I made: https://www.alexhordal.ca/portfolio/colours-of-sweden

1

u/BoysenberryGreen104 Oct 01 '26

an SVG map with each country as an `<a>` element, then use CSS `:hover` to turn the paths red

1

u/sheriffderek Oct 01 '26

I’d use SVG

1

u/SensitiveSugar1369 Oct 07 '26

use the `<map>` tag with `<area>` elements for each country, setting the `href` attribute to the desired page.

-1

u/notepad987 Oct 01 '26

I used Gemini to make a Image map generator.
Here is the link:
https://gemini.google.com/share/0f88782c8023?skid=10682f81-86fa-4f4f-98d1-0a09201e7a7d

With this you upload your image or practice with the one provided. Draw your rectangle or circle or polygon then drag your cursor over the image area and it will draw the area. On the right side you add your web address and choose to have it open in another tab or over existing page.
https://gemini.google.com/app:

You can Test then copy the code it creates.

Question I used: create a image map generator using html & css

It did not quite work so I asked this:
why does the web address not work? Destination URL ('href') says #https://www.google.com/ but nothing happens when I click on the image after clicking Test Map

It now works. See link above.

Gemini: I will now update the Image Map Generator application to fix the destination URL handling, sanitize inputs, ensure interactive previews correctly navigate to URLs (with window.open fallbacks), and provide quick URL preset helpers.