Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

`format()` in the `@font-face` `src` descriptor

`format()` tells the browser what format to expect from one font source, so it can skip an unsupported source without downloading it.

Version: Current CSS specifications; browser support varies by feature

Syntax

src: <font-src-list>;
<font-src-list> = <font-src>#
<font-src> = <url> [ format( <font-format> ) ]? [ tech( <font-tech># ) ]? | local( <font-family-name> )
<font-format> = <string> | collection | embedded-opentype | opentype | svg | truetype | woff | woff2

? marks an optional component; # means one or more comma-separated values. These are CSS grammar markers, not characters to type in a declaration.

@font-face defines one font face. Its font-family descriptor names the family, and its required src descriptor lists sources in preference order, separated by commas. The font-family property in an element rule, not src, asks to use that family.

Put the optional format() immediately after url(). It applies only to that source, not to the whole list or to a local() entry. format(woff2) uses a keyword; format("woff2") is the equivalent form retained for backward compatibility. The hint neither converts the file nor verifies its contents. tech() is a separate hint about font technology, not the file format.

When the face is needed, the browser skips sources whose hint names an unknown or unsupported format and uses the first source it can load successfully. Without a hint, it can try loading the resource and detect the format from the data. If a source is missing or the data is invalid, the browser can move on to the next source. If none works, font matching can move on to the next family in the font-family property. That is a separate fallback from the src list. Browser support for formats and syntax varies.

Examples

<!doctype html>
<meta charset="utf-8">
<title>Font format demo</title>
<style>
  @font-face {
    font-family: "CktisFormatDemo";
    src: url("data:application/octet-stream,first") format("cktis-unknown"),
         url("data:application/octet-stream,");
  }

  body {
    font-family: "CktisFormatDemo", monospace;
  }
</style>
<body>Font format demo</body>

Result

Font format demo — rendered in the browser's generic monospace fallback. The first source is skipped because its format hint is unknown. The second has no hint and fails because it contains no font data. Neither source requires an external file.

The browser skips the first `data:` URL because its format hint is unknown. It tries the second URL, which has no `format()` hint, but the empty resource supplies no font data. The text `Font format demo` therefore uses the generic `monospace` fallback.

Related lessons

  • CSS · Lesson 12 · Intermediate · Version: 2
  • CSS · Lesson 47 · Intermediate · Version: 2

Sources