Bio
I'm interested in technology, web education, and writing. I create a daily writing prompt at First 50 Words and write about web education and web tec...
 
 
 
 

Most Popular

How to Embed Fonts the Easy Way

  • Share This Post
  • Pin It
  • 9
  • Sparkle (
    )
     

For a while, I toyed with the idea of using embedded fonts to liven up my web pages. I would read articles on how to do it and get discouraged. Some browsers needed one kind of font, some another -- it was too much bother.

Then Google came out with a font-embedding system that is dead easy. You can get started with them at the Google Font API page.

For completeness, I must add other sources for embeddable fonts. One is Font Squirrel. It uses a different technique involving the CSS @font-face declaration. With Font Squirrel, you download the font and put it on your server. TypeKit sells access to embeddable fonts, which are on their server network. TypeKit has many more fonts than the free sources do. The price structure on TypeKit is very reasonable.

The How To

Google's tools are the easiest to use. Here's how you would use Google fonts.

  1. Pick a font you like from the Webfonts page.

    font choices

  2. Click a font you like. You see it in various sizes. Click the Tab that says "Get the Code."

  3. There are two code snippets. The first you paste into the head of your HTML document. Make it the first thing in the head. (I'll get to why in a minute.) I wanted to try Cantarell, so I pasted this code into my web page.

    link in head to embedded font

  4. The second code snippet goes into your CSS file. I changed it up a bit to include three sizes of headings and default to sans-serif rather than the serif in their example code. Here's how my CSS looked.

    CSS rule for embedded font

  5. Upload the HTML and the CSS to your server and take a look at your page. (You may need to refresh the page.) Here's how Cantarell looks on my web site.

    browser display of embedded font

The Caveats

The Google fonts work with most browsers, but with limits. You mostly need a pretty up-to-the-minute version of any browser to see the magic. Don't remove that old font rule in your stylesheet -- just put the new one calling a font from Google after your original rule. If the browser doesn't know the embedded font magic, it will still show your original font.

The other limit is download time. If you have a lot of users with dial-up, mobile users, or users with slow connections of some other kind, you may want to stay away from the idea for a while longer. It's whiz-bang fast with cable or DSL, but that may not be the people your web page targets.

It works in Google Chrome versions 4.249.4+. Chrome renders the rest of the page, but until the web font has loaded, it displays a blank space in place of the text that uses the font. This may cause a problem with slow connections. Apple Safari versions 3.1+ work. Like Chrome, Safari renders the rest of the page, but until the web font has loaded, it displays a blank space in place of the text that uses the font. The same thing applies in Internet Explorer versions 6+. The reason the LINK element you paste into the document head must go first is because of Internet Explorer. If it isn't the first thing there, the whole page may not render.

The fonts work in Mozilla Firefox version: 3.5+. In Firefox, the first display is the text in the default font. Firefox then re-renders text in the web font once it has loaded. So, the user sees something, but it may change appearance unexpectedly when the connection speed is slow.

For Opera versions 10.5+, Google mentions no problems. Imagine that.

--

Virginia DeBolt
BlogHer Contributing Editor|Web Teacher|First 50 Words

  • 9
  • Sparkle (
    )
     

Comments

Post comment as twitter logo facebook logo
Sort: Newest | Oldest
Virginia DeBolt 5 pts

to learn that you are the other person who's read my book!

Hope you have some fun with fonts.

Virginia DeBolt
BlogHer CE ( http://www.blogher.com/blog/virginia-debolt ) | Web Teacher ( http://www.webteacher.ws/ ) | First 50 Words ( http://first50.wordpress.com )

AJillofAllTrades 5 pts

Well we can't all be perfect designers and do everything right as beginners.

That's why it's great to have guidance from awesome people like Virginia and have resources so easily accessible.

For that I am very grateful. I started designing in the late 90s and first learned CSS a couple of years ago by reading Integrated HTML and CSS.

Whether I like certain design ideas/advances/whatever or not doesn't mean they are a bad idea. We can all learn something from others mistakes and successes.

Many thanks to you Virginia for having a large impact on who I am as a developer/designer.

MLOKnitting 5 pts

I keep getting pictures of some of those scarier sites out there. I am having visions of what else this woman (http://yvettesbridalformal.com/index.htm) could have done if she had had fonts.

:: shudder ::

ETA: It has also helped that I used to be able to tell the type of client who wanted every font and color that the web couldn't do that!!!

MLO / Melissa

Books, Movies, Games, Ovarian Cancer, and Life in General at http://www.mloknitting.com/

Virginia DeBolt 5 pts

Give an amateur a font and she'll end up with 30 different ones on the page.

Virginia DeBolt
BlogHer CE ( http://www.blogher.com/blog/virginia-debolt ) | Web Teacher ( http://www.webteacher.ws/ ) | First 50 Words ( http://first50.wordpress.com )

MLOKnitting 5 pts

SGML was specifically designed to separate content from design. Really, I was one of the people who was originally doing it back in the early 1990s. HTML is a DtD and CSS is a way for designers to implement their vision on that DtD.

Most designers do not design well - just like most of any profession don't do things well. More fonts is an invitation to disastrous designs by those enamored of font faces over information exchange.

MLO / Melissa

Books, Movies, Games, Ovarian Cancer, and Life in General at http://www.mloknitting.com/

IsleDance 5 pts

Fantastic tutorial - thank you!

One Friday night, I loaded up my life and headed out... ( http://isledance.blogspot.com )

Virginia DeBolt 5 pts

just like any other aspect of a design, I have to say that I think font choices are a powerful part of a page design. The more font choices you have an easy way to use, the better, in my opinion.

Separating content from appearance was not a feature of the original markup language. When CSS was introduced, it became possible.

In the days before font embedding became possible, designers used images of words to create custom appearances involving fonts. Since images are not text, this creates some serious accessibility problems. Words using embedded fonts are displayed as text, and are definitely better than images.

Virginia DeBolt
BlogHer CE ( http://www.blogher.com/blog/virginia-debolt ) | Web Teacher ( http://www.webteacher.ws/ ) | First 50 Words ( http://first50.wordpress.com )

MLOKnitting 5 pts

People do NOT know how to use fonts properly - including so-called online designers. There are only a handful of acceptable online fonts and they should never have included Times New Roman and Arial.

This, to me, is the worst possible news as one of the great strengths of the originating mark-up language of the internet was the separation of content from appearance. It was supposed to allow users more control over what they see. I really wish Google had not introduced this technology.

Embedded fonts are the work of evil internet daemons!

MLO / Melissa

Books, Movies, Games, Ovarian Cancer, and Life in General at http://www.mloknitting.com/