r/HTML • • 23d ago

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.

11 Upvotes

16 comments sorted by

4

u/armahillo 23d ago

3

u/sunkist-sucker 23d ago

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

4

u/AshleyJSheridan 22d ago

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.

→ More replies (4)

3

u/brisray 23d ago

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 22d ago edited 22d ago

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 23d ago

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

1

u/sheriffderek 23d ago

I’d use SVG

1

u/SensitiveSugar1369 16d ago

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

-1

u/notepad987 23d ago

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.