Skip to content

Instantly share code, notes, and snippets.

@szapp
Last active August 5, 2025 19:27
Show Gist options
  • Select an option

  • Save szapp/4b16d8a02363de0119214b5972328199 to your computer and use it in GitHub Desktop.

Select an option

Save szapp/4b16d8a02363de0119214b5972328199 to your computer and use it in GitHub Desktop.
Demo of dynamic SVG files that change appearance based on the presence of each other.
Display the source blob
Display the rendered blob
Raw
<!--
This is an example of how to implement conditional images based on SVG
This SVG will display a pointer if the file 'mask.svg' resides in the same directory.
Otherwise it will display a checkmark. The idea is to indicate a to-do list using static images.
-->
<svg xmlns="http://www.w3.org/2000/svg" width="27" height="24" xmlns:xlink="http://www.w3.org/1999/xlink">
<style>
text {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';
font-weight: 600;
font-size: 1.25em;
line-height: 1.25;
}
</style>
<defs>
<filter id="invert">
<feColorMatrix in="SourceGraphic" type="matrix" values="-1 0 0 0 1 0 -1 0 0 1 0 0 -1 0 1 0 0 0 1 0" />
</filter>
<g id="maskimg">
<rect width="100%" height="100%" fill="black" />
<image xlink:href="./mask.svg" />
</g>
<mask id="complete">
<use href="#maskimg" filter="url(#invert)" />
</mask >
<mask id="not-complete">
<use href="#maskimg" />
</mask >
</defs>
<text x="0" y="19" mask="url(#complete)">✅</text>
<text x="0" y="19" mask="url(#not-complete)">👉</text>
</svg>
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment