CSS @font-face Rule

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP




<!--
main_leaderboard, all: [728,90][970,90][320,50][468,60]
-->




CSS @font-face Rule



Previous
Complete CSS Reference
Next



Example


Specify a font named "myFirstFont", and specify the URL where it can be found:



@font-face


   
font-family: myFirstFont;

   
src: url(sansation_light.woff);

Try it Yourself »

More "Try it Yourself" examples below.



Definition and Usage


With the @font-face rule, web designers do not have to use one of the "web-safe" fonts
anymore.


In the @font-face rule you must first define a name for the font (e.g. myFirstFont), and then point to the font file.


Tip: Use lowercase letters for the font URL. Uppercase
letters can give unexpected results in IE!


To use the font for an HTML element, refer to the name of the font (myFirstFont) through the font-family property:



div


   
font-family: myFirstFont;


Browser Support


The @font-face rule is supported in Internet Explorer, Firefox, Opera, Chrome, and Safari.


The numbers in the table specifies the first browser version that fully supports the
font format.







































Font format
TTF/OTF 4.0 9.0* 3.5 3.1 10.0
WOFF 5.0 9.0 3.6 5.1 11.1
WOFF2 36.0 Not supported 35.0* Not supported 26.0
SVG 4.0 Not supported Not supported 3.2 9.0
EOT Not supported 6.0 Not supported Not supported Not supported

*Edge and IE: The font format only works when set to be "installable".


*Firefox: Disabled by default, but can be enabled (need to set a flag to
"true" to use WOFF2).






<!--
mid_content, all: [300,250][336,280][728,90][970,250][970,90][320,50][468,60]
-->




Syntax



@font-face


    font-properties

























Font descriptor Values Description
font-family name Required. Defines the name of the font.
src URL Required. Defines the URL(s) where the font should be downloaded from
font-stretch normal

condensed

ultra-condensed

extra-condensed

semi-condensed

expanded

semi-expanded

extra-expanded

ultra-expanded
Optional. Defines how the font should be stretched. Default value is "normal"
font-style normal

italic

oblique
Optional. Defines how the font should be styled. Default value is "normal"
font-weight normal

bold

100

200

300

400

500

600

700

800

900
Optional. Defines the boldness of the font. Default value is "normal"
unicode-range unicode-range Optional. Defines the range of unicode characters the font supports. Default value is "U+0-10FFFF"


More Examples



Example


You must add another @font-face rule containing descriptors for bold text:



@font-face
    font-family: myFirstFont;
    src: url(sansation_bold.woff);

   
font-weight: bold;

Try it Yourself »

The file "sansation_bold.woff" is another font file, that contains the bold
characters for the Sansation font.


Browsers will use this whenever a piece of text with the font-family "myFirstFont" should render as bold.


This way you can have many @font-face rules for the same font.



Related Pages


CSS tutorial: CSS Web Fonts




Previous
Complete CSS Reference
Next

Popular posts from this blog

California

New York City

CNN