The @font-face CSS at-rule specifies a custom font with which to display text; the font can be loaded from either a remote server or the user's own computer. If the local() function is provided, specifying a font name to look for on the user's computer, and the user agent finds a match, that local font is used. Otherwise, the font resource specified using the url() function is downloaded and used.

By allowing authors to provide their own fonts, @font-face makes it possible to design content without being limited to the so-called "safe" fonts (that is, the fonts which are so common that they're considered to be universally available). The ability to specify the name of a locally-installed font to look for and use makes it possible to customize the font beyond the basics while making it possible to do so without relying on an Internet connection.

It's common to use both url() and local() together, so that the user's installed copy of the font is used if available, falling back to downloading a copy of the font if it's not found on the user's device.

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.

@font-face {
  font-family: "Open Sans";
  src: url("/fonts/OpenSans-Regular-webfont.woff2") format("woff2"),
       url("/fonts/OpenSans-Regular-webfont.woff") format("woff");
}

Syntax

Descriptors

font-display
Determines how a font face is displayed based on whether and when it is downloaded and ready to use.
font-family
Specifies a name that will be used as the font face value for font properties.
font-stretch
A font-stretch value. Since Firefox 61 (and in other modern browsers) this also accepts two values to specify a range that is supported by a font-face, for example font-stretch: 50% 200%;
font-style
A font-style value. Since Firefox 61 (and in other modern browsers) this also accepts two values to specify a range that is supported by a font-face, for example font-style: oblique 20deg 50deg;
font-weight
A font-weight value. Since Firefox 61 (and in other modern browsers) this also accepts two values to specify a range that is supported by a font-face, for example font-weight: 100 400;
font-variant
A font-variant value.
font-feature-settings
Allows control over advanced typographic features in OpenType fonts.
font-variation-settings
Allows low-level control over OpenType or TrueType font variations, by specifying the four letter axis names of the features to vary, along with their variation values.
src

Specifies the resource containing the font data. This can be a URL to a remote font file location or the name of a font on the user's computer.

To provide the browser with a hint as to what format a font resource is — so it can select a suitable one — it is possible to include a format type inside a format() function:

src: url(ideal-sans-serif.woff) format("woff"),
     url(basic-sans-serif.ttf) format("opentype");

The available types are: "woff", "woff2", "truetype", "opentype", "embedded-opentype", and "svg".

unicode-range
The range of Unicode code points to be used from the font.

Formal syntax

@font-face {
  [ font-family: <family-name>; ] ||
  [ src: <src>; ] ||
  [ unicode-range: <unicode-range>; ] ||
  [ font-variant: <font-variant>; ] ||
  [ font-feature-settings: <font-feature-settings>; ] ||
  [ font-variation-settings: <font-variation-settings>; ] ||
  [ font-stretch: <font-stretch>; ] ||
  [ font-weight: <font-weight>; ] ||
  [ font-style: <font-style>; ]
}

where
<family-name> = <string> | <custom-ident>+

Examples

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

View the live example

<html>
<head>
  <title>Web Font Sample</title>
  <style type="text/css" media="screen, print">
    @font-face {
      font-family: "Bitstream Vera Serif Bold";
      src: url("https://mdn.mozillademos.org/files/2468/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 does not 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;
}

Font MIME Types

Format MIME type
TrueType font/ttf
OpenType font/otf
Web Open File Format font/woff
Web Open File Format 2 font/woff2

Notes

  • 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.
  • @font-face cannot be declared within a CSS selector. For example, the following will not work:
    .className { 
      @font-face { 
        font-family: MyHelvetica; 
        src: local("Helvetica Neue Bold"),
             local("HelveticaNeue-Bold"),
             url(MgOpenModernaBold.ttf);
        font-weight: bold; 
      } 
    }

Specifications

Specification Status Comment
WOFF File Format 2.0
The definition of 'WOFF2 font format' in that specification.
Recommendation Font format specification with new compression algorithm
WOFF File Format 1.0
The definition of 'WOFF font format' in that specification.
Recommendation Font format specification
CSS Fonts Module Level 3
The definition of '@font-face' in that specification.
Candidate Recommendation Initial definition

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
Basic supportChrome Full support 4Edge Full support 12Firefox Full support 3.5IE Full support 4Opera Full support 10Safari Full support 3.1WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support 12Firefox Android Full support 4Opera Android Full support 10Safari iOS Full support YesSamsung Internet Android Full support Yes
WOFFChrome Full support 6Edge Full support YesFirefox Full support 3.5IE Full support 9Opera Full support 11.1Safari Full support 5.1WebView Android Full support 4.4Chrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support 11Safari iOS Full support 5Samsung Internet Android Full support Yes
WOFF 2Chrome Full support 36Edge Full support 14Firefox Full support 39
Full support 39
Full support 35
Disabled
Disabled From version 35: this feature is behind the gfx.downloadable_fonts.woff2.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
IE No support NoOpera Full support 23Safari Full support 10
Notes
Full support 10
Notes
Notes Supported only on macOS 10.12 (Sierra) and later.
WebView Android Full support 37Chrome Android Full support 36Edge Mobile Full support 14Firefox Android Full support 39
Full support 39
Full support 35
Disabled
Disabled From version 35: this feature is behind the gfx.downloadable_fonts.woff2.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
Opera Android Full support 23Safari iOS Full support 10Samsung Internet Android Full support 3.0
SVG fonts
DeprecatedNon-standard
Chrome No support NoEdge No support NoFirefox No support NoIE No support NoOpera No support NoSafari Full support YesWebView Android No support NoChrome Android No support NoEdge Mobile No support NoFirefox Android No support NoOpera Android No support NoSafari iOS Full support YesSamsung Internet Android No support No
font-displayChrome Full support 60Edge No support NoFirefox Full support 58IE No support NoOpera Full support 47Safari Full support YesWebView Android Full support 60Chrome Android Full support 60Edge Mobile No support NoFirefox Android Full support 58Opera Android Full support 47Safari iOS Full support YesSamsung Internet Android No support No
font-familyChrome Full support 4Edge Full support 12Firefox Full support 3.5IE Full support 6Opera Full support 9Safari Full support 3.1WebView Android Full support 2.2Chrome Android ? Edge Mobile Full support 12Firefox Android Full support 4Opera Android Full support 12Safari iOS Full support 3.1Samsung Internet Android Full support Yes
font-feature-settingsChrome No support NoEdge No support NoFirefox Full support 34
Notes
Full support 34
Notes
Notes The ISO/IEC CD 14496-22 3rd edition suggests using the ssty feature to provide glyph variants more suitable for use in scripts (for example primes used as superscripts). Starting with Firefox 29, this is done automatically by the MathML rendering engine. The ISO/IEC CD 14496-22 3rd edition also suggests applying the dtls feature to letters when placing mathematical accents to get dotless forms (for example dotless i, j with a hat). Starting with Firefox 35, this is done automatically by the MathML rendering engine. You can override the default values determined by the MathML rendering engine with CSS.
Full support 15
Prefixed Notes
Prefixed Implemented with the vendor prefix: -moz-
Notes From Firefox 4 to Firefox 14 (inclusive), Firefox supported an older, slightly different syntax. See OpenType Font Feature support in Firefox 4.
IE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoEdge Mobile No support NoFirefox Android Full support 34
Notes
Full support 34
Notes
Notes The ISO/IEC CD 14496-22 3rd edition suggests using the ssty feature to provide glyph variants more suitable for use in scripts (for example primes used as superscripts). Starting with Firefox 29, this is done automatically by the MathML rendering engine. The ISO/IEC CD 14496-22 3rd edition also suggests applying the dtls feature to letters when placing mathematical accents to get dotless forms (for example dotless i, j with a hat). Starting with Firefox 35, this is done automatically by the MathML rendering engine. You can override the default values determined by the MathML rendering engine with CSS.
Full support 15
Prefixed Notes
Prefixed Implemented with the vendor prefix: -moz-
Notes From Firefox 4 to Firefox 14 (inclusive), Firefox supported an older, slightly different syntax. See OpenType Font Feature support in Firefox 4.
Opera Android No support NoSafari iOS No support NoSamsung Internet Android No support No
font-variation-settingsChrome Full support 62Edge No support NoFirefox Full support 60
Disabled
Full support 60
Disabled
Disabled From version 60: this feature is behind the layout.css.font-variations.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
IE No support NoOpera Full support 49Safari No support NoWebView Android Full support 62Chrome Android Full support 62Edge Mobile No support NoFirefox Android Full support 60
Disabled
Full support 60
Disabled
Disabled From version 60: this feature is behind the layout.css.font-variations.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
Opera Android Full support YesSafari iOS No support NoSamsung Internet Android No support No
font-styleChrome Full support 4Edge ? Firefox Full support 3.5IE Full support 4Opera Full support 10Safari Full support 3.1WebView Android Full support YesChrome Android ? Edge Mobile ? Firefox Android Full support 4Opera Android Full support 10Safari iOS Full support YesSamsung Internet Android Full support Yes
font-weightChrome Full support 4Edge Full support 12Firefox Full support 3.5IE Full support 4Opera Full support 10Safari Full support 3.1WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support 12Firefox Android Full support 4Opera Android Full support 10Safari iOS Full support YesSamsung Internet Android Full support Yes
srcChrome Full support 4Edge Full support 12Firefox Full support 3.5IE Full support 6Opera Full support 9Safari Full support 3.1WebView Android Full support 2.2Chrome Android ? Edge Mobile Full support 12Firefox Android Full support 4Opera Android Full support 12Safari iOS Full support 3.1Samsung Internet Android Full support Yes
unicode-rangeChrome Full support YesEdge Full support YesFirefox Full support 36IE Full support 9Opera Full support YesSafari Full support YesWebView Android ? Chrome Android ? Edge Mobile Full support YesFirefox Android Full support 36Opera Android ? Safari iOS Full support YesSamsung Internet Android Full support Yes

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Non-standard. Expect poor cross-browser support.
Non-standard. Expect poor cross-browser support.
Deprecated. Not for use in new websites.
Deprecated. Not for use in new websites.
See implementation notes.
See implementation notes.
User must explicitly enable this feature.
User must explicitly enable this feature.
Requires a vendor prefix or different name for use.
Requires a vendor prefix or different name for use.

See also