2

Using Dark/Light Mode Specific Images in GitHub Markdown

 2 years ago
source link: https://dev.to/arnavkr/using-darklight-mode-specific-images-in-github-markdown-3iln
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Hey There Devs! πŸ‘‹

Hope you are doing great with your projects.

Why this post? πŸ€”

As a developer we develop projects, write code all day around and we might also publish it on GitHub to let others understand and use our project.

And Markdowns play a vital role in explaining the code, branding your tool, showcasing your stats and so on.

And you all know how much is the craze of the Dark Mode nowadays especially between the Devs. But most browsers have light mode as their default.

So, here comes the actual point of this post. By default GitHub adapts most of the parts of the README according to the theme. But it doesn't do anything with your images by default.

Imagine an image that was made to look good on white background with black as its foreground color. it will not even be notable in the dark mode.

So, you may want to optimize your Images according to the current theme of the viewer's browser. And also maybe to look a bit cool and professional πŸ˜….

Procedure πŸ§ͺ

The procedure is very simple. No I am not joking its actually very simple.

  1. Do Create to separate versions of your images one optimized for light mode and one for dark mode. For example take this image of Termux. I have created two of the variants of the same image one for light and one for dark Light Mode VariantLight Mode Variant



Dark Mode Variant

  1. Now, here comes the magical thing πŸͺ„. To make an Image only visible in Dark Mode, add #gh-dark-mode-only at the end of the image url. And to make an Image Only Visible in Light Mode, add #gh-light-mode-only.

Example:

![Termux Logo](https://user-images.githubusercontent.com/72879799/153904003-d7dee710-6552-4d23-a803-7a9a0ba67d92.png#gh-dark-mode-only)
![Termux Logo](https://user-images.githubusercontent.com/72879799/153904095-9d78a019-8495-4035-8174-e3da8e4dd66b.png#gh-light-mode-only)

Enter fullscreen mode

Exit fullscreen mode

Now the Dark Mode variant of the Image will only be visible in the Dark mode and the Light Mode variant will only be visible in the Light Mode.

The Image URLs above are just for demonstration. Replace them with your own image URLs and you are Ready to Go!

And it works πŸ₯³πŸŽ‰!

Live Example ⚑:

You can see the working example at my GitHub.

Disclaimers ⚠️

Note that it will not adapt according to the Theme if the image is not hosted on the GitHub


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK