Digital Solutions & Online Creative 

Alex runs a small digital creative business from an office in London. It's called Outside In Media.

About

SOYREX is a web development and design resource intended as a place for me to share tips and tricks relating to html, css, web design, web development and other internet and web topics. If you like what you read, leave a comment, or send an email. Also, check out my company web site.

This form does not yet contain any fields.
    Search the Archives

    Online Schools

    Currently Reading..
    • Blink: The Power of Thinking Without Thinking
      Blink: The Power of Thinking Without Thinking
      by Malcolm Gladwell

      Blink talks about flash cognition and sub-conscious cognitive activity.. awesome read!

    • Confessions of an Economic Hit Man: The Shocking Story of How America Really Took Over the World
      Confessions of an Economic Hit Man: The Shocking Story of How America Really Took Over the World
      by John Perkins

      Confessions of an Economic Hit Man - i knew the world was a big conspiracy.. but this is a gripping insight into how the world really works.

    Recommended Reading
    • Designing with Web Standards (Voices That Matter)
      Designing with Web Standards (Voices That Matter)
      by Jeffrey Zeldman, Ethan Marcotte
    • Web Standards Creativity: Innovations in Web Design with XHTML, CSS, & DOM Scripting: Innovations in Web Design with XHTML, CSS, and DOM Scripting
      Web Standards Creativity: Innovations in Web Design with XHTML, CSS, & DOM Scripting: Innovations in Web Design with XHTML, CSS, and DOM Scripting
      by C et al Adams
    Friday
    Jan222010

    Tutorial: using @font-face to embed fonts

    So @font-face has been around for a while now, and everyone has been ranting and raving about how it will change the web.

    Services like typekit have arrived to try and tackle the issue of licensing and distribution.

    However the technology is here. It's cross browser, and it works today. So, this is a quick tutorial in how to easily and quickly ACTUALLY use font-face to embed a font on your site.

    Step 1: select a font.

    The first step in embedding a non-standard font on your site is to choose a font. Now, to avoid the licensing issues, the site of choice (in my opinion) is http://www.fontsquirrel.com/ - their tag line is 100% free for commercial use - just what we want :)

    Font Squirrel have a small blue pill shaped icon with FF in it that indicates if a font-face kit is available for that font, you want to select one of the fonts that has this icon. The font-face kit includes a stylesheet with the correct font-face declarations and also the necessary font files (including the funny EOT files that IE uses). It IS possible to make these files yourself, however this is beyond the scope of a beginner tutorial like this.

    Step 2: Include the CSS

    Now, having downloaded the font-face kit, we move the files into our site directory (inside the css/ folder). Now open up the stylesheet that came in the font-face kit. We want to copy the @font-face rules out and place them in our site's stylesheet (or their own, however you choose to structure it). Either way, we need the CSS for the fonts to be available to the browser before the CSS file that uses them.

    What's actually going on here?

    To help with understanding, let's disect the @font-face declaration in all it's glory:

    @font-face
    {
        font-family: 'MyFont';
        src: url('fonts/MyFont.eot'); 
        src: local('My Font'), 
             url('fonts/MyFont.ttf') format('truetype'); 
    }

    The first line tells the browser we are defining a font face, then inside the braces we are telling it the name we want to use for the font, in this case 'MyFont'. This font-family: declaration can be anything you want, you might call it 'SuperDuperHeadingFont' - this is the bit you will use in your stylesheet when referring to the font.

    The second line of these @font-face calls is the first in a chain of src: declarations, it references an .eot file, which allows Internet Explorer to render the font (curiously, IE has had the ability to do this for years, but only with EOT font files.. the other browsers support TTF and OTF files). It's important that the EOT declaration is first, so that IE doesn't think the font-face call has failed.

    The second src declaration is for the other browsers, it contains a call to local('My Font') which instructs the browser to check the local system for that font before downloading the remote version (it makes no sense to download the embed if the user's system already has the font).. and the second call is to url('fonts/MyFont.ttf') format('truetype') - this tells the browser to grab the TTY file from the url fonts/MyFont.ttf, it also instructs the browser to expect the TTF file to be a truetype font.

    Step 3: Use the embedded font in your normal CSS

    Now, with the above example, we are able to now use MyFont as a font declaration in our CSS files. So if we were to use that font for the H1s on our page we would simply add:

    h1 { font-family: MyFont, Helvetica, Arial, san-serif; }

    Remember to always stack your fonts, just in case a user's browser can't display the custom font, that way the page wont go completely haywire. In this case i've assumed that MyFont is a san-serif and stacked Helvetica and Arial under it, so we should gracefully degrade to a similar standard font if their browser doesn't support the external font (for example, at the time of writing, iphones don't support @font-face).

    Ok, so there we have it, @font-face using fontsquirrel's font face kits. You can view an example on my studio website: http://outsideinmedia.co.uk - the headings and body copy use a custom font called Titillium.

    Hat tip to fontsquirrel.com, for making cross browser font embedding free and easy for beginners :) Enjoy!

    PrintView Printer Friendly Version

    EmailEmail Article to Friend

    References (1)

    References allow you to track sources for this article, as well as articles that were written in response to this article.

    Reader Comments (55)

    very useful!

    February 7, 2010 | Unregistered CommenterChris

    Maybe this is me talking nonsense, but it seems like Google isn't a company run strictly by the top and they seem to be doing quite well.

    February 11, 2010 | Unregistered CommenterJamesDX

    Do you like this better than cufon?

    March 3, 2010 | Unregistered CommenterNatetronn

    @Natetronn: cufon is a javascript based font replacement engine. While it's great, in that it doesn't require any plugins etc, it still creates image (or canvas) based text, which is not really ideal.

    The advantage of @font-face is that it is actually rendering standard system text - better for SEO and doesn't require any Javascript or plugins...

    So in answer to your question, i wouldn't say i like it more than cufon, simply that i think it's a cleaner solution than cufon.

    March 12, 2010 | Registered Commenterrex

    good job...

    Thanks for the information and post.

    March 20, 2010 | Unregistered CommenterWeb Development Company

    Great Post. Very useful.

    Thank You :)

    April 3, 2010 | Unregistered CommenterArunprasad

    Nice Article. I am attempting to use 4 @font-face fonts in a pulldown selector, but I must be referencing the font names incorrectly as they don't change.
    Do you have any suggestions ?
    thanks so much

    April 12, 2010 | Unregistered CommenterDennis

    Awesome tips! This is really useful for those who are starting in web designing.

    April 18, 2010 | Unregistered Commenterchicago limo companies

    Thanks for the tutorial!

    April 21, 2010 | Unregistered CommenterWeb development Beijing

    this is great i always wanted to use custom fonts on my sites .. can i use this method with my own fonts or i'll have to use fonts of this site?

    April 24, 2010 | Unregistered Commenterkareem

    Awesome! it was really helpful tutorial.....

    May 13, 2010 | Unregistered CommenterClipping Path

    Great Post. I'm stoked that this let's me use one of my favorite fonts now on my site. Thanks for the tip. LB

    June 9, 2010 | Unregistered CommenterLes

    Great interesting articles loved to explain about it to all my friends

    June 10, 2010 | Unregistered CommenterPhone Systems UK

    I’m a young webdesigner ! very useful and so informative,thanks and keep this effort up.

    June 16, 2010 | Unregistered CommenterWeb development London

    <p>We are a professional supplier of wholesale designer handbags ,wholesale gucci,please feel free to
    contact us if you need fashion handbags.
    Find all the latest fashion, brown handbag, celebrity gossip and leather handbags!
    Different Colors And Sizes Available. </p>
    We take pleasure to introduce ourselves as manufacturers and exporters of all kinds of ladies high heel shoes.We are manufacturers and exporters of all kinds of high shoes. We specialize in wedding shoes fitted with Swarovski and imitation diamond

    July 12, 2010 | Unregistered CommenterFrank

    <p>We are a professional supplier of wholesale designer handbags ,wholesale gucci,please feel free to
    contact us if you need fashion handbags.
    Find all the latest fashion, brown handbag, celebrity gossip and leather handbags!
    Different Colors And Sizes Available. </p>
    We take pleasure to introduce ourselves as manufacturers and exporters of all kinds of ladies high heel shoes.We are manufacturers and exporters of all kinds of high shoes. We specialize in wedding shoes fitted with Swarovski and imitation diamond

    July 12, 2010 | Unregistered CommenterFrank

    Discount EasyTone shoes here. Reebok EasyTone wholesale. Reebok Easy Tone on sale.

    July 12, 2010 | Unregistered CommenterDiscount EasyTone

    Fitness shoes of MBT and Vibram Five Fingers are collected at our website. MBT Shoes on sale. MBT Shoes Clearance. You will find high-quality brand shoes at low prices.

    July 12, 2010 | Unregistered CommenterDiscount EasyTone

    I really like your website http://soyrex.com , our website as well。coach outletis the market popular longest and most successful leather brand. Especially the coach handbagsand coach bags have a good reputation for quality and exquisite craft in female consumers.
    MBT shoes
    reebok easy tone
    shape ups shoes
    P90X
    P90X Workout
    P90X DVD-Fitness
    birkenstock sandals
    birkenstock gizeh
    birkenstock Madrid

    July 12, 2010 | Unregistered Commentercoach outlet

    One of the easiest ways to have a backup of your most important files is to back up hard drive to SIMON & SIMON or simply copy them all in SIMON & SIMON DVD format. Aside from lightweight to carry, having your files on SIMON & SIMON DVD COLLECTION can also be easily accessed, unlike having backups online, in which the speed of access is dependent on the speed of your internet.
    Hardy clothing has a way of showing itself off. With an extensive range to choose from for men, women and kids, hardy shirt has something for everyone. So you're a guy and looking to impress the girls? Choose the macho looking hardy shirt tees and team them up with a sexy hardy shirts hat and it becomes a killer combination.
    The kind only a scarpe Hogan can give. That's a very special kind. Freedom: Yes, that's there. hogan donna are all about going your own way. Play hoops in your Hogan uomo on Sunday, then go to work on Monday. Or, do it the other way around. Either way, your Hogan scarpe uomo let you express your personality. That's what they're for.

    July 13, 2010 | Unregistered CommenterED clothing

    At the first look, these might look like the Air Jordan 7 jumpman shoes that released back in 2006. But, the colorway is entirely different from the pacific’s. These 7s sports a nice and clean white leather upper. Orion blue and michael jordans shoes are evenly split onto the sole, tongue, and heel. What do you think of this latest Air Jordan VII Retro?which just so happens to be a Thursday. Thursday is an unusual day for an Air Jordan release considering that most Jordan’s are released discount jordan shoes. For now, this release date change only applies to Foot Locker, but if any other retailers follow, we will let you know. This is great news for most people, but it could be bad news for some trying to save up with two less days. Look for these July 1st at Foot Locker locations and Footlocker.com

    No sport event could have been air force ones shoes than the recent 2010 World Cup. And a lot of sneaker manufacturers who put some of their designs to be in line with the event will continue to delight air jordans shoe of sneaker fanatics. To further expand on encouraging team spirit, Puma came up with the Tekkies World Cup which is available at Puma City in New York.The Air jordan sneakers shoes Infrared Pack will go done as one of the best Jordan packages when Jordan Brand is all set and done. The pack caused major mayhem on the release date as limited numbers caused people to put blood and tears into their package.

    July 13, 2010 | Unregistered Commenterwholesale jordan shoes

    <p>Eventually women began sporting these thick framed glasses too. This was also the sunglass shop the cat glasses for women first became popular. Many people are fond of wearing these 50’s inspired sunglasses up to now, including celebrities and fashion elites.Most people are fond of sunglasses shops eyeglasses from the golden age of fashion in order to make a fashion statement while others use these styles from celebrity sunglass to compliment their current styles further.</p>
    <p>Aside from colored lenses, vintage designer shades also gave way to the mirrored type of sunglasses, which were very common in the 80s. These mirrored designer sungalsses are back in style again and even made more popular than ever thanks to the celebrities who flaunt them. Dark ray ban polarized sunglasses could be used for these mirrored sunglasses as well.

    </p>

    July 13, 2010 | Unregistered Commenterwholesale sungalsses

    To be able to store your files on SISTERS or saving a copy of it on disks, of course, you need to have a SISTERS DVD drive, where you can put your disk and copy files on it. These times when the floppy disks are seen to be obsolete, PCs usually have SISTERS DVD COLLECTION drives which are also useful in installing programs, drivers, and especially your operating system.
    With cool prints made to order for the youthful attitude, Ed Hardy clothing can make you look different and trendy. And if you're a girl on the look out for some male attention, then also hardy shirt has the solution for you. With their feminine styled jeans and tees that are body hugging with bold designs, hardy shirts can do wonders to your figure and your style quotient. These funky designs of hardy shirts are adopted by fashion icons like Paris Hilton and Britney Spears amongst many.
    The kind only a scarpe Hogan can give. That's a very special kind. Freedom: Yes, that's there. hogan donna are all about going your own way. Play hoops in your Hogan uomo on Sunday, then go to work on Monday. Or, do it the other way around. Either way, your Hogan scarpe uomo let you express your personality. That's what they're for.

    July 13, 2010 | Unregistered CommenterED clothing

    Discount Louis louis vuitton handbags Vuitton Handbags,Wallets & Purse louis vuitton Online Store. In

    louis vuitton replica handbags the my lv replica handbags store buy designer handbags cheap Louis louis vuitton handbags Vuitton Handbags, You replica handbags best choice.louis vuitton,louis vuitton handbags,louis vuitton handbag,louis louis

    vuitton handbags vuitton bags,louis vuitton bag,louis vuitton wallets,louis vuitton wallet,gucci,gucci wholesale louis vuitton

    handbags handbags,gucci handbag,gucci bags,gucci bag,gucci wallets,gucci wallet,prada,prada handbags,prada handbag,prada bags,prada wholesale replica handbags bag,prada wallets,prada wallet,buy prada handbag.
    815GSW0715

    July 15, 2010 | Unregistered CommenterReplica Handbags

    PostPost a New Comment

    Enter your information below to add a new comment.

    My response is on my own website »
    Author Email (optional):
    Author URL (optional):
    Post:
     
    Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>
    « Tutorial: Sketched Text in Photoshop | Main | Quick Tip: Grounding web designs in Google Chrome »