typekit /webfontloader

Web Font Loader gives you added control when using linked fonts via @font-face.

★ 9,246⑂ 629👁 262⑃ 185● 271▤ 0
JavaScriptApache-2.0Created 2010-04-21
+1
日增长
9,246
stars
629
forks
262
watchers
185
prs
271
issues
0
releases

README

Web Font Loader

Web Font Loader gives you added control when using linked fonts via @font-face. It provides a common interface to loading fonts regardless of the source, then adds a standard set of events you may use to control the loading experience. The Web Font Loader is able to load fonts from Google Fonts, Typekit,  Fonts.com, and Fontdeck, as well as self-hosted web fonts. It is co-developed by Google and Typekit.



 Contents

 Get started
 Configuration
     Events
     Timeout
     Iframes
 Modules
     Adobe Edge Web Fonts
     Custom
     Fontdeck
     Fonts.com
     Google
     Typekit
 Browser support
 License

 Get Started

To use the Web Font Loader library, just include it in your page and tell it which fonts to load. For example, you could load fonts from Google Fonts using the Web Font Loader hosted on Google Hosted Libraries using the following code.

html


  WebFont.load({
    google: {
      families: ['Droid Sans', 'Droid Serif']
    }
  });



Alternatively, you can link to the latest 1.x version of the Web Font Loader by using https://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js as the script source. Note that the version in this url is less specific. It will always load the latest 1.x version, but it also has a shorter cache time to ensure that your page gets updates in a timely manner. For performance reasons, we recommend using an explicit version number (such as 1.6.26) in urls when using the Web Font Loader in production. You can manually update the Web Font Loader version number in the url when you want to adopt a new version.

Web Font Loader is also available on the jsDelivr & CDNJS CDNs.

It is also possible to use the Web Font Loader asynchronously. For example, to load Typekit fonts asynchronously, you could use the following code.

html

   WebFontConfig = {
      typekit: { id: 'xxxxxx' }
   };

   (function(d) {
      var wf = d.createElement('script'), s = d.scripts[0];
      wf.src = 'https://ajax.googleapis.com/ajax/libs/webfont/1.6.26/webfont.js';
      wf.async = true;
      s.parentNode.insertBefore(wf, s);
   })(document);



Using the Web Font Loader asynchronously avoids blocking your page while loading the JavaScript. Be aware that if the script is used asynchronously, the rest of the page might render before the Web Font Loader is loaded and executed, which can cause a Flash of Unstyled Text (FOUT).

The FOUT can be more easily avoided when loading the Web Font Loader synchronously, as it will automatically set the wf-loading class on the HTML element as soon as Webfont.load has been called. The browser will wait for the script to load before continuing to load the rest of the content, FOUT is avoided.

Web Font Loader is also available on npm as a CommonJS module. Just npm install webfontloader and then require it in your code.

js
  var WebFont = require('webfontloader');

  WebFont.load({
    google: {
      families: ['Droid Sans', 'Droid Serif']
    }
  });


 Configuration

The Web Fo

Top issues

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON