mozilla

Revision 19386 of @font-face

  • Revision slug: CSS/@font-face
  • Revision title: @font-face
  • Revision id: 19386
  • Created:
  • Creator: sloppy_4455
  • Is current revision? No
  • Comment no wording changes

Revision Content

{{ CSSRef() }}{{ gecko_minversion_header("1.9.1") }}

Summary

@font-face allows authors to specify online fonts to display text on their webpages. 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: <a-remote-font-name>;
  src: <source> [,<source>]*;
  [font-weight: <weight>];
  [font-style: <style>];
}

Values

<a-remote-font-name> 
Specifies a font name that will be used as font face value for font properties.
<source> 
URL for the remote font file location, or the name of a font on the user's computer in the form local("Font Name").
<weight> 
A font weight value.
<style> 
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.

About WOFF

WOFF (Web Open Font Format) is a new web font format developed by Mozilla in concert with Type Supply, LettError, and other organizations. It uses a compressed version of the same table-based sfnt structure used by TrueType, OpenType, and Open Font Format, but adds metadata and private-use data structures, including predefined fields allowing foundries and vendors to provide license information if desired.

There are three main benefits to using WOFF:

  1. The font data is compressed, so sites using WOFF will use less bandwidth and will load faster than if they used equivalent uncompressed TrueType or OpenType files.
  2. Many font vendors that are unwilling to license their TrueType or OpenType format fonts for use on the web will license WOFF format fonts. This improves availability of fonts to site designers.
  3. Both proprietary and free-software browser vendors like the WOFF format, so it has the potential of becoming a truly universal, interoperable font format for the web, unlike other current font formats.

Examples

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

View live sample

<html>
<head>
  <title>Web Font Sample</title>
  <style type="text/css" media="screen, print">
    @font-face {
      font-family: "Bitstream Vera Serif Bold";
      src: url("http://developer.mozilla.org/@api/deki/files/2934/=VeraSeBd.ttf");
    }
    
    body { font-family: "Bitstream Vera Serif Bold", serif }
  </style>
</head>
<body>
  This is Bitstream Vera Serif Bold.
</body>
</html>

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:

@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

See also

{{ languages( { "fr": "fr/CSS/@font-face", "ja": "ja/CSS/@font-face" } ) }}

Revision Source

