Search code examples
javascriptfontstruetype

Is it possible to load truetype fonts using javascript


I have a folder in my server with several fonts (myserver.com/fonts). and I have a JavaScript application where I would like to use those fonts on. but I have no idea how to load the fonts and use them. does anyone know how to load truetype fonts? I know I can do it with Cufon fonts but I'd rather use truetype.

PS. I'm new in JavaScript any examples would be greatly appreciated.


Solution

  • Use CSS font face.

    @font-face { font-family: Delicious; src: url('myserver.com/fonts/Delicious-Roman.ttf'); } 
    @font-face { font-family: Delicious; font-weight: bold; src: url('myserver.com/fonts/Delicious-Bold.otf'); }
    

    Then call it using font-family:

    h3 { font-family: Delicious, sans-serif; }
    

    You can use any licensed TrueType (.ttf) or OpenType (.otf) font.