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

HowToPlaza Earn money writing

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
  • 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.com 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/Guj_Regular_SULEKH.eot');
    src: url('http://www.samvadprakashan.com/Guj_Regular_SULEKH.ttf');
    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
  • 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.com
    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.com/uploads/cataneo_bt.ttf" 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.blogspot.com/2010/03/making-css-custom-font-works-with-ie.html
  • 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!
  • 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: