Make an html svg object also a clickable link
Wrap your SVG with an anchor <a>
tag to create a clickable link. Here's how to do that:
Guess what happens, clicking on the SVG redirects you to https://www.example.com. Yes, you've guessed right!
Communication with SVG: pointers and events
Firstly, rid your SVG elements of any interfering clicks; set pointer-events: none;
. This makes it possible for the object to function as a clickable link.
Anchor man(datorily) encapsulates SVG
Wrapping SVG like a baby in a blanket can be done by employing an anchor tag. Remember, the anchor's home attire constitutes display: block;
for smooth clickability. For instance:
What you've done here is reserved the SVG's entire area as clickable territory. High five!
Past-tense compatibility: IE woes
If you're on a trip to the past with IE8<, you might encounter some mischievous behavior from SVG. But we got you; use conditioning tea (or comments) for web harmony. Layer your anchor ABOVE the SVG like so:
The Unseen Ad blockers
Watch out for the invisible Ad Blockers, they might play tricks with your hover states. To be on the safe side, test your SVG links with these spunky ad-blocking extensions. You'll be ahead of the game!
Compatibility: A stitch in time...
Though it’s like finding a unicorn, some browsers don’t support SVG. In such mythical circumstances, provide them a fallback image for those adventurous users:
Portal parameters and high-sea SEO
Anchoring URL parameters
When SVGs double as clickable links, consider including query parameters. Observe:
Remember, your server better be ready to handle these precise parameters!
Accessibility: All aboard!
Roll out the red carpet for all types of users. Use aria-label
or title
attributes for a descriptive text for your SVGs. Making sure your SVG is prepared to host ALL browsers.
Was this article helpful?