Spicing up the web with Google Web Fonts

| July 27, 2012

For some time now, typog­ra­phy on the web has been like a fast food bur­rito: The selec­tions have been lim­ited to only a few bland ingre­di­ents that may only be mixed in a few com­bi­na­tions. It is our job as either web design­ers or bur­rito artists to com­bine these ingre­di­ents together in a com­pelling and more visu­ally appeal­ing manner.

In com­par­i­son, print design­ers have had it rel­a­tively easy. For them, the scope of prob­lems involved in using a font are lim­ited to:

  1. Hav­ing own­er­ship or a license to use the font
  2. Writ­ing words using the font and putting them onto a piece of paper

Once the type has been struck, it is essen­tially there for­ever. The print designer doesn’t have to worry about whether the piece of paper has the font installed or if the reader of the piece of paper has a weird alter­nate font installed in its place that would alter the intended dis­play of the type­set­ting. The web does have these problems.

The menu thus far has con­sisted pri­mar­ily of what are known as “web-safe fonts:” Arial, Hel­vetica, Times New Roman, or Courier New. Some­times a devel­oper would get crazy and throw in a dash of Ver­dana or Impact or Comic Sans MS if he thought that a large enough per­cent­age of the pro­jected user base would have these already installed on their computers.

Using the Google Web Fonts API is a great way to add some spirit and leg­i­bil­ity to the text of your web­site. Cur­rently, there are over 500 dif­fer­ent font fam­i­lies avail­able, which is about 100 times as many fonts many of us have been accus­tomed to using regularly.

Today, any­body who can write an HTML <link> tag and a CSS font-family rule can take advan­tage of the many fonts avail­able through the Google Web Fonts API. The usage is quite simple:

  1. Include a <link> at the top of your web page that retrieves the font file that you would like to use
  2. Add a font-family rule to your stylesheet that ref­er­ences the font in your <link>
  3. Use your new font with wild abandon.

Here is a com­plete, bare­bones, and inline exam­ple:

<!DOCTYPE html>
<html>
<head>
<!-- A font reminiscent of an old 8-bit video game  -->
<link rel='stylesheet' type='text/css' href='http://fonts.googleapis.com/css?family=Press+Start+2P'>
<!-- A font that clearly brings the thought of monkeys who are in a good mood to the forefront of your mind -->
<link rel='stylesheet' type='text/css'
href='http://fonts.googleapis.com/css?family=Happy+Monkey'>
<style type='text/css'>
body {
background-color: black;
}
h1 {
font-family: 'Press Start 2P', ‘Times New Roman’, serif;
color: yellow;
text-shadow: 2px 2px 0 #AAA;
}
p {
font-family: 'Happy Monkey', Arial, sans-serif;
font-size: 1.5em;
color: white;
}
</style>
</head>
<body>
<h1>My Funky Page Header</h1>
<p>Whoa! This paragraph is considerably funkier than
the header that preceded it.</p>
</body>
</html>

And here is a screen­shot of this page run­ning in a few browsers installed on my com­puter, as well as in a cou­ple of pop­u­lar mobile browsers. In a clock­wise fash­ion start­ing from the top left cor­ner, these are Fire­fox, Safari, Chrome, Inter­net Explorer 7, Mobile Safari, Android ICS Browser, and Opera:

 

 

The Google Web Fonts API works by serv­ing fonts in mul­ti­ple file types such that each par­tic­u­lar browser can down­load and ren­der the font in the par­tic­u­lar fla­vor that it prefers. These for­mats are:

  • TTF — True­Type Font. Most Win­dows and Mac users are famil­iar with these fonts. These are the same as many fonts that shipped with your com­puter. Safari uses this format.
  • EOT — Embed­ded Open­Type. This is a font file for­mat that is par­tic­u­lar only to Inter­net Explorer.
  • WOFF — Web Open Font For­mat. An emerg­ing stan­dard for font file dis­tri­b­u­tion that has been embraced by the W3C, and is cur­rently in Can­di­date Rec­om­men­da­tion sta­tus. This for­mat is used by Chrome, Fire­fox, and Opera.
  • SVG — Scal­able Vec­tor Graph­ics. Sup­ported on iPhone/iPad, but not as widely imple­mented or well sup­ported as the above formats.


A request to the Google Web Fonts API is inspected to deter­mine which font file for­mat should be deliv­ered to the web browser mak­ing the request, and only that font file for­mat will be returned. Browser-specific, tar­geted rules save con­sid­er­able band­width and are there­fore faster to respond, because the browser does not have to wait for or even con­sider font file def­i­n­i­tions that it can­not sup­port or under­stand any­way. Here is a rep­re­sen­ta­tion of how dif­fer­ent browsers are served dif­fer­ent font fam­i­lies, depend­ing on who they are:

 

Given the sur­gi­cal atten­tion to detail of browser imple­men­ta­tions and pecu­liar­i­ties and with over 500 font fam­i­lies avail­able, the Google Web Fonts API clearly gives a web site designer many fonts to pick from and the peace of mind of reli­able browser cov­er­age. Google is huge and their net­work spans the globe, which ensures redun­dancy and speed. The font you picked will be view­able. This is the good part. You don’t always have to fall back to Comic Sans MS when you want to look cool.

The draw­backs are mostly prac­ti­cal in nature. If a user doesn’t have a font you spec­ify already installed, then the font must be down­loaded. This doesn’t usu­ally take very long but it is depen­dent on the speed of the user’s net­work con­nec­tion. While the font is down­load­ing, the user may see a flash of unstyled con­tent using another font that the user does have installed already, or using a default font face for the browser. But after the font that you have spec­i­fied is down­loaded and installed, the con­tent will appear cor­rectly, and the font will be cached on the user’s machine so that it will not have to be down­loaded again.

Another point to make is that you don’t have to use this ser­vice if you want to use a font. If you have a font that you would like to use, and you either own it, license it, or oth­er­wise have per­mis­sion to use it on the web, you can make use of your font in a very sim­i­lar man­ner to the Google Web Fonts API. Here’s how:

  1. Get or cre­ate the dif­fer­ent for­mats of your font listed above. These are TTF, WOFF, EOT, and maybe SVG for com­plete­ness sake.
  2. Host these font for­mats on your own website.
  3. Add a @font-face def­i­n­i­tion rule to your stylesheet that ref­er­ences these dif­fer­ent font formats.
  4. Use these fonts in font-family style rules.

The only real dif­fer­ence between rolling your own @font-face def­i­n­i­tion and in using the Google Web Fonts API is that you would be pro­vid­ing all for­mats at once instead of a tar­geted for­mat for a par­tic­u­lar browser that the API gives you.

Almost all fonts are web-safe these days.

This entry was posted in Real and tagged , . Bookmark the permalink.
Top

Leave a comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Top