Skip to content

Instantly share code, notes, and snippets.

@timerring
Created November 19, 2024 12:43
Show Gist options
  • Select an option

  • Save timerring/34f721d587fa5f47c2ca7b893fd325cf to your computer and use it in GitHub Desktop.

Select an option

Save timerring/34f721d587fa5f47c2ca7b893fd325cf to your computer and use it in GitHub Desktop.

The github does not support custom fonts in README.md. Thus to use custom fonts, we need to use other methods.

The Github README files are essentially markdown files thus it supports embedding SVG images. One of the SVG pros is that you can make updates to the SVG images and they will be rendered in the README.md files.

So let us talk about how to embed SVG. From the docs we know that github usually strips out any external resources when rendering the README.md files, which accounts for the reason why the @import does not work.

Thus we need to embedding font data using Base64 encoding. So we need to convert the TTF file to Base64 encoding. You can try this website

Then it will generate the SVG code in the css and html, you can merge them into the SVG file. Take my project as an example. And introduce the SVG file into the README.md file. You can change the SVG path to follow the system.

  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="assets/headerDark.svg" />
    <img src="assets/headerLight.svg" alt="Your Title" />
  </picture>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment