Skip to content

Instantly share code, notes, and snippets.

@angeloevangelista
Forked from jdsimcoe/base64.md
Created December 19, 2022 19:31
Show Gist options
  • Save angeloevangelista/464be99ee62033abe2f99f6480e7da5a to your computer and use it in GitHub Desktop.
Save angeloevangelista/464be99ee62033abe2f99f6480e7da5a to your computer and use it in GitHub Desktop.
A guide to how to embed Base64 stuff in your web stuff.

HTML

Here is some code on how to embed Base64 in HTML:

JPEG

<img src="data:image/jpeg;base64,BASE64_STRING"/>

PNG

<img src="data:image/png;base64,BASE64_STRING"/>

GIF

<img src="data:image/gif;base64,BASE64_STRING"/>

JavaScript

<script type="text/javascript" src="data:text/javascript;base64,BASE64_STRING"></script>

CSS

You can also Base64 encode stuff straight in your CSS:

Images

.yourclass {
  background: url('data:image/jpeg;base64,BASE64_STRING');
}

OpenType Fonts

@font-face {
  font-family:'FONT_NAME';
  src: url(data:font/opentype;charset=utf-8;base64,BASE64_STRING);
}

WOFF Fonts

@font-face {
  font-family:'FONT_NAME';
  src: url(data:application/font-woff;charset=utf-8;base64,BASE64_STRING) format(‘woff’);
}

TrueType Fonts

@font-face {
  font-family:'FONT_NAME';
  src: url(data:application/font-ttf;charset=utf-8;base64,BASE64_STRING) format('truetype');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment