SVG Links

What You’ll Learn
You can make SVG graphics clickable by wrapping shapes inside an SVG <a> element. This lets users click an icon, badge, map region, or diagram node to navigate to another page.
This guide shows modern SVG linking with href (and the legacy xlink:href), how to open links in a new tab safely with target + rel, and how to add hover styling and accessibility.
⚡ Quick Reference — SVG Links
<a>Wrap the clickable shapes
hrefPreferred for new SVG
xlink:hrefOlder content (avoid if possible)
target + rel_blank + noopener
a:hoverChange fill/stroke on hover
<svg>
<a href="/path">
<rect x="10" y="10" width="100" height="50" />
</a>
</svg>👀 Live Preview — Clickable SVG
Hover and click the preview to see how an SVG link behaves. (The preview links to internal routes.)
Wrap a Shape with <a href="...">
This example uses href (recommended) to make a rectangle clickable. It opens in a new tab with a safe rel value.
<svg width="240" height="160" viewBox="0 0 240 160">
<style>
.btn rect{cursor:pointer;transition:transform 140ms ease,opacity 140ms ease}
.btn:hover rect{transform:translateY(-2px);opacity:0.95}
</style>
<a class="btn" href="https://example.com" target="_blank" rel="noopener noreferrer">
<rect x="40" y="48" width="160" height="64" rx="16" fill="#22c55e" />
<text x="120" y="86" text-anchor="middle" font-size="14" fill="white" font-family="system-ui,Segoe UI,Arial" style="pointer-events:none">
Open Example.com
</text>
</a>
</svg>Legacy xlink:href (When You See It)
Older SVG code uses xlink:href. Modern SVG uses href, but you may still encounter xlink in existing projects.
<svg width="240" height="120" viewBox="0 0 240 120">
<a xlink:href="/svg" target="_self">
<circle cx="120" cy="60" r="40" fill="#3b82f6" />
</a>
</svg>💡 Best Practices
Do
- Prefer
hreffor new SVG code - Use
target="_blank"withrel="noopener noreferrer"for external links - Add hover styles to communicate clickability (fill, stroke, underline)
- Use
pointer-events: noneon text labels so clicks hit the link target - Provide clear labels (text inside the SVG or
aria-label)
Don’t
- Open external links in a new tab without
relsafety - Rely on xlink for new projects unless you must support very old code
- Make tiny clickable targets that are hard to tap on mobile
- Let other elements overlap the link region (it blocks clicks)
- Assume hover works on touch devices—use clear button styling too
❓ Frequently Asked Questions
<a> element and set href to the destination (or xlink:href for legacy content).href for modern SVG. You may see xlink:href in older codebases.target="_blank" and add rel="noopener noreferrer" for external links.pointer-events settings, and ensure the link wraps a visible painted area (fill or stroke).a:hover rect or a class on the anchor to animate fill, stroke, opacity, or transforms.Build Custom Clickable Regions
Next, learn SVG paths to create complex shapes for icons, diagrams, and interactive maps.
4 people found this page helpful
