Menu

1 / 3

Why Does Your SVG Map Pin Move When You Resize It?

DEV Community: frontend·Axialis Software·9 days ago
#jjXmwkxk
#devtofrontend#devto#dev#center#viewbox
Long article (479 words) — no AI summary yet.
Reading 0:00
15s threshold

A map pin points to the right building at 16 px. You increase it to 24 px and the tip moves down. The map coordinate stayed put. What moved was the tip's position relative to the point used to place the SVG.

Here's a small experiment you can reproduce without a map library.

Put the center on the cross

Start with a square viewBox="0 0 24 24" and a pin whose tip is at (12, 22) . Place the center of the SVG viewport on a fixed cross. The center corresponds to (12, 12) in the SVG, so the tip sits 10 SVG units below it.

At 16 CSS px, that gap becomes 6.67 px . At 24 CSS px, it becomes 10 px . Increasing the icon size moves the tip 3.33 px farther down , even though the cross stays in exactly the same place.

The screenshots magnify the shapes for readability. The labels report offsets in CSS pixels at the original marker sizes.

Try bottom center with two silhouettes

Bottom center puts (12, 24) on the cross. That helps with the first pin, but its tip is still two SVG units above the bottom of the box.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.