Skip to content

Instantly share code, notes, and snippets.

@jdsimcoe
Created October 16, 2015 23:03
Show Gist options
  • Save jdsimcoe/65810b2772990da44565 to your computer and use it in GitHub Desktop.
Save jdsimcoe/65810b2772990da44565 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');
}
@DonBattery
Copy link

You can add Favicon:

<link href="data:image/x-icon;base64,BASE64_STRING" rel="icon" type="image/x-icon" />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment