Categories: DevelopmentWeb Design

Using custom .ttf or .otf fonts in css and html

If you want to use a custom font from dafont or other font websites they usually come as either a .TTF or .OTF here is how to use these fonts in web development and design.

Firstly have your font file that you want to use downloaded. Now go to onlinefontconverter.com

Make sure these types are selected

Click SELECT FONTS and upload your font file (.TTF or .OTF)

Now you want to download the zip file, in it there will be a folder with your font in 5 different file types.

* The reason we wanted the font file in all these different types is because we want to support a wide variety of browsers. .WOFF type is used by every major desktop browser, while the .TTF type is for older Safari, Android and iOS browsers.

Drag these font files into a fonts folder in your web site directory.

Now in your .CSS file you want to paste what was in the font.css file in the onlinefontconverter zip into the top of your .CSS file. An example is like:

@font-face {
  font-family: 'customFont';
  src: url('/fonts/customFont.eot');
  src: url('/fonts/customFont.woff2') format('woff2'),
       url('/fonts/customFont.woff') format('woff'),
       url('/fonts/customFont.ttf') format('truetype'),
       url('/fonts/customFont.svg#customFont') format('svg'),
       url('/fonts/customFont.eot?#iefix') format('embedded-opentype');
  font-weight: normal;
  font-style: normal;
}

body {
color: white;
}

h1 {
font-size: 21px;
font-family: customFont;
}

 

You will see i wanted h1 to use my custom font that i uploaded so i made sure it had font-family: customFont; defined.

 

Share

Recent Posts

Kennington reservoir drained drone images

A drained and empty Kennington reservoir images from a drone in early July 2024. The…

2 years ago

Merrimu Reservoir drone images

Merrimu Reservoir from drone. Click images to view larger.

2 years ago

Early September spring shots

Some early September spring shots from a bushwalk, It is still too early for wildflowers.

3 years ago

Cloning an NVMe to SK Hynix Platinum P41 NVMe

I recently needed to clone over a smaller NVMe to a 2TB SK Hynix Platinum…

3 years ago

Using Laravel’s deleteDirectory to delete folders and their contents

If you ever needed a simple solution in Laravel to delete an entire directory and…

3 years ago

How to allow only 1 user to register in a Laravel application

How to enforce only one user to register or be registered in a Laravel web…

3 years ago