PSD-HTML. These Pixel perfect HTML pages will be tested on Chrome, Firefox, IE, Safari on OS X and Windows Imajine will help you create your own fan page in facebook with an eye appealing graphic banner for its welcome page Custom CMS theme building weboranje.com - showcase of inspirational web 2.0 websites
CSS3 tutorial to embed custom fonts in web pages

Until recently, web developers were limited to the use of common fonts. But with @font-face now it is possible to retain the unique / custom fonts, one would like to show in his website, of course only if they have the legal right to post those fonts on the web.

What is @font face

Generally, we’ve been limited to using fonts pre-installed on visitor's computer. Increasing support of CSS3 '@font-face' allows us to reflect fonts installed on remote servers on to the web pages. Simply by referring to same in your styles.

Style sheet syntax for the same is provided below

@font-face
{
font-family: MyCustomBebas;
src: url("BebasNeue-webfont.eot") /* EOT file for IE */
}

@font-face
{
font-family: MyCustomBebas;
src: url("bebas_neue_regular.ttf") /* TTF file for CSS3 browsers */
}

.font_style
{
font-family:"MyCustomBebas", Arial, Helvetica, sans-serif;
}

Utility of @font face

In the above example, we have used an true type font called 'Bebas Neue'  to reflect on our web pages.
 
In the above example, you must have noticed that we have 2 '@font-face' tags with 1 refering to '.eot' font format and the other refering to '.otf' font format.  Reason being, CSS browsers like chrome and firefox supports / recognises open type (otf) and true type (ttf) font types, but IE browsers support / recongnise only an embeddable open type fonts (eot).

I used an online free font convertor to convert true type font (ttf) to an embeddable open type font (eot).

Saved this converted '.eot' file and regular Bebas Neue '.ttf' font in a folder along with stylesheet and the web page onto which I wanted custom font to reflect.

The '@font face' style syntax given above can go into style sheet or as a style tag in the head region of web page.

Syntax explanation

@font-face
{
font-family: MyCustomBebas;
src: url("BebasNeue-webfont.eot") /*EOT file for IE */
}
@font-face
{
font-family: MyCustomBebas;
src: url("bebas_neue_regular.ttf") /* TTF file for CSS3 browsers */
}

The first line of the syntax, I have assigned custom font name to 'font-family' predifined variable - ‘MyCustomBebas’. This custom name can be anything you like. But it should be noted that you should refer to this custom name in your style class, like the one shown below

.font_style
{
font-family:"MyCustomBebas", Arial, Helvetica, sans-serif;
}


@font-face syntax second line refers to font source file / path to the same.

where in the IE browser would recognise eot file and thus the font shows up in IE and Google chrome and Mozilla browsers recognise ttf / otf file.

Interestingly, the above utility can also be used to show different fonts in different browsers. Here is an example to show how to do it.

@font-face
{
font-family: MyCustomGnuolane;
src: url("BebasNeue-webfont.eot") /*EOT file for IE */
}
@font-face
{
font-family: MyCustomGnuolane;
src: url("gnuolane_free.ttf") /* TTF file for CSS3 browsers */
}


In the above case, webpage will show 'Bebas Neue' font in IE browsers but 'Gnuolane' font in Mozilla Firefox and Google chrome.

Challenges faced:

The same 'Bebas Neue' font when I downloaded from different source with extension '.otf' -  BebasNeue.otf didn’t work in Google chrome and Mozilla Firefox. The syntax I used for it is given below:

@font-face
{
font-family: MyCustomBebas;
src: url("BebasNeue-webfont.eot") /*EOT file for IE */
}
@font-face
{
font-family: MyCustomBebas;
src: url("BebasNeue.ttf") /* TTF file for CSS3 browsers */
}

Here too, had saved the otf and converted eot file in the same folder. While the font showed absolutely fine in IE browsers, but didn’t show in Mozilla Firefox and Google chrome browsers. The reason I guessed for it not showing in above mentioned browsers was probably because otf font file must have been corrupt.

Live example of css custom fonts can be seen in our imajine website menulinks / titles. Here we have used 'Helvetica Light Condensed Black'.

Tags: Embed External font in web pages, add / show custom fonts in web pages, how to show different fonts in websites, chrome font-face otf, @font-face tut

 

Bookmark and Share
HI, AM JAY, AND I IMAJINE
I am a freelance web designer and web application developer with over 7 years of result oriented experience. I am accustomed to working in a dynamic and goal oriented client environment. My strengths include the ability to visualize, personalize and create a truly unique and enthralling web presence. My passion apart from web design, logo design, Flash animation / actionscripting, CMS Customization, print and web development includes photography, game programming, tutorial development (includes Adobe Flash, Adobe Fireworks and Adobe Photoshop) and blogging.
Read more about me...
CONTACT US
Name :  
Email Address :  
 
Comments :
 
jayanthi.varma@imajine.in  |  © 2008 - 2011 Imajine.