Chapter 14: SVG Links

SVG Links means adding clickable hyperlinks inside your SVG graphics. You can make:

  • A circle, rectangle, path, icon, or text clickable
  • When user clicks → goes to another page, downloads file, opens email, jumps to section, etc.

This is done using the <a> element inside SVG — yes, SVG has its own <a> tag, very similar to HTML’s <a>, but it works perfectly around shapes, paths, groups, text, etc.

Important: SVG <a> is a container (like a wrapper). You put your shape/text inside it, and the whole thing becomes clickable.

1. Why Use SVG Links? (Real Reasons)

  • Make icons/buttons in navbar clickable (e.g., home icon → home page)
  • Interactive charts (click bar → details)
  • Logos that link to homepage
  • Downloadable SVG diagrams
  • Map regions clickable
  • Hover + click effects on vector graphics

2. Basic Syntax of SVG <a>

XML
  • <a> must be inside<svg>…</svg>
  • href works like HTML (full URL, relative path, #anchor, mailto:, tel:, etc.)
  • In modern browsers (2026): Just use href — no need for old xlink:href
  • Old code sometimes uses xlink:href (for SVG 1.1 compatibility) — but now href is standard and preferred

3. Your First SVG Link Example (Copy-Paste Right Now!)

Make svg-link.html:

HTML

What happens:

  • Whole circle + text inside <a> becomes one big clickable area
  • Click anywhere on green circle or “Click Me!” text → new tab to Google
  • target=”_blank” → opens in new tab (like HTML)
  • title → tooltip on hover

Zoom browser — link still works perfectly, text sharp!

4. More Real Examples (Try These!)

Example 1: Link Around a Path/Icon (Common for Buttons)

XML

→ Clickable heart icon (use <use> for reuse)

Example 2: Download Link (SVG as Downloadable File)

XML

→ Click rectangle → browser downloads “my-diagram.svg”

Example 3: Internal Link (Anchor in Same Page)

XML

Example 4: Hover + CSS Style (Make Link Feel Nice)

HTML

→ Hover changes colors (shows it’s interactive)

5. Important Attributes Table (Like Class Notes)

Attribute Meaning Example Notes
href Destination URL “https://google.com”, “#top”, “file.pdf” Main one — use this!
target Where to open “_blank”, “_self” _blank = new tab
download Download instead of open “report.svg” Prompts save dialog
title Tooltip on hover “Visit site” Accessibility + UX
rel Relationship (like HTML) “noopener noreferrer” Security for _blank
hreflang Language of target “en” Rare

6. Teacher’s Tips (Hyderabad Student Style 😄)

  • Always put shapes inside <a> — don’t put <a> around whole SVG unless you want entire graphic clickable
  • For icons from Font Awesome/Material → wrap <path> or <g> in <a>
  • Accessibility: Add aria-label or title so screen readers know what link does
  • Common mistake: Use xlink:href only if old browser support needed — modern code just href
  • In React/Vue: Inline SVG links work same, but watch namespace if using JSX
  • Job/freelance: Clients love clickable SVG maps, interactive infographics, animated buttons

Understood SVG Links now? It’s what makes static vectors interactive! Want next: Full interactive icon set example? Animate link on hover? Or <use> + links? Or textPath inside link? Just tell me — we’re turning you into SVG expert! 🚀

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *