Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web

Create Stylish Webpage using CSS3 Custom Font

4.65/5 (14 votes)
17 Jul 2013CPOL1 min read 34K   27  
Make your website attractive using CSS3 Custom Fonts

Due to licensing issues, the font shown in the image below cannot be uploaded. You can obtain it for your personal use from here[^]. 

All of us want to create an attractive website but many of us don't know properly about How to change or use CSS Custom font. So, We are going to learn How to add various fonts to webpage. 

Let's Start:  

Download Fonts:

First Step is to Download the Font. There are many Websites which provide you thousands of Fonts at free of Cost. I am giving you some links.(I have no profit in sharing these links with you. You can find more on searching on google)

www.1001freefonts.com 

www.dafont.com 

Download the font which you like.

Convert the Font:

Why we require to convert the font(from .ttf to .eot)?

Answer is simple:- Actually most of our browser support .ttf font file except I.E. so if we want to see same font on I.E. also we have to convert it to .eot file. I am providing you a link by which you can convert .ttf to .eot.

Free online .ttf to .eot Converter

Here you have to just upload the font file (.ttf) and convert it to .eot. After converting Download your .eot font file.

Applying Fonts to Web Page: 

HTML
<body>
<p class="new">Anoop Kumar Sharma</p>
</body>

 I have created a page in Html and add a class .new for applying fonts that i have downloaded earlier.

Preview:

 Image 1

CSS: 

CSS
@font-face
{
font-family:defused;/*Supported by major browser*/
src:url("defused.ttf");
}
@font-face
{
font-family:defused;/*for I.E. only*/
src:url("defused.eot");
}
.new
{
font-family:defused;
font-size:40px;
} 

Here using @font-face we can set Source and name to our font.

In above code I have added both .ttf and .eot file so that if user visit my page using I.E or other browser than same font appear to him on webpage.

Finally I apply the font on .new class.

Preview:

 Image 2

That's all.

Hope you like it. 

Please view my other Tips/tricks:

Create Stylish Search Button 

Stylish Glowing button  

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)