<p>{{ CSSRef() }}{{ gecko_minversion_header("1.9.1") }}</p>
<h3>Summary</h3>
<p><code>@font-face </code>allows authors to specify online fonts to display text on their webpages. By allowing authors to provide their own fonts,<code> @font-face </code>eliminates the need to depend on the limited number of fonts users have installed on their computers.</p>
<h3>Syntax</h3>
<pre>@font-face {
  font-family: &lt;a-remote-font-name&gt;;
  src: &lt;source&gt; [,&lt;source&gt;]*;
  [font-weight: &lt;weight&gt;];
  [font-style: &lt;style&gt;];
}
</pre><h3>Values</h3>
<dl> <dt>&lt;a-remote-font-name&gt; </dt> <dd>Specifies a font name that will be used as font face value for font properties.</dd> <dt>&lt;source&gt; </dt> <dd>URL for the remote font file location, or the name of a font on the user's computer in the form <code>local("Font Name")</code>.</dd> <dt>&lt;weight&gt; </dt> <dd>A <a class="internal" href="/en/CSS/font-weight" title="en/CSS/font-weight">font weight</a> value.</dd> <dt>&lt;style&gt; </dt> <dd>A <a class="internal" href="/en/CSS/font-style" title="en/CSS/font-style">font style</a> value.</dd>
</dl>
<p>You can specify a font on the user's local computer by name using the <code>local()</code> syntax. If that font isn't found, other sources will be tried until one is found.</p><h3>Supported font formats</h3>
<ul> <li>Gecko 1.9.1 (Firefox 3.5) supports TrueType and OpenType fonts.</li> <li>Gecko 1.9.2 (Firefox 3.6) adds support for <a class=" external" href="http://people.mozilla.com/~jkew/woff/woff-2009-09-16.html" title="http://people.mozilla.com/~jkew/woff/woff-2009-09-16.html">WOFF</a>.</li>
</ul>
<h4>About WOFF</h4>
<p>WOFF (Web Open Font Format) is a new web font format developed by Mozilla in concert with Type Supply, LettError, and other organizations. It uses a compressed version of the same table-based sfnt structure used by TrueType, OpenType, and Open Font Format, but adds metadata and private-use data structures, including predefined fields allowing foundries and vendors to provide license information if desired.</p>
<p>There are three main benefits to using WOFF:</p>
<ol> <li>The font data is compressed, so sites using WOFF will use less bandwidth and will load faster than if they used equivalent uncompressed TrueType or OpenType files.</li> <li>Many font vendors that are unwilling to license their TrueType or OpenType format fonts for use on the web will license WOFF format fonts. This improves availability of fonts to site designers.</li> <li>Both proprietary and free-software browser vendors like the WOFF format, so it has the potential of becoming a truly universal, interoperable font format for the web, unlike other current font formats.</li>
</ol>
<h3>Examples</h3>
<p>This example simply specifies a downloadable font to use, applying it to the entire body of the document.</p>
<p><a class="internal" href="/@api/deki/files/2935/=webfont-sample.html" title="/@api/deki/files/2935/=webfont-sample.html">View live sample</a></p>
<pre>&lt;html&gt;
&lt;head&gt;
  &lt;title&gt;Web Font Sample&lt;/title&gt;
  &lt;style type="text/css" media="screen, print"&gt;
    @font-face {
      font-family: "Bitstream Vera Serif Bold";
      src: url("http://developer.mozilla.org/@api/deki/files/2934/=VeraSeBd.ttf");
    }
    
    body { font-family: "Bitstream Vera Serif Bold", serif }
  &lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
  This is Bitstream Vera Serif Bold.
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>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:</p>
<pre class="brush: css">@font-face {
  font-family: MyHelvetica;
  src: local("Helvetica Neue Bold"),
  local("HelveticaNeue-Bold"),
  url(MgOpenModernaBold.ttf);
  font-weight: bold;
}
</pre>
<h3>Notes</h3>
<ul> <li>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 <a class="internal" href="/En/HTTP_access_control" title="En/HTTP access control">HTTP access controls</a> are used to relax this restriction.</li> <li> <div class="note"><strong>Note:</strong> Because there are no defined MIME types for TrueType, OpenType, and WOFF fonts, the MIME type of the file specified is not considered.</div> </li> <li>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.</li>
</ul>
<h3>Browser compatibility</h3>
<table class="standard-table"> <tbody> <tr> <th>Browser</th> <th>Lowest version</th> <th>Support of</th> </tr> <tr> <td>Internet Explorer</td> <td><strong>4.0</strong></td> <td>Embedded OpenType fonts only</td> </tr> <tr> <td rowspan="2">Firefox (Gecko)</td> <td><strong>3.5</strong> (1.9.1)</td> <td>TrueType and OpenType fonts only</td> </tr> <tr> <td><strong>3.6</strong> (1.9.2)</td> <td>Web Open Font Format (WOFF)</td> </tr> <tr> <td>Opera</td> <td><strong>10.0</strong></td> <td>TrueType and OpenType fonts only</td> </tr> <tr> <td>Safari (WebKit)</td> <td><strong>3.1</strong> (525)</td> <td>TrueType and OpenType fonts only</td> </tr> </tbody>
</table>
<p>See also <a class="external" href="http://msdn.microsoft.com/en-us/library/ms530757(VS.85).aspx" title="http://msdn.microsoft.com/en-us/library/ms530757(VS.85).aspx">MSDN Microsoft library @font-face</a>.</p>
<h3>Specifications</h3>
<ul> <li><a class="external" href="http://www.w3.org/TR/1998/REC-CSS2-19980512/fonts.html#font-descriptions" title="http://www.w3.org/TR/1998/REC-CSS2-19980512/fonts.html#font-descriptions">CSS 2 Fonts</a> 1998-05-12 Obsolete</li> <li><a class="external" href="http://www.w3.org/TR/css3-fonts/#font-resources" title="http://www.w3.org/TR/css3-fonts/#font-resources">CSS 3 Fonts</a> 2009 Working draft</li> <li><a class=" external" href="http://people.mozilla.com/~jkew/woff/woff-2009-09-16.html" title="http://people.mozilla.com/~jkew/woff/woff-2009-09-16.html">WOFF file format specification</a> Draft</li>
</ul>
<h3>See also</h3>
<ul> <li>{{ CSS_Reference:Fonts() }}</li> <li><a class="external" href="http://hacks.mozilla.org/2009/06/beautiful-fonts-with-font-face/" title="http://hacks.mozilla.org/2009/06/beautiful-fonts-with-font-face/">Beautiful fonts with @font-face</a></li> <li><a class="external" href="http://openfontlibrary.org/" title="http://openfontlibrary.org/">Open Font Library</a></li> <li><a class="external" href="http://opentype.info/demo/webfontdemo.html" title="http://opentype.info/demo/webfontdemo.html">10 Great Free Fonts for @font-face embedding</a></li>
</ul>
<p>{{ languages( { "fr": "fr/CSS/@font-face", "ja": "ja/CSS/@font-face" } ) }}</p>
Revert to this revision