@font-face – MDC

@font-face – MDC

@font-face

« CSS « CSS Reference

Introduced in Gecko 1.9.1

(Firefox 3.5 / Thunderbird 3 / SeaMonkey 2)

Summary

@font-face allows authors to specify online fonts to display text on their web pages. By allowing authors to provide their own fonts, @font-face eliminates the need to depend on the limited number of fonts users have installed on their computers.

Syntax

@font-face { font-family: ; src:  [,]*;   [font-weight: ];   [font-style: 

Values

 
Specifies a font name that will be used as font face value for font properties.
 
URL for the remote font file location, or the name of a font on the user’s computer in the form local("Font Name").
 
A font weight value.
A font style value.

You can specify a font on the user’s local computer by name using the local() syntax. If that font isn’t found, other sources will be tried until one is found.

Supported font formats

  • Gecko 1.9.1 (Firefox 3.5) supports TrueType and OpenType fonts.
  • Gecko 1.9.2 (Firefox 3.6) adds support for WOFF.

Examples

This example simply specifies a downloadable font to use, applying it to the entire body of the document.

View live sample

Web Font Sample

This is Bitstream Vera Serif Bold.

In this example, the user’s local copy of “Helvetica Neue Bold” is used; if the user doesn’t have that font installed (two different names are tried), then the downloadable font named “MgOpenModernaBold.ttf” is used instead:

  1. @font-face {   
  2.   font-family: MyHelvetica;   
  3.   srclocal(“Helvetica Neue Bold”),   
  4.   local(“HelveticaNeue-Bold”),   
  5.   url(MgOpenModernaBold.ttf);   
  6.   font-weightbold;   
  7. }  
@font-face { font-family: MyHelvetica; src: local("Helvetica Neue Bold"), local("HelveticaNeue-Bold"), url(MgOpenModernaBold.ttf); font-weight: bold; }

Notes

  • In Gecko, web fonts are subject to the same domain restriction (font files must be on the same domain as the page using them), unless HTTP access controls are used to relax this restriction.
  • Note: Because there are no defined MIME types for TrueType, OpenType, and WOFF fonts, the MIME type of the file specified is not considered.
  • When Gecko displays a page that uses web fonts, it initially displays text using the best CSS fallback font available on the user’s computer while it waits for the web font to finish downloading.  As each web font finishes downloading, Gecko updates the text that uses that font.  This lets the user to read the text on the page more quickly.

Browser compatibility

Browser Lowest version Support of
Internet Explorer 4.0 Embedded OpenType fonts only
Firefox (Gecko) 3.5 (1.9.1) TrueType and OpenType fonts only
3.6 (1.9.2) Web Open Font Format (WOFF)
Opera 10.0 TrueType and OpenType fonts only
Safari (WebKit) 3.1 (525) TrueType and OpenType fonts only

See also MSDN Microsoft library @font-face.

Specifications

Page last modified 17:49, 1 Aug 2010 by Verruckt

Leave a Reply

Leave a Reply