obsidian-qa-bot / docs /obsidian-developer /Themes /App themes /Embed fonts and images in your theme.md
anpigon's picture
Add favicon and image assets for Obsidian help and developer documentation
c63ff03

A newer version of the Gradio SDK is available: 5.0.1

Upgrade

Learn how to include assets, such as fonts and images, in your theme.

Loading remote content For Obsidian to work offline and to preserve user privacy, themes [[Developer policies|aren't allowed]] to load remote content over the network. For more information, refer to [[Theme guidelines#Keep resources local]]

Use data URLs

To include assets such as fonts, icons, and images in your theme, you need to embed them in the CSS file by passing a data URL to the url() function.

To create a data URL for your assets, create a URL using the following format:

url("data:<MIME_TYPE>;base64,<BASE64_DATA>")
  • Replace <MIME_TYPE> with the MIME type for your asset. If you don't know it, refer to Common MIME types.
  • Replace <BASE64_DATA> with the Base64 encoded representation of your asset.

The following example embeds a GIF file as a background image:

h1 {
  background-image: url("data:image/gif;base64,R0lGODdhAQADAPABAP////8AACwAAAAAAQADAAACAgxQADs=")
}

Encode your assets

For instructions on how to encode an asset into base64, refer to Encoding data into base64 format.

You can also use one of the many free online tools for encoding.

For fonts:

  • Woff2Base for WOFF2 font files
  • Aspose supports a wide variety of font formats

For images:

Consider file size

Embedding assets increases the file size of your theme, which may lead to poor performance in the following situations:

  • Downloading and updating your theme from the community theme directory.
  • Loading and using your theme in the Obsidian app.
  • Editing your theme in a code editor. Consider breaking up your theme into multiple files using a CSS preprocessor, such as Sass or Less.