Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

`local()` and `format()` in `@font-face` `src`

Order font sources in `src` and distinguish `local()`, which looks up an installed face, from `format()`, which hints at the format of a URL resource.

Version: Current CSS specifications; browser support varies by feature

Syntax

Common @font-face form with a local source and a URL fallback:
@font-face {
  font-family: "Example Family";
  src: local("Example Regular"), url("example.woff2") format("woff2");
}

src grammar:
<font-src-list> = <font-src>#
<font-src> = <url> [ format(<font-format>) ]? [ tech(<font-tech>#) ]? | local(<font-family-name>)
`#` means one or more comma-separated items; `?` marks an optional part. The formal name `<font-family-name>` in `local()` does not change the lookup: it identifies an individual face, not a whole family.

@font-face makes one font face available to the document. The rule requires two descriptors: font-family gives it the name you use in an element’s font-family property, and src lists where to get the font data. When the browser needs the face, it tries the comma-separated sources from left to right and uses the first one it can activate.

local() looks up a specific installed face, not an entire family. For OpenType and TrueType fonts, use the full face name or its PostScript name. You can list both in separate local() entries because matching varies by platform and font. Browsers may restrict access to local fonts to reduce device fingerprinting.

url() points to a font resource. The optional format() hint goes after url() in the same entry, never after local(). For example, format("woff2") tells the browser to expect WOFF2 so it can skip downloading the resource if it does not support that format. The hint neither converts the file nor guarantees that its data are valid.

If a local face is missing or a source’s data cannot be used, the browser moves on to the next source. If none works, text can use the next family in the font-family property, such as sans-serif. That is a different fallback from the src list. Some browsers may reject the entire src descriptor if one entry has invalid CSS syntax.

Examples

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Font source demo</title>
  <style>
    @font-face {
      font-family: "CKTIS Demo";
      src: local("Arial"),
           local("ArialMT"),
           url("data:font/woff2;base64,AA==") format("woff2");
    }

    body {
      font-family: "CKTIS Demo", sans-serif;
    }
  </style>
</head>
<body>Font source demo</body>
</html>

Result

The page displays “Font source demo”. If the browser can use a matching local Arial face, it renders the text with that face. Otherwise it uses the browser’s sans-serif fallback: the embedded data are deliberately not a valid WOFF2 font. The exact appearance depends on the browser and system.

No external font file is needed. Remove both `local()` entries and their trailing commas to force the `sans-serif` fallback. The `data:` URL deliberately contains invalid WOFF2 data.

Related lessons

  • CSS · Lesson 11 · Intermediate · Version: 2

Sources