W3Schools.com

CSS Reference

CSS Reference
CSS Selectors
CSS Reference Aural
CSS Web Safe Fonts
CSS Units
CSS Colors
CSS Color Values
CSS Color Names
CSS Color HEX
CSS3 Browser Support

CSS Properties

CSS3 @font-face Rule

CSS Reference Complete CSS Reference

Example

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

@font-face
{
font-family: myFirstFont;
src: url('Sansation_Light.ttf'),
     url('Sansation_Light.eot'); /* IE */
}

Try it yourself »

Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The @font-face rule is supported in all major browsers.

Internet Explorer only supports .eot type fonts.

Firefox, Chrome, Safari, and Opera support .ttf and .otf type fonts.


Definition and Usage

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

Make a font-face rule by giving the font a name:

  • font-family: myFirstFont;

Include a font file somewhere on your server, and refer to it with CSS:

  • src: url('Sansation_Light.ttf')

If the font file is located at a different domain, use a full URL instead:

  • src: url('http://www.w3schools.com/css3/Sansation_Light.ttf').

Now the font is ready to use, below is an example of how to use it for all div elements:

div
{
font-family: myFirstFont;
}


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"


Related Pages

CSS3 tutorial: CSS3 Fonts


CSS Reference Complete CSS Reference

W3Schools Certification

W3Schools' Online Certification

The perfect solution for professionals who need to balance work, family, and career building.

More than 10 000 certificates already issued!

Get Your Certificate »

The HTML Certificate documents your knowledge of HTML.

The CSS Certificate documents your knowledge of advanced CSS.

The JavaScript Certificate documents your knowledge of JavaScript and HTML DOM.

The jQuery Certificate documents your knowledge of jQuery.

The XML Certificate documents your knowledge of XML, XML DOM and XSLT.

The ASP Certificate documents your knowledge of ASP, SQL, and ADO.

The PHP Certificate documents your knowledge of PHP and SQL (MySQL).

WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Best Hosting Coupons
UK Reseller Hosting
Cloud Hosting
Top Web Hosting
$3.98 Unlimited Hosting
Premium Website Design
WEB BUILDING
Download XML Editor
FREE Website BUILDER
Free Website Templates Free CSS Templates
Make Your Own Website
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE