Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Support #gh-dark-mode-only and #gh-light-mode-only #36

Open
b0o opened this issue Oct 14, 2022 · 1 comment
Open

Support #gh-dark-mode-only and #gh-light-mode-only #36

b0o opened this issue Oct 14, 2022 · 1 comment

Comments

@b0o
Copy link

b0o commented Oct 14, 2022

See the GitHub docs and this article for an explanation of #gh-dark-mode-only and #gh-light-mode-only.

You can use this repo of mine, which uses this feature, to test this functionality if you'd like.

Here is what my repo looks like in gh-markdown-preview:

Click to expand

Screen Shot 2022-10-13 at 21 34 21

And here is what it looks like rendered on GitHub:

Click to expand

Screen Shot 2022-10-13 at 21 37 27

@yusukebe
Copy link
Owner

HI @b0o !

#gh-dark-mode-only and gh-light-mode-only seems to be deprecated.

The old method of specifying images based on the theme, by using a fragment appended to the URL (#gh-dark-mode-only or #gh-light-mode-only), is deprecated and will be removed in favor of the new method described above.

Link

So we can use the media queries:

<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/25423296/163456776-7f95b81a-f1ed-45f7-b7ab-8fa810d529fa.png">
  <source media="(prefers-color-scheme: light)" srcset="https://user-images.githubusercontent.com/25423296/163456779-a8556205-d0a5-45e2-ac17-42d089e3c3f8.png">
  <img alt="Shows an illustrated sun in light mode and a moon with stars in dark mode." src="https://user-images.githubusercontent.com/25423296/163456779-a8556205-d0a5-45e2-ac17-42d089e3c3f8.png">
</picture>

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants