liveBook · Manning

@font-face

As explained in Tiny CSS Projects

@font-face is a CSS at-rule that defines a font resource and its loading and typographic characteristics.

@font-face defines a web font, its source files, its available weights and styles, and its loading behavior. Place each rule at the top of the stylesheet. section 9.4.1 section 9.9

Configure the rule with descriptors that describe the font and its loading:

  • font-family names the font used later by the font-family property. section 9.4.1
  • src lists font locations and formats; the browser tries the sources in order until one loads successfully. section 9.4.1
  • font-weight identifies a file's weight, or gives a range when the file is a variable font. section 9.4.1
  • font-display: swap limits font blocking so content remains available while the font finishes loading. section 9.4.1

Load regular and italic Open Sans

Use a variable WOFF2 file for normal text when multiple weights are needed, but use a smaller static regular file for italic. A separate @font-face rule describes each variation. section 9.4.1

Listing 9.16 Declaring our fonts
@font-face {
  font-family: "Open Sans";                                       #1
  src: url("./fonts/open-sans-variable.woff2")                    #2
       format("woff2-variations");                                #2
  font-style: normal;
  font-weight: 100 800;                                           #3
  font-display: swap;
}
 
@font-face {
  font-family: "Open Sans";                                       #1
  src: local("Open Sans Italic"),                                 #4
       url("./fonts/open-sans-regular.woff2") format("woff2"),    #5
       url("./fonts/open-sans-regular.woff") format("woff");      #6
  font-style: italic;
  font-weight: normal;                                            #7
  font-display: swap;
}

Inspect the complete declarations, including WOFF2 format, a 100–800 variable weight range, a local italic source, and swap loading. section 9.4.1

How Tiny CSS Projects covers it

How deep it goes
Explains four descriptors, source fallback, variable weight ranges, font blocking, and stylesheet placement without deeper font internals.
Examples
Demonstrates normal and italic Open Sans using variable and static files, local lookup, WOFF2 sources, and a variable weight range.
What you can do after
Operate/configure custom web fonts with ordered sources, explicit formats, weight declarations, and non-blocking swap behavior.
How it connects
Connects font loading with font-family, variable fonts, static fonts, WOFF, WOFF2, and font-display.

Also explained in

Compare how 4 books explain @font-face →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Tiny CSS Projects. The section links point to the parts of the book it draws on.