Table of contents
- 1. Summary
- 2. Syntax
- 2.1. Values
- 3. Examples
- 4. Notes
- 5. Browser compatibility
- 5.1. Notes
- 6. Specifications
- 7. See also
Summary
The @font-face CSS at-rule 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. The @font-face at-rule may be used not only at the top level of a CSS, but also inside any CSS conditional-group at-rule.
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.
Examples
This example simply specifies a downloadable font to use, applying it to the entire body of the document.
<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:
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 allows the user to read the text on the page more quickly.
Browser compatibility
| Feature | Firefox (Gecko) | Chrome | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Basic support | 3.5 (1.9.1) | 4.0 | 4.0 | 10.0 | 3.1 |
| WOFF | 3.5 (1.9.1) | 6.0 | 9.0 | 11.10 | 5.1 |
| SVG Font | -- Unimplemented (see bug 119490 ) | yes | -- | yes | yes |
| Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mini | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| Basic support | (Yes) | 1.0 (1.9.1) | ? | -- | 10.0 | (Yes) |
| WOFF | -- | 5.0 (5.0) | ? | -- | 11.0 | -- |
| SVG fonts | -- | -- Unimplemented (see bug 119490 ) | ? | -- | 10.0 | (Yes) |
Notes
- Support of the Embedded OpenType font format is not included in the compatibility table because it is a proprietary feature. Prior to IE 9.0, IE supported only this format.
- TrueType and OpenType are not included because they are superseded by WOFF.
Specifications
- CSS 2 Fonts 1998-05-12 Obsolete
- CSS Fonts Module Level 3 2011 Working draft
- WOFF File Format 1.0 2011 Candidate Recommendation
See also
- CSS Reference
- CSS at-rules: @charset, @font-face, @import, @keyframes, @media, @page.
-
font,font-family,font-size,font-size-adjust,font-stretch,font-style,font-variant,font-weight,@font-face - FontSquirrel @font-face generator
- About WOFF
- Beautiful fonts with @font-face
- Open Font Library
- MSDN Microsoft library @font-face
- When can I use WOFF?When can I use SVG Fonts?
Mozilla Developer Network