Skip to: content, navigation

@font-face

Spec
Version
CSS2, 3
Browser support (more…)
IE5.5+ FF2 Saf3 Op9.5
Partial None None None

Syntax

@font-face {
font descriptors
}

Description

The @font-face at-rule allows you to define custom fonts. It was first defined in the CSS2 specification, but was removed from CSS2.1. Currently, it’s a draft recommendation for CSS3. The at-rule contains one or more property declarations, like those in a regular CSS rule set, which are called font descriptors. You can specify up to 24 different properties, but it’s beyond the scope of this reference to explain them all—you can read about them at the W3C Web Fonts page.

The font descriptors allow you to define fonts, and to influence the browser’s selection of fonts when no matching font is found on the client system. This matching can be performed not only on the font name, but on many other font characteristics as well.

In the simplest usage scenario, @font-face allows you to specify a font-family name, and the URI to a source file for the font, which can be downloaded by the user agent if needed. You can then use the font-family name in other font-family declarations where required.

Example

This at-rule declares the font family called Example Font, which is used in the statement that follows:

@font-face {
  font-family: "Example Font";
  src: url("http://www.example.com
  ➥    /fonts/example");
}
h1 {
  font-family: "Example Font",
  ➥    sans-serif;
}

Compatibility

Internet Explorer Firefox Safari Opera
5.5 6.0 7.0 1.0 1.5 2.0 1.3 2.0 3.0 9.2 9.5
Partial Partial Partial None None None None None None None None

Internet Explorer versions 5.5 and later offer a partial implementation for the browser’s WEFT (Web Embedding Fonts Tool) technology, but this only works with EOT (Embedded OpenType Font) files.

Some experimental support is provided for the @font-face at-rule in nightly builds of WebKit.1

Footnotes

1 Web Kit is used by Safari.

User-contributed notes

ID:
#3
Contributed:
by armchaircritic
Date:
Wed, 18 Feb 2009 15:38:06 GMT

Opera 10 alpha build supports @font-face, and most likely will be supported in the final release of Opera 10 [scheduled for release sometime in 2009]

ID:
#2
Contributed:
by Kevin Yank
Date:
Tue, 29 Jul 2008 05:50:42 GMT

Safari 3.1 has added support for linking to TrueType fonts as per this announcement:

http://webkit.org/blog/124/downloadable-fonts/

Be aware that most font licenses prohibit the distribution of TrueType font files on the Web, so for most commercial fonts (including the fonts provided with your operating system), you would be breaking the terms of the software license that you agreed to by using this feature.

A small selection of “free” fonts are available at various sites on the web. Some of these are available under licenses that allow this kind of font linking.

Add a note

To post a note on this topic, please log in with your SitePoint username and password. If you don't have an account yet, you can create a new account for free.

Related Products

Search