3

Is there a way to embed a font in the html / javascript code? (everything in 1 html file)

Quinn Keaveney
  • 1,248
  • 1
  • 17
  • 39
Sam
  • 65
  • 5

2 Answers2

1

I think Cufón may be your best bet. Its font converter turns OTF, TTF, PFB, and PostScript fonts into JavaScript. You can also limit the converted fonts to certain glyph subsets to reduce file size. Read more here:

https://github.com/sorccu/cufon/wiki/about

Usually you'd want to include the resultant JavaScript files externally (to aid cacheing and ease development and maintenance), but for your purposes, you can just include it all within <script> elements in the HTML document.

RamC
  • 1,287
  • 1
  • 11
  • 15
Bungle
  • 19,392
  • 24
  • 79
  • 106
0

You can add a font file as css code by converting it to base64 and embedding it as a Data URI.

I'll break down the steps below:

  1. Convert font to dataURI (https://base64.guru/converter/encode/file)

enter image description here

  1. Embed it in CSS via @font-face.
<style>
@font-face {
    font-family: 'Merriweather';
    src: url('data:@file/x-font-ttf;base64,AAEAAAARAQAABAAQR0RFRo9QjtMAAANAAAAB9Ed...')
         format('ttf');
    font-weight: 400;
}
</style>

You're all set!

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Quinn Keaveney
  • 1,248
  • 1
  • 17
  • 39