Due to the fact that @font-face can be a bit overly complicated, it hasn’t caught on quite as much as it should. Once you start reading about licensing, different font formats, browser consistencies, it can potentially become more trouble than it’s worth.
But – in five minutes, I’ll try to simplify the process of working with custom fonts as much as I possibly can. Services like Font Squirrel help to make the task a cinch!
Final CSS
@font-face {
font-family: 'blok-regular';
src: url('type/Blokletters-Potlood.eot');
src: local('Blokletters Potlood Potlood'),
local('Blokletters-Potlood'),
url('type/Blokletters-Potlood.ttf') format('truetype');
}
@font-face {
font-family: 'blok-italic';
src: url('type/Blokletters-Balpen.eot');
src: local('Blokletters Balpen Balpen'),
local('Blokletters-Balpen'),
url('type/Blokletters-Balpen.ttf') format('truetype');
}
@font-face {
font-family: 'blok-heavy';
src: url('type/Blokletters-Viltstift.eot');
src: local('Blokletters Viltstift Viltstift'),
local('Blokletters-Viltstift'),
url('type/Blokletters-Viltstift.ttf') format('truetype');
}
h1 { font-family: blok-heavy, helvetica, arial; }
Notice how we’re referencing both an .eot and .ttf font? This is because, of course, Internet Explorer only uses its own format, that has yet to truly catch on. As such, we must first import that .eot file, and then move on to the different formats for Firefox, Safari, etc. It’s essential that you load the .eot version first.
Next, we search for the font on the user’s computer by using the “local” attribute. If it’s unfound, only then do we pass a url that will load the font.
Why Doesn’t IE Try to Load the TTF Fonts?
This was definitely a concern. If Explorer can’t work with the truetype format, we don’t want to waste time trying to download the font. Luckily, because of all those local attributes, and the commas, IE won’t understand any of it. As such, it will simply skip the line all together, thus, only utilizing the .eot version.
- Follow us on Twitter, or subscribe to the Nettuts+ RSS Feed for the best web development tutorials on the web.
- Jack
- http://andreip.net Andrei Patrascu
- http://ministrylogic.com Brandon
- http://builtbyhand.co.uk Neale
- Jeremy
- http://tutsvalley.com Slobodan Kustrimovic
- Micko
- Batfan
- http://tutsvalley.com Slobodan Kustrimovic
- Batfan
- http://tutsvalley.com Slobodan Kustrimovic
- Batfan
- Danijel
- http://www.BryanWatson.ca Bryan Watson
- r_jake
- Dave
- http://stvproductions.net S.T. Verschoof
- Andrew
- Mikey
- http://www.philohermans.com Philo
- James Bull
- James Bull
- http://sffarlenn.net Laneth Sffarlenn
- Viktor
- http://miralize.com Sean O’Grady
- http://cristurm.wordpress.com Cristina Sturm
- http://miralize.com Sean O’Grady
- http://bryceroney.com Bryce
- http://thesacrificebunt.com Melvin
- http://HDesignsPlus.com Hooman
- http://hdesignsPlus.com Hooman
- Evan-XG
- Matt
- http://www.moraywebsolutions.com Gordon
- http://designdotcode.com agilius
- http://nordahl.me Kenneth D. Nordahl
- http://www.mihaomejc.com Miha O
- r_jake
- http://nordahl.me Kenneth D. Nordahl
- http://spotdex.com/ David Moreen
- http://hdesignsPlus.com Hooman
- http://sideradesign.com paul
- Sahan
- http://www.jordanwalker.net/index.php Jordan Walker
- http://www.aboubaker.info/ Aboubaker Nour
- micheal b
- jmarreros
- Lori
- http://www.jc-designs.net/blog Jeremy Carlson
- http://rodrigoflores.ca/ Rodrigo Flores
- http://www.jacktardesign.com Justin
- http://www.eganwebdesign.com Mike
- http://bloggerzbible.blogspot.com/ Bloggerzbible
- Dave
- http://meissen.stadtlog.com Meissen
- Bobbi
- Eric Boxer
- Dave
- http://cocaineandcoffee.com Jesse Jamis
- sovanndy
- http://www.joomlahackers.net Joomla & Magento Services
- http://www.anthonyterrell.com Anthony
- http://www.anthonyterrell.com Anthony
- http://www.siberevlilik.com evlilik
- http://www.sointeractive.co.za nathaniel
- http://www.micelistudios.com Steve
- Alejandro Gonzalez


