排版印刷

Web Fonts

Fonts downloaded by the browser to render text, declared via CSS @font-face. WOFF2 is the standard format. Unicode subsetting and unicode-range enable efficient loading of multilingual fonts.

What is a Web Font?

A web font is a font file loaded over HTTP/HTTPS and applied to text in a web page, rather than relying on fonts installed on the user's operating system. The @font-face CSS rule enables web fonts, and the WOFF2 format (Web Open Font Format 2) is the standard delivery format used on the modern web.

Web fonts allow designers to use consistent, brand-specific typography across all devices and operating systems, solving the long-standing limitation of relying on a small set of universally-installed "web-safe" fonts.

WOFF2: The Standard Web Font Format

WOFF2, defined in the W3C specification, is a compressed container format for OpenType fonts. It uses Brotli compression (replacing the zlib used in WOFF1), achieving approximately 30% better compression than WOFF1 and typically 50–70% smaller than the raw OTF/TTF file.

@font-face {
  font-family: "Inter";
  font-weight: 100 900;   /* Variable font weight range */
  font-style: normal;
  font-display: swap;     /* Show fallback immediately, swap when loaded */
  src:
    url("/fonts/inter-var.woff2") format("woff2"),
    url("/fonts/inter-var.ttf")   format("truetype");  /* Fallback */
  unicode-range: U+0000-00FF, U+0131, U+0152-0153;
}

font-display: Controlling Loading Behavior

The font-display descriptor controls the tradeoff between showing unstyled text immediately (FOUT — Flash of Unstyled Text) and waiting for the font (FOIT — Flash of Invisible Text):

Value Behavior
auto Browser default (usually block)
block Hide text briefly, then show with web font
swap Show fallback immediately, swap to web font when loaded
fallback Short block period (100ms), then fallback, swap only if fast
optional Browser decides; may not load on slow connections

font-display: swap is recommended for body text; optional is recommended for decorative fonts.

CJK Web Font Challenges

CJK (Chinese, Japanese, Korean) web fonts present unique challenges:

  • A full CJK font covering all unified ideographs contains 65,000–100,000 glyphs and weighs 5–30 MB
  • Even a practical subset of "common" Chinese characters (3,500 characters) produces a font of 1–3 MB
  • Loading a 3 MB font on a mobile connection causes significant page weight issues

Strategies for CJK web fonts:

  1. Unicode-range subsetting: Serve only the characters actually used (see unicode-range CSS descriptor)
  2. On-demand subsetting: Services like Google Fonts and Adobe Fonts generate per-page subsets
  3. Dynamic subsetting APIs: Font subsetting APIs accept a list of characters and return a minimal font file containing only those glyphs
  4. System fonts: Fall back to the platform's CJK system font for body text, using web fonts only for headings
# Python font subsetting with fonttools
from fontTools.subset import Subsetter, Options

options = Options()
subsetter = Subsetter(options=options)
subsetter.populate(text="常用漢字テキスト")
# Produces a font with only the required glyphs

Variable Fonts on the Web

Variable fonts (OpenType 1.8+) are increasingly used on the web because a single variable font file replaces multiple separate weight/style files:

  • Traditional: 8 files (thin, light, regular, medium, semibold, bold, extrabold, black)
  • Variable: 1 file with continuous weight axis from 100–900

For Latin scripts, a variable WOFF2 is typically 80–150 KB — smaller than two traditional static weight files combined.

Quick Facts

Property Value
Standard format WOFF2 (W3C spec, Brotli compression)
Compression ~30% better than WOFF1, ~50% smaller than OTF
CSS declaration @font-face rule
Loading behavior Controlled by font-display descriptor
CJK font size 5–30 MB full; 100–500 KB subsetted
Variable fonts Single file replaces 4–8 static weight files
Subsetting tool fonttools Python library

相关术语

排版印刷 中的更多内容

CSS unicode-range

CSS @font-face descriptor specifying which Unicode code points a font should cover. …

Font Fallback

The mechanism by which a rendering engine substitutes glyphs from a secondary …

OpenType

Modern font format developed by Microsoft and Adobe supporting up to 65,535 …

RTL(从右到左)

字符从右向左流动的文本方向,用于阿拉伯语、希伯来语、塔阿纳等文字,正确显示需要双向算法。

不换行空格

U+00A0,防止在该位置换行的空格。HTML中为 ,用于数字与单位之间(100 km)、专有名词(Mr. Smith)和缩写之后。

全角 / 半角(排版单位)

全角(Em):等于字号的宽度;半角(En):全角的一半,用于定义全角破折号宽度、全角空格、半角空格和CSS单位(1em、0.5em)。

变音符号 / 附加符号

附加在字母上以改变发音或意义的符号,可以是预组合形式(é U+00E9)或组合形式(e + ◌́ U+0065+U+0301),包括重音、变音符、软音符和波浪号等。

字体

特定大小、字重和样式的字型实现,在数字排版中指包含字形定义和度量的字体文件(TTF、OTF、WOFF2)。

字形

字体渲染的字符视觉表现形式。一个字符可有多个字形(连字、上下文形式),一个字形也可表示多个字符。

字距调整

为视觉美观而调整特定字符对(如AV、To、LT)之间间距的操作,是字体特性而非Unicode概念,但会影响Unicode文本的渲染。