How to make your images in Markdown on GitHub adjust for dark mode and light mode


GitHub supports dark mode and light mode, and as developers, we can make our README images look great in both themes. Here’s a quick guide to using the <picture> element in your GitHub Markdown files to dynamically switch images based on the user’s color scheme.

When developers switch to GitHub’s dark mode (or vice versa), standard images can look out of place, with bright backgrounds or clashing colors.

Instead of forcing a one-size-fits-all image, you can tailor your visuals to blend seamlessly with the theme. It’s a small change, but it can make your project look much more polished.

One snippet, two themes!

Here’s the magic snippet you can copy into your README (or any Markdown file):

<picture>
  <source media="(prefers-color-scheme: dark)" srcset="dark-mode-image.png">
  <source media="(prefers-color-scheme: light)" srcset="light-mode-image.png">
  <img alt="Fallback image description" src="default-image.png">
</picture>

Now, we say it’s magic, but let’s take a peek behind the curtain to show how it works:

  • The <picture> tag lets you define multiple image sources for different scenarios.
  • The <source media="..."> attribute matches the user’s color scheme.
    • When media="(prefers-color-scheme: dark)", the browser loads the srcset image when GitHub is in dark mode.
    • Similarly, when media="(prefers-color-scheme: light)", the browser loads the srcset image when GitHub is in light mode.
  • If the browser doesn’t support the <picture> element, or the user’s system doesn’t match any defined media queries, the fallback <img> tag will be used.

You can use this approach in your repo README files, documentation hosted on GitHub, and any other Markdown files rendered on GitHub.com!

Demo

What’s better than a demo to help you get started? Here’s what this looks like in practice:

Written by

Blog Article: Here

  • Related Posts

    Cracking the code: How to wow the acceptance committee at your next tech event

    Want to speak at a tech conference? These four practical tips will help your session proposal stand out—and land you on the stage.

    The post Cracking the code: How to wow the acceptance committee at your next tech event appeared first on The GitHub Blog.

    Which AI model should I use with GitHub Copilot?

    Ever wondered which AI model is the best fit for your GitHub Copilot project? Here are some things to consider.

    The post Which AI model should I use with GitHub Copilot? appeared first on The GitHub Blog.

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    You Missed

    How we’re helping Google Play developers deliver better user experiences through improved performance insights.

    How we’re helping Google Play developers deliver better user experiences through improved performance insights.

    Cracking the code: How to wow the acceptance committee at your next tech event

    Cracking the code: How to wow the acceptance committee at your next tech event

    How to make your images in Markdown on GitHub adjust for dark mode and light mode

    How to make your images in Markdown on GitHub adjust for dark mode and light mode
    AWS Weekly Roundup: Amazon EKS, Amazon OpenSearch, Amazon API Gateway, and more (April 7, 2025)
    AWS Weekly Roundup: Amazon S3 Express One Zone price cuts, Pixtral Large on Amazon Bedrock, Amazon Nova Sonic, and more (April 14, 2025)

    4 Fitbit features I’m using to become a more efficient runner

    4 Fitbit features I’m using to become a more efficient runner