Skip to content

Is there a way to toggle png images according to the theme in use? #1742

Answered by mc7h
MankiratSingh1315 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @MankiratSingh1315 — I achieved it this way:

---
date: '2025-05-18T17:32:11+10:00'
draft: false
title: 'My First Post'
---

Hi there!


<style>
body.dark .light-img {
    display:none
}

body:not(.dark) .dark-img {
    display:none
}
</style>

<img src="/dark.png" alt="Logo" class="dark-img">
<img src="/light.png" alt="Logo" class="light-img">

However, I had to turn on unsafe in my config.

markup:
  goldmark:
    renderer:
      unsafe: true

Otherwise the raw tags are stripped out.

Demo:
https://github.com/user-attachments/assets/b1487553-e43b-4938-aa8d-4ada9602fb45

Replies: 1 comment 1 reply

Comment options

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

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