Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
February 14, 2022 04:56 pm GMT

Using Dark/Light Mode Specific Images in GitHub Markdown

Hey There Devs!

Hope you are doing great with your projects.

TOC

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 darkLight Mode VariantLight Mode Variant

Dark 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)

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 !
Image description

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


Original Link: https://dev.to/arnavkr/using-darklight-mode-specific-images-in-github-markdown-3iln

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To