Skip to content

Switch SVG colors automatically in light/dark modes #7717

Answered by esynr3z
esynr3z asked this question in Q&A
Discussion options

You must be logged in to vote

So, I went with filter and it works like a charm! Thank you @kamilkrzyskow again!

Full recipe:

  1. Add additional CSS

  2. Put this code into created CSS:

img.invert-on-slate {
    filter: invert(0);
}

[data-md-color-scheme="slate"] img.invert-on-slate {
    filter: invert(1);
}
  1. In a Markdown document use img tag with class attribute to make it work
<img src="/assets/images/flow.drawio.svg" alt="Program Flow" class="invert-on-slate">

Note: I use draw.io for diagrams and save the diagram as "editable SVG", so I can edit nodes and connections in the software anytime and make it looks like a valid SVG elsewhere.

Replies: 4 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@esynr3z
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@schneekluth
Comment options

Answer selected by kamilkrzyskow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants