Home / Web Designing / How To Use Custom Fonts On Your Website With CSS

How To Use Custom Fonts On Your Website With CSS

by Sarah Watts



With CSS (Cascading Style Sheets) you can use custom fonts on your website. Normally your visitors can only see the fonts that are already installed on their computers. So if you use a font that is not installed on your website visitor’s computer then his or her browser will show some other font that is there on the computer. That’s why when you are defining a font for an element (such as <p>) you often specify multiple fonts so that if your preferred font is not available your CSS file should use the available alternatives.

Conventional way of using custom fonts for headings and logos etc. is creating the text in a graphic editor and then using the image file. From the perspective of SEO this is not appropriate; you must use text as much as possible.

Now there is a way around in CSS that lets you use custom fonts, downloadable fonts on your website. You can download the font of your preference, let’s say cool_font.ttf, and upload it to your remote server where your blog or website is hosted.

Then from within your CSS file (or wherever you are defining your styles) you have to refer to that custom font in the following manner:

1
2
3
4
@font-face {
	font-family: cool_font;
	src: url('cool_font.ttf');
}

After that you can use it just like a normal CSS declaration:

1
2
3
p.custom_font{
	font-family: cool_font; /* no .ttf */
}

This way you can use as many custom fonts as you feel like on your website.

As you can notice in the comments section, this method of using custom fonts on your website doesn’t work with Internet Explorer (but of course!). Please refer to this link in order to know how you can make it work in IE too.

Related posts

  • No Related Post
  • Dredlore

    Awesome.. it helped me when i was stuck..
    if you want to see it in action the page in progress..
    http://www.bee-amazed.com/KAOS
    check the title.

  • Susan

    I used this method for a while but then I found this WP theme generator called Lubith which has a great typography extension. over 400 fonts to choose from and no trouble with compatibility or copyright issues. I get my design in no time with no code and time spent on the web searching and downloading fonts.

  • Sallosalla

    function ae_detect_ie()
    {
        if (isset($_SERVER['HTTP_USER_AGENT']) && 
        (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false))
            return true;
        else
            return false;
    }
     

  • Sallosalla

    block IE using this script ;-)

     

  • Sallosalla

    Nice!
     

  • Utpal Cse Mbstu

    nice

  • Ssss

    Thank you very much

  • guest

    this doesn't work at all ...???

  • Hamad

    Testing.. Testing...

  • Thanks, this is exactly what I was looking for, but I'm still having some trouble getting it to work in IE. Since so many people online use IE, cross-compatibility is really important.

  • AndyM

    FOR PEOPLE WHO CAN'T SEEM TO GET THIS WORKING:

    try putting the css and font files in THE SAME FOLDER as the html.... it worked for me!

  • You can also try the Google Fonts API -

    Not a massive selection of fonts, but pretty easy to use for most website designs & also works in IE.

  • Anoop Technopark

    Thank you for sharing this information. I was searching for this on internet for 2 days...
     

  • hougye

    this method is quite useful for us all...

  • Maneksh V.Thomas

    Hello,
    Liked your post. The link led me to the article to use with IE but it does not work with IE9 as expected. So I had to use a work around. Thought I'd put it up just in case you will like to update ur article with it. Infact this seems to work with everything.The Idea is that I declare both Fonts with separate names and attach them as a font family.

    @font-face{
    font-family: myFont;
    src: url('myFont.ttf');
    }

    @font-face{
    font-family: myFontEI;
    src: url('myFont.eot');
    }

    Then Attach it as a font family like so...

    font-family: myFont, myFontEI;

    Hope it helps... :)

  • Kevin

    I just could not leave your web site before suggesting that I extremely
    loved the standard information an individual supply to your guests? Is
    gonna be back incessantly to check up on new posts

    getting rid of belly fat

  • Adilahmedmd

    Hi
    i trid same what u told
    but its not working in IE 8 with .eot

  • villagertest
  • thank you so much, this works well on my site, luv this trick

  • shiduoaa

    Thanks for your guide! It's quite difficult to figure out which font-family I should modify since there are many font-family.

  • andrew

    Everyone seems to have it working on every browser (and firefox) but it doesn't work with firefox for me. I even got it working with IE. Can someone help please

  • my own favorite css in my blog.....thats cool

    http://www.waterproof-camera.u...

  • instantanc

    the blog is really popular all around the world...

    everyone want to use it

  • ktbsayrelax

    Awesome, but I've tried this twice for two different custom fonts and it won't work on the second font? hmmm ... 

  • Santosh

    thanks,

    but it not work in ie how to apply for ie 

  • Alok12f

    I am using this type of font : Gelder Sans Book
    but only work in IE and not working in other browser .

  • nd

    thanx for this informationi developed a websitehttp://www.nidiots.co.inso suggest the font for this web site

  • Thank you so much for this I have been looking for a way to embed custom fonts into my site for ages now!

  • NicolasCacace

    I noticed that font sites have MAC and PC versions for fonts....

    Does the solution above apply to all platforms, after all it is for web right?

  • thesophist

    Hello!  Thank you for the great tutorial!  I was wondering, are there some font types that cannot be used?  I am attempting to use "Bank Gothic" on my site and I have loaded the font pack into the site folder and properly addressed it in my master CSS sheet, but it won't load in my browsers (Chrome, FF, Safari) nor Dreamweaver's live view.  Here is the section of my CSS:

    @font-face { font-family: BankGothic; src: url('fonts/BankGothic');}@font-face { font-family: BrushScript; src: url('fonts/BrushScriptStd.otf');}

    On a side-note, Brush Script is working fine.  I think the problem is that the font pack I have for Bank Gothic is a font suitcase and has no extension, but I am unsure what extension to put into my CSS to get it to load.  Thanks!

  • Quint

    Hello, did you ever get the Gothic font to work?

  • Ctcmiami

    Is it possible to attatch the custom fonts to any other html tags... for example can I use the <h1> or <font> tag (or any other tag for that matter),  instead of, or alongside the

    tag???

    </font></h1>

  • rhodri80

    very good puuuuuur

  • Jjackson02

    Oh, try the html5boilerplate.com/ to get IE 7-8 to work. ;)

  • Jjackson02

    works in FF, IE7 and 8 for me. Thanks

  • c13133

     i love it! you guys saved my skin!

  • Jaeggi Roger

    IE use the .eot Fonts Type

    @font-face {
    font-family: "Droid Serif";
    src: url(DroidSerif-Regular.eot);

  • Gr8 post. Thank you very much

  • Deben2008

    Thnx.....

  • Sachin

    Thankx but its not work with internet explorer.

  • Wouter_verreydt

    Why are you using MSIE in the first place?

  • That's Microsoft's fault.

  • David

    YES!

  • itmartins

    Good job pal!

  • Sheshe

    Thank you :)

  • Witzoar

    what about the browser compatibility?

    answer or forward that article at razak.salman@gmail.com

    thank you!

  • rvguy

    Thank you!
    I was having correctly this problem. :)

  • Himanshu Monga

    Thanks you helped me..

  • Satnam2k2

    hello r u there???

  • Amardeep Yash

    Plz give a solution to ie 6,7

  • Amardeep Yash

    It's not working in ie 6,7

  • Free_agent

    Hello,

    I am an absolute beginner and I cant get this code to work for me! I have a few embarrassing questions so if anyone can help that would be awesome!

    1. Can I paste the @font-face code ANYWHERE in my CSS document? If not, where should it go?

    2. With this part of the code src: url('cool_font.ttf'); do I type in the url address of where my font is located where it says url or keep the code exactly as it is with my font name in brackets?

    3. After this has been completed how do I apply this font? I have tried applying it to a heading but the heading keeps defaulting to another font.

    Any help is appreciated.

  • subhramani

    1. This can go anywhere in your CSS file.

    2. The font should be in the same directory as your CSS file (to reduce headaches).

    3. Once you put the font in the same directory as our CSS file, just mention the font name and not the whole URL.

    4. Even I cant get it to work. Hahahah! :-D

  • Dave

    great! it helps me very much!

  • JayPee Mateo

    thanks for this info

  • Simple and Easy.. Thank you.

  • Developer&Designer

    Thanks this was really easy and helpful

  • Rachel

    YOU ARE SUCH A DARLING! :D

  • nicepawn

    Very nice trick! Thank you for your help!

  • Kitsunekaze93

    this crashes my site =/

  • Aditya Bajaj

    Thank you so much this is the best way of using customs fonts without limiting bandwith usage

  • Antonio

    Awesome

  • Theadsbook

    great

  • tHANKS howtoplaza, this tutor make me easy to customizing my sites.

  • @bdunn. I think you need to check the path of the files on your server.

  • The font I am wanting on my site works great when I am looking at the pages on my local machine. But when I upload to the server, it goes back to the default times font. Any ideas?

  • Aditya Bajaj

    have you put the actual font file somewhere on your ftp server the link in the first css should also point to it.

    All the best

  • Thanks!!!! works like a charm :).

  • very good. Thanks for shareing.

  • Hey guys, it work like charm in all browsers. I really don't know how to thank you all contributor.

    Thanks to Sarah and all. hv a good one.

  • Ms. Sarah Watts,

    Thanks for your quick response. I've added following code in my style.css and it works on firefox and chrome.

    I've also converted ttf to eot,using http://ttf2eot.sebastiankippe.... and updated in my theme folder but its not showing in IE. can you guide pls?

    @font-face {
    font-family: "Guj_Regular_SULEKH";
    src: url('http://www.samvadprakashan.com...
    src: url('http://www.samvadprakashan.com...
    src: local(Guj_Regular_SULEKH), url('Guj_Regular_SULEKH.ttf') url('Guj_Regular_SULEKH.eot') format('opentype');
    }
    p { font-family: Guj_Regular_SULEKH }

    Thanks and vbr,

  • Hello Jimmy.

    In wordpress you'll have to upload the custom fonts in your current theme folder, something like
    /wp-content/themes/current-theme

  • Hi Guys,

    I'm trying to display font on wordpress website and I'm using custom indian font to display.

    I copied font into public_html folder and add following code but still no luck. any help please!!

    code i add in style.css:

    @font-face {
    font-family: Guj_Regular_SULEKH;
    src: url('Guj_Regular_SULEKH.ttf');
    }

    p.custom_font{
    font-family: Guj_Regular_SULEKH; /* no .ttf */
    }

  • Hello Rakesh.

    In the end of the post I've mentioned a link where you can find information on how to make it compatible with IE :-)

  • Rakesh

    Hi,

    Is it work for IE browsers? i am using custom font for my new project it has to be compatible for IE6, 7, 8, Firefox, Chrome, Safari, Opera

  • Daniel

    It does not work for IE 7 and 8. This CSS Attribute was added in addition to CSS3.

  • Tq,this tutorial that i want

  • css

    @font-face {
    font-family: "Alexandra";
    src: url("Alexandra"), url("Alexandra.ttf") format("truetype");
    }

  • http://www.gucci-shoes-bags.co...
    http://www.guccinewshop.com
    Dear friends welcome to our store: we have a specail offer now which is once you buy any product you can get a free gift as well, these gifts are in the gift area, you can free to choose and please add to the shopping cart, we will send it together with your purchased product. Thanks!

  • Joshua

    can I define a font more than once?

  • Joshua

    Can i have multiple fonts?

  • Anonymous

    Can someone explain to me? :D What part should i add in css and what to html file? Where to define that font?

  • Rob

    I used the following code and it shows up in safari and chrome but not firefox 3.6.3. Any ideas?
    @font-face {
    font-family: "MyAmaze";
    src: url(customFonts/amazr.ttf);
    }
    p.customfont { font-family: "MyAmaze"; }

  • summi

    mehndi
    impressions

    That's what I have right now in my website for the title. I have the font Cataneo BT installed on my server as a .ttf file, but I don't think I referenced it right, so it shows up as times new roman on alot of computers. But when I tried to add the src to it, it still didn't work. So I don't think I know where to add it in the html the right way. I'm not a website person at all, I just made it for a side business. If anyone knows how to reference the font, just let me know!

    p.s. I'm using webstarts.com if that matters. And as far as I know, the source for the .ttf file is "http://www.mehndi-impressions...." but I could even be wrong on that one.

  • Hello Ccchai (?). I'll put a reference to this link in the post. Thanks.

  • ccchai

    Prabakar, it does not work in IE because IE does not support TTF / OTF. Please refer to my blog post on how to make it work with IE. http://symphony-of-dot-net.blo...

  • Prabakar

    thank u so much
    this coding is working well
    but this codes are not working in internet explorer why this problem

  • Things are as easy and difficult as we make them out. I think some people make things appear difficult just to sound important.

  • Sarah

    Thank you so much!

    I don't understand why every other answer to using custom fonts that I find either says it's impossible or makes it super difficult. I've designed so many sites around the crappy pre-installed fonts and it's this simple?! Cheers!

  • Please mention tag or code for custom fonts

  • THANK YOU VERY MUCH FOR A WONDERFUL TUTORIAL......IT's REALY AWESOME.

  • thank you! fonts on my website is just what i need. thumbz up!

  • Rohitazadwebdesigner

    solutions for newicvs.com

  • bhuros

    How To Use Custom Fonts On Website With CSS and withOut install font

  • Hamed

    Thanks Usefull

  • Mail

blog comments powered by Disqus

Previous post:

Next post: