Skip to content

Instantly share code, notes, and snippets.

@viktor-yakubiv
Created March 28, 2022 16:16
Show Gist options
  • Save viktor-yakubiv/0ac7f051303140a629c03365eb7a3000 to your computer and use it in GitHub Desktop.
Save viktor-yakubiv/0ac7f051303140a629c03365eb7a3000 to your computer and use it in GitHub Desktop.
SVG sprite boilerplate
Display the source blob
Display the rendered blob
Raw
<svg xmlns="http://www.w3.org/2000/svg">
<symbol id="name" viewBox="0 0 24 24">
<!-- icon code goes here -->
</symbol>
<!-- The script makes the targeted icon visible when the file opened in the browser tab -->
<script>
const useElement = document.createElementNS(document.rootElement.namespaceURI, 'use')
const render = () => useElement.setAttribute('href', location.hash)
document.rootElement.append(useElement)
window.addEventListener('hashchange', render)
render()
</script>
</svg>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment