How to show different images in GitHub light and dark mode
Updated 25 November 2026
Short answer
Wrap the image in a picture element with a source for prefers-color-scheme: dark and a normal img as the light fallback. GitHub follows the reader’s theme setting and shows the matching image.Copy-paste example
<picture>
<source media="(prefers-color-scheme: dark)" srcset="docs/logo-dark.png">
<source media="(prefers-color-scheme: light)" srcset="docs/logo-light.png">
<img alt="Project logo" src="docs/logo-light.png">
</picture>The img line is the fallback for places that ignore the picture element, such as some package registries, so point it at the version that works on white.
Tips
- Always set alt on the img, not on the source elements.
- Use transparent backgrounds where possible so one image may work in both themes.
- Test both themes: GitHub settings, Appearance, Theme.
PrettyGit does this automatically: with the theme option on, every card in a repository README is wrapped in a picture element with a light and dark twin.
FAQ
- Does #gh-dark-mode-only still work?
- The URL fragment trick still renders in many places, but the picture element is the documented way and works more reliably.