CSS3 @font-face rule
Example
Specify a font named "myFirstFont" and indicate the URL where it can be found:
@font-face
{
font-family: myFirstFont;
src: url('Sansation_Light.ttf'),
url('Sansation_Light.eot'); /* IE9 */
}
Try it »
Browser support





Internet Explorer 9, Firefox, Opera, Chrome, and Safari support the @font-face rule.
However, Internet Explorer 9 only supports fonts of type .eot, while Firefox, Chrome, Safari, and Opera support both .ttf and .otf font types.
Note: Internet Explorer 8 and earlier IE versions do not support the @font-face rule.
Property definition and usage
With the @font-face rule, web designers no longer have to use one of the "web-safe" fonts.
The font name, for the font-face rule:
- font-family: myFirstFont;
The font file is included somewhere on your server; refer to the CSS:
- src: url('Sansation_Light.ttf')
If the font file is at a different location, use the full URL:
- src: url('http://www.w3cschool.css/css3/Sansation_Light.ttf')
Now that the font is ready to use, the following is an example of how to use it for all div elements:
div
{
font-family: myFirstFont;
}
Syntax:
The following example uses the font in a div:
div
{
font-family: myFirstFont;
}
Syntax
@font-face
{
font-properties
}
| Font description | Value | Description |
|---|---|---|
| font-family | name | Required. Defines the name of the font. |
| src | URL | Required. Defines the URL where the font can be downloaded. |
| font-stretch | normal |
condensed
ultra-condensed
extra-condensed
semi-condensed
expanded
semi-expanded
extra-expanded
ultra-expanded | 可选。定义该字体应该如何被拉长。默认值是"正常" |
| font-style | normal
italic
oblique | Optional. Defines how the font should be styled. The default value is "normal" | | font-weight | normal
bold
100
200
300
400
500
600
700
800
900 | Optional. Defines the weight of the font. The default value is "normal" | | unicode-range | unicode-range | Optional. Defines the range of Unicode characters supported by the font. The default value is "ü+0-10 FFFF" |
Related Articles
CSS3 tutorial: CSS3 Fonts