Jon
Rohan

I'm a front end web developer living in San Francisco. I have been coding HTML since I was 15. I strive to be the best I can at what I do. I believe in clean and simple design as well as code. This is where I represent myself on the web. I am always looking to form relationships with other amazing people, part time or full time. contact me!

CSS 3 @font-face

Surprisingly embed-able opentype fonts have been included in Internet Explorer since version 4. But with the recent release of Firefox 3.5 and Safari, you can now embed Opentype and Truetype fonts across all major browsers. It’s pretty simple and here’s how it’s done.

First you must define your font, basically tell the browser where to get the font file, and what you’re going to call it.

/* For IE */

@font-face {
font-family: 'Komika Display';
src: url('Komika_display.eot');
}

/* For Other Browsers */

@font-face {
font-family: 'Komika Display';
src: local('Komika Display Regular'),
     local('KomikaDisplay-Regular'),
     url('Komika_display.ttf') format('truetype');
}

@font-face {
font-family: 'Komika Display';
src: local('Komika Display Bold'),
     local('KomikaDisplay-Bold'),
     url('Komika_display_bold.ttf') format('truetype');
font-weight: bold;
}

@font-face {
font-family: 'Komika Display Kaps';
src: local('Komika Display Kaps Regular'),
     local('KomikaDisplayKaps-Regular'),
     url('Komika_display_kaps.ttf') format('truetype');
}

@font-face {
font-family: 'Komika Display Kaps';
src: local('Komika Display Kaps Bold'),
     local('KomikaDisplayKaps-Bold'),
     url('Komika_display_kaps_bold.ttf') format('truetype');
font-weight: bold;
}

ok, now that you have defined your font, you can use it.

body {
  font-family: Komika Display Kaps, sans-serif;
}

And here’s what it looks like:

This should be the demo font face

The second part of this tutorial is should you use font-face?

This is another call to your server, which when u have a huge website, isn’t a great thing. But compared to most things on a website, this size is tiny.

You have to consider too, for the designers who need the exact font everywhere this is a better alternative than to cut images for every heading on the website, or for the nav. And bonus! The text is still crawl-able by search engines.

If you enjoyed reading this post, check out these posts Using CSS3’s :target pseudo-class to Make a Slideshow, <!DOCTYPE HTML>.

Tags: , , , , , 23 Jul 2009

About the Author, Jon Rohan

Hey! Thanks for stopping by. I love posting new topics here about various development things. If you liked it follow me on twitter and let me know.

Subscribe to Posts

3 comments

Add comment