Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correct way to add links in an SVG image [closed]

Tags:

html

css

svg

If I have an SVG image and I want to make it interactive by adding some links, is right to do it this way?

<a href="https://www.link-1.com">
 <g>
 </g>
</a>

<a href="https://www.link-2.com">
 <g>
 </g>
</a>

So wrapping the <g> tag with an <a> tag? Or there is another best practice?

like image 515
Pahed Avatar asked Dec 18 '25 16:12

Pahed


1 Answers

Your example is the correct way to add links to SVG.

SVG's <a> element is a container, which means you can create a link around text (like in HTML) but also around any shape.

Example:

<a href="/docs/Web/SVG/Element/circle">
    <circle cx="50" cy="40" r="35" />
</a>

Source: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/a

like image 128
Dimitris Maragkos Avatar answered Dec 21 '25 10:12

Dimitris Maragkos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!