How to add your preferable fonts?

Using the font files in our web page

@font-face { font-family: (family-name); src: (the url for the font file); }

/* font decleration */ @font-face { font-family: "MyFont"; src: url("http://my_server.com/fonts/mycustomfont.ttf"), url("http://my_server.com/fonts/mycustomfont.woff2"); } /* font usage */ body { font-family: "MyFont", serif}

Understanding Font File Formats:

WOFF / WOFF2 Stands for (Web Open Font Format). Created for use on web only.

They are compressed, and they contain license info and metadata.

WOFF2 is the newer version and it is more compressed and faster that the older one.

WOFF2 is becoming the de-facto standard for font formats for all devices and modern browsers.

If you don't care about old browsers navigating to your site, then you can just add a reference to this file format only. SVG / SVGZ Stands for (Scalable Vector Graphics Font)

Is a SVG vector format for the font. It is small, which make it perfect for mobile. But with new mobiles support WOFF2, it is becoming less important.

EOT Stands for (Embedded Open Type)

This is very old format from Microsoft, and it is only supported by IE, and it is the only format that IE 8 and lower will recognize. OTF / TTF Stands for (OpenType Font and TrueType Font)

OpenType was an enhancement on TTF. And later WOFF was created to add a licensing to prevent illegal copying of fonts.

Supporting all browsers and font formats

@font-face { font-family: 'MyWebFont'; src: url('webfont.eot'); /* IE9 Compat Modes */ src: url('webfont.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */ url('webfont.woff2') format('woff2'), /* Super Modern Browsers */ url('webfont.woff') format('woff'), /* Pretty Modern Browsers */ url('webfont.ttf') format('truetype'), /* Safari, Android, iOS */ url('webfont.svg#svgFontName') format('svg'); /* Legacy iOS */ }

The simplist way to use different fonts in your web site is using fonts from the "Web-Safe" fonts[ 1 ][ 2 ].But, no impressive design will depend only on these web-safe fonts, and designers add their own preferable fonts to the web site they are building.Fonts comes as files that you have to upload to the site, and then reference them in the CSS file.Usually font vendors provide fonts with different formats in order to be consumable by many different browsers.For example, this is the files come with the font "Font Awesome":After we upload the font files into the web site, we add them into the css files as @font-face rule.The @font-face rule will create the definition for the rule, and later we can use that definition.The syntax to do that is as follows:Whereis a our own name that we give to the font which we are going to use later.And: is the url for the font file that we uploaded.An example for thatThe above code uses only one two file formats (ttf and woff2), but as we can see not all of the browsers support these formats, so we will end up adding more than one file type.We will see down later how to do that, but first let us see what are different file formats for the font.There are many different types and formats of the fonts.And you need to know a little bit of them to know which one you chooseAs you can see, not all browsers support all formats, so it is the designer's responsibility to specify the Url(s) for all these files when defining the font face.So more real example of using the @font-face rule is as follows:The order is important, because the browser will pick the first compatible format it incounter.So, it is important to have woff2 format as almost the first one after the IE compatible ones.