How to define dark/light mode images in GitHub Markdown (#note)

I was just browsing the GitHub markdown docs to check something and spotted a new GitHub feature. 🙈 GitHub markdown finally supports light and dark mode images! It always bugs me when GitHub Readmes look super polished but include a…


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis

I was just browsing the GitHub markdown docs to check something and spotted a new GitHub feature. 🙈 GitHub markdown finally supports light and dark mode images! It always bugs me when GitHub Readmes look super polished but include a terrible-looking "hero image" in the dark GitHub UI (or the other way around).

Use a URI fragment in the image URL to hide or show it depending on user preferences!

![Fancy logo](./dark.png#gh-dark-mode-only)
![Fancy logo](./light.png#gh-light-mode-only)

Here is it in action. 👇

I couldn't find official release notes about it, but the feature seems to be only a few days old. The new CEO shared it on Twitter, too.

The problem with non-standard solutions

While this approach seems smart, it comes with drawbacks. Appending #gh-dark-mode-only to an image URL works perfectly fine on github.com. That's not the only location many Readmes are rendered on, though. npm renders repo Readmes, blogs render repo Readmes, for any site but GitHub two images will be rendered using this new approach.

Thinking of npm, I'm sure they will adopt this syntax quickly (it's all Microsoft, right?), but it's probably too early to adopt this feature right now. And if you do, you better be sure that the Readme isn't rendered anywhere else because I don't see Markdown renderers implementing this soon...


Reply to Stefan


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis


Print Share Comment Cite Upload Translate Updates
APA

Stefan Judis | Sciencx (2021-11-29T23:00:00+00:00) How to define dark/light mode images in GitHub Markdown (#note). Retrieved from https://www.scien.cx/2021/11/29/how-to-define-dark-light-mode-images-in-github-markdown-note/

MLA
" » How to define dark/light mode images in GitHub Markdown (#note)." Stefan Judis | Sciencx - Monday November 29, 2021, https://www.scien.cx/2021/11/29/how-to-define-dark-light-mode-images-in-github-markdown-note/
HARVARD
Stefan Judis | Sciencx Monday November 29, 2021 » How to define dark/light mode images in GitHub Markdown (#note)., viewed ,<https://www.scien.cx/2021/11/29/how-to-define-dark-light-mode-images-in-github-markdown-note/>
VANCOUVER
Stefan Judis | Sciencx - » How to define dark/light mode images in GitHub Markdown (#note). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/11/29/how-to-define-dark-light-mode-images-in-github-markdown-note/
CHICAGO
" » How to define dark/light mode images in GitHub Markdown (#note)." Stefan Judis | Sciencx - Accessed . https://www.scien.cx/2021/11/29/how-to-define-dark-light-mode-images-in-github-markdown-note/
IEEE
" » How to define dark/light mode images in GitHub Markdown (#note)." Stefan Judis | Sciencx [Online]. Available: https://www.scien.cx/2021/11/29/how-to-define-dark-light-mode-images-in-github-markdown-note/. [Accessed: ]
rf:citation
» How to define dark/light mode images in GitHub Markdown (#note) | Stefan Judis | Sciencx | https://www.scien.cx/2021/11/29/how-to-define-dark-light-mode-images-in-github-markdown-note/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.