<a>
SVG anchor
Wrap clickable shapes inside the SVG <a> element.

SVG’s <a> element turns shapes into real hyperlinks. This tutorial covers modern href (and legacy xlink:href), safe new-tab linking with target and rel, hover styling, accessibility, five worked examples, and how SVG links compare to HTML anchors and click handlers.
SVG anchor
Wrap clickable shapes inside the SVG <a> element.
Modern attribute
Prefer href for new SVG — destination URL or path.
Safe new tabs
Use _blank with noopener noreferrer for external links.
Feedback
Change fill, stroke, or transform on a:hover.
Labels & hit area
Visible text or aria-label, plus a generous tap target.
Legacy
Still appears in older SVG — prefer href for new work.
SVG links let users click an icon, badge, map region, or diagram node and navigate like any other hyperlink. You wrap the graphics in an SVG <a> and set a destination with href.
Unlike wiring onclick handlers, real anchors work with middle-click, open-in-new-tab, and browser history — the same mental model as HTML links.
Clickable SVG keeps icons and diagrams sharp and navigable without exporting separate image maps or bolting on fragile JavaScript for basic navigation.
Native navigation with href — not only click scripts.
target="_blank" plus rel="noopener noreferrer".
CSS on the anchor communicates that shapes are clickable.
Text inside the link or aria-label for screen readers.
In short: wrap shapes in SVG <a href="...">, style on hover, and label the destination clearly.
Basic form of an SVG link:
<svg width="200" height="80">
<a href="/svg">
<rect x="20" y="20" width="160" height="40" rx="10" fill="#2563eb" />
</a>
</svg> | Attribute | Type | Description |
|---|---|---|
href | URL | Modern destination for the link (preferred). |
xlink:href | URL | Legacy destination attribute — avoid for new code. |
target | Keyword | Where to open: _self, _blank, etc. |
rel | Tokens | Use noopener noreferrer with _blank. |
aria-label | Text | Accessible name when visible text is missing. |
<!-- 1. Wrap shapes -->
<a href="https://example.com" target="_blank" rel="noopener noreferrer">
<rect ... />
<text ...>Label</text>
</a>
<!-- 2. Style feedback -->
<style>
a:hover rect { opacity: 0.9; }
</style> | Idea | Detail | Notes |
|---|---|---|
| Painted area | Needs fill or stroke | fill="none" alone is hard to hit |
| Text labels | pointer-events: none | Clicks pass through to the link |
| Overlays | Later elements win | Don’t cover the link region |
| Goal | Code |
|---|---|
| Basic link | <a href="/svg"><rect ... /></a> |
| External new tab | target="_blank" rel="noopener noreferrer" |
| Hover fill | a:hover rect { fill: #0ea5e9; } |
| Accessible name | <a href="..." aria-label="SVG home"> |
| Pass clicks through text | style="pointer-events:none" on <text> |
| Legacy attribute | xlink:href (prefer href) |
<a> vs HTML <a> vs onclickAll can respond to clicks — pick the right tool for navigation vs behaviour.
inside <svg>Hyperlink shapes, icons, and map regions
wrap the SVGWhole graphic as one link from outside
legacy <map>Older raster approach — prefer SVG links
Reach for SVG <a> when a graphic region should navigate like a normal link.
Logo marks and toolbar icons that open pages or docs.
Flowchart boxes that deep-link to detail pages.
Regions or pins that navigate to location pages.
Illustrated call-to-action shapes inside marketing graphics.
For show/hide and state without navigation, use interactivity patterns instead.
Key benefit: vector-sharp graphics that behave like real links — middle-click, new tab, and shareable URLs included.
Five starter snippets using SVG <a>. Click View Output for a preview, or Try It Yourself to edit live.
Wrap a shape, then link inside your site.
Make a rectangle clickable. 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> The SVG <a> wraps the rect and label. pointer-events: none on text ensures clicks hit the link, not the text alone.
Link to another page on the same site with a relative href.
<svg width="200" height="80" viewBox="0 0 200 80">
<a href="/svg">
<rect x="20" y="18" width="160" height="44" rx="12" fill="#2563eb" />
<text x="100" y="46" text-anchor="middle" font-size="14" fill="white"
font-family="system-ui,Segoe UI,Arial" style="pointer-events:none">
Go to SVG
</text>
</a>
</svg> Relative paths work the same as in HTML. Default target is the current tab (_self).
Hover feedback, accessible names, and larger tap targets.
Communicate clickability by changing fill and lifting the shape on hover.
<svg width="220" height="100" viewBox="0 0 220 100">
<style>
.chip rect{cursor:pointer;transition:fill 160ms ease,transform 160ms ease}
.chip:hover rect{fill:#0ea5e9;transform:translateY(-2px)}
</style>
<a class="chip" href="/svg/interactivity">
<rect x="30" y="28" width="160" height="44" rx="22" fill="#6366f1" />
<text x="110" y="56" text-anchor="middle" font-size="13" fill="white"
font-family="system-ui,Segoe UI,Arial" style="pointer-events:none">
Hover me
</text>
</a>
</svg> Style the child shape with a:hover rect (or a class). Touch devices may not hover — keep the default look clearly button-like too.
When the graphic is icon-only, give the link an accessible name with aria-label.
<svg width="120" height="120" viewBox="0 0 120 120">
<a href="/svg" aria-label="SVG introduction">
<circle cx="60" cy="60" r="42" fill="#3b82f6" />
<path d="M48 60h24M60 48v24" stroke="white" stroke-width="6"
stroke-linecap="round" style="pointer-events:none" />
</a>
</svg> Screen readers announce the aria-label. Prefer visible text when you can; use aria-label for compact icons.
Wrap a small icon with an invisible (or nearly invisible) rect so the tap target stays generous on mobile.
<svg width="160" height="80" viewBox="0 0 160 80">
<a href="/svg/links" aria-label="SVG links tutorial">
<!-- Large invisible hit area -->
<rect x="10" y="10" width="140" height="60" rx="12"
fill="#000" fill-opacity="0" />
<!-- Visible icon -->
<path d="M58 40h16M70 28v16" stroke="#0f172a" stroke-width="4"
stroke-linecap="round" style="pointer-events:none" />
<circle cx="70" cy="40" r="18" fill="none" stroke="#0f172a"
stroke-width="3" style="pointer-events:none" />
</a>
</svg> A rect with fill-opacity="0" still receives pointer events. Put decorative strokes under pointer-events: none so the big rect remains the hit target.
Real-world places where SVG links show up every day.
Brand marks that return home or open the product site.
Example: header logo SVG wrapping href="/".
Clickable slices that deep-link to related articles.
Example: pie segment linking to a category page.
Illustrated tiles that open reports or settings.
Example: metric badge linking to a detail view.
Diagram steps that jump to matching chapters.
Example: architecture box linking to an API page.
External profile icons opening in a new tab safely.
Example: GitHub mark with rel="noopener".
Tutorial graphics that jump to the next lesson.
Example: “Next topic” shape in an SVG diagram.
Pro Tip: for one link around the whole graphic, wrapping the <svg> in an HTML <a> is often simpler than nesting SVG anchors.
Why use SVG anchors instead of only JavaScript click handlers.
Works with middle-click, open-in-new-tab, and browser history.
Vector icons remain crisp while staying fully clickable.
Several anchors can live in one SVG for maps and diagrams.
Basic navigation works even if custom JS fails to load.
href, target, and rel match what you already know from HTML.
Pro Tip: keep navigation in <a href> and reserve JS for behaviour that is not a page change.
Follow these practices for reliable, accessible SVG links.
Use modern href for new SVG; treat xlink:href as legacy.
Always pair target="_blank" with rel="noopener noreferrer".
Change fill, stroke, or slight lift so users know it is clickable.
Aim for comfortable tap targets — expand with an invisible rect if needed.
Visible text or aria-label so assistive tech can announce the link.
Pro Tip: set pointer-events: none on decorative text and strokes so the painted hit target stays predictable.
Avoid these mistakes when your SVG link refuses to click.
fill="none" with no stroke is nearly impossible to click.
→ Add a fill, stroke, or transparent rect for the hit target.
A later shape can sit on top and steal clicks.
→ Check stacking order and pointer-events.
Opening external pages without rel can expose window.opener.
→ Always add rel="noopener noreferrer".
Small icons frustrate mobile users.
→ Expand the hit area with a larger transparent shape.
Icon-only links without text or aria-label confuse assistive tech.
→ Add a label that describes the destination.
Pro Tip: if clicks fail, inspect for overlays, pointer-events: none on the wrong element, and whether the link wraps a painted shape.
Place the clickable graphics inside <a> within the same <svg>.
Use modern href for internal or external URLs. Prefer it over legacy xlink:href.
For new tabs, set target="_blank" and rel="noopener noreferrer".
Hover CSS shows it is interactive; text or aria-label names the destination.
Users navigate with a sharp SVG that behaves like a normal hyperlink.
href on SVG <a>; xlink:href is legacy.target="_blank" with rel="noopener noreferrer".aria-label.<a> wrapping the <svg>.Quick Takeaway: wrap painted shapes in SVG <a href>, secure external tabs, and label the control clearly.
SVG linking with <a href> is supported in all modern browsers. Legacy xlink:href still works in many engines but is not needed for new projects.
Use href on SVG anchors in inline SVG. Chrome, Firefox, Safari, Edge, and mobile browsers all support clickable SVG links for navigation.
Bottom line: Safe for production. Prefer href; keep xlink:href only when maintaining older SVG assets.
SVG links are straightforward: wrap shapes in <a href="...">, style for feedback, and label the destination. Prefer modern href, and secure external tabs with rel="noopener noreferrer".
Practice the five examples above, then revisit SVG Introduction or explore more topics from the sidebar.
Keep hit areas large, avoid overlays, and use interactivity patterns when you need behaviour without navigation.
href for new SVG codetarget="_blank" with rel="noopener noreferrer" for external linkspointer-events: none on text labels so clicks hit the link targetaria-label)rel safetyTurn vector shapes into real hyperlinks.
Wrap clickable shapes
APIModern destination
URLSafe blank tabs
SecurityCSS feedback
UXText or aria-label
a11ySVG has its own <a> element inside the SVG namespace — wrap shapes with it and set href to turn graphics into real hyperlinks. You can put several <a> elements in one SVG so different regions navigate to different URLs — perfect for simple interactive maps.
You finished the Advanced track — revisit the SVG overview or pick another topic from the sidebar.
8 people found this page helpful