All notes

Web Font Loading Starts with Readability

Budget font coverage, weights and layout changes against the actual reading task.

English edition, edited for length. Read the complete Chinese original.

The title doesn’t appear, and the body text initially displays using the system font, followed by a full page re-formatting a few seconds later. Font loading affects both readability and layout, not just the visual style. The Chinese character set is large, and it’s especially important to demonstrate the value of a custom font before incurring the cost of transferring it.

This text provides an example using a Chinese technical blog. Code blocks typically require monospaced fonts, while the main text requires stable and readable fonts. These two have different character coverage and layout requirements, and should not force the same font file to be used for all content.

Choose a font for reading tasks, not a font based on a brand screenshot

Let’s assume the article discusses database transactions, and the body text contains Chinese, English terms, numbers, and code. The body text font should have a stable baseline and sufficient character coverage, while the code font should clearly distinguish between zeros and letters, quotes, and backticks. The heading font should express hierarchy. Different font families can be used for these tasks, or the system font can be used primarily. A font that looks good in a branding display might not be suitable for reading thousands of words continuously.

First, establish a baseline with no downloads, measuring the readability, line breaks, and control layout of system fonts. Then, incorporate custom resource comparison. If the only differences are minor variations in title formats, you can use a limited set of character resources specifically for titles. The main text does not need to download the entire Chinese family of fonts. Font selection is not about being as customized as possible; stability and readability for the reader are more important. All adjustments should be viewed on pages with rich content, not just a single English name.

First, Establish a Reliable Rollback Mechanism

@font-face {
  font-family: 'Note Sans';
  src: url('/fonts/note-sans.woff2') format('woff2');
  font-display: swap;
  font-weight: 400;
}
body {
  font-family: 'Note Sans', system-ui, sans-serif;
}

swap: This allows the user to initially display a fallback font, and then switch to the preferred font later. However, it does not automatically correct any layout changes caused by the switch. optional: This approach differs from other strategies, and should be tested in situations with slow network speeds and high cache hit rates, rather than assuming that there is a universally optimal value.

The width, line height, and baseline of the font affect the layout. If there is a significant difference between the main font and the fallback font, it’s worth investigating the size-adjust and related metrics, but this should be based on actual font measurements. Setting percentages arbitrarily may improve one device but worsen another.

The initial visit might not have font caching, while subsequent visits might immediately load the fonts. Users on slow networks might never even get the fonts. The font-display property determines how the browser displays the text, but the exact timing is browser-dependent and not a fixed millisecond promise. swap prioritizes displaying text, but allows for subsequent font replacements. optional might reduce late font switching, but brand fonts may not always be displayed. When comparing, record the time when the text becomes visible and whether the replacement changes the reading position.

Adjusting the “retract” measurement requires specific font measurements. While “size-adjust” and other overrides can make the character width and line height more consistent, they cannot guarantee consistency for all characters with a single percentage. Chinese, English, and punctuation may have different variations, and fonts on different operating systems are also not identical. Using a fixed container and appropriate line height can reduce changes in button layout, but the body text still needs to be checked manually. Do not use a single hyphen or absolute positioning to compensate for a single line break for all labels.

When a font fails, the text should not be hidden permanently. All headings, navigation, and body text should retain proper fallback options. If page icons also use fonts, they may also display missing characters. Use reliable icon resources or text alternatives to avoid relying on un-loaded fonts for core buttons. Font resources are an optional visual enhancement and should not determine whether a website is navigable.

Controlling Character Weight and Range

Instead of downloading all font weights, limit yourself to using only the 400 and 600 weights. While variable fonts can combine multiple weights into a single file, the optimal approach depends on the specific resources. Remember that browser-generated bold fonts may not match the visual and readability of the intended font, so don’t rely solely on CSS values.

Proper font family matching also requires correctly declaring font weights and styles. If a single regular file is marked with multiple actual weights, the browser may use an unexpected combination; for variable fonts, it’s important to declare the supported ranges and verify the actual axes. A limited number of resources does not necessarily mean accurate declaration. Inconsistent configuration and file capabilities can make it difficult to understand the appearance of the theme.

The code font should cover common symbols and ensure that characters are easily distinguishable. In technical articles, mathematical symbols, emojis, and other character sets may use different fallback fonts. The test samples should not only contain a single paragraph of pure Chinese title.

While generating resources based only on the characters of the current page can reduce file size, it also makes sharing and maintaining cached content, as well as future content, more complex. Dividing content into Unicode ranges allows browsers to download only what is needed, but this requires covering common punctuation, simplified Chinese, and other actual content. Requesting multiple fragments simultaneously increases the number of requests, and it’s not possible to simply compare the smallest file among them. When new characters are added to a dynamic article, it requires rebuilding and confirming a rollback, which can lead to unexpected formatting issues.

The subset strategy should be tested in conjunction with the publishing pipeline. When adding traditional Chinese characters, mathematical symbols, or long English identifiers, verify that the glyphs exist and that the width does not disrupt the layout. Browsers may choose another font for missing characters, which is a reasonable mechanism, but frequent switching within the same word can reduce consistency. Do not assume that the main font is complete just because the text appears correctly; network and font checks can provide additional verification.

The advantages of variable fonts depend on the specific resources and axes used. If only two static font weights are used, a complete variable font may not necessarily be smaller; however, if multiple weights and width axes are used, the file size may be reduced. When comparing actual download sizes, caching, rendering, and licensing, do not assume that a specific font format automatically provides better performance. Also, when creating bold fonts, it is important to check the details, and the technical text should not sacrifice character recognition in the name of design consistency.

Only preload resources that are truly necessary for the initial screen

Preloading all fonts consumes bandwidth on the initial page load, which can delay image and CSS loading. Choose only the fonts that are actually needed for the initial page and ensure they have the correct font type and cross-origin attributes. Incorrect URLs or duplicate declarations can lead to repeated downloads, so verify the actual behavior in the network panel.

Using third-party font services increases reliance on network and privacy, while self-hosting requires verifying licenses and maintaining updates. Do not re-host commercial fonts without authorization solely for performance reasons. System fonts can be a mature and reliable choice, rather than a temporary solution for unfinished designs.

The URLs, types, and cross-origin attributes specified in the preloaded section must align with the final font request. Otherwise, the font may be downloaded multiple times. When the path in the font declaration differs from the preload target, the browser first downloads the unused old file and then requests the new file. To verify that resources are only downloaded the necessary number of times, examine the actual network timeline. The presence of a preload tag on a page does not indicate a successful outcome. When a page only contains a single character, do not preempt all the bandwidth required for that character.

Third-party services also impact privacy and availability. Each reader requesting a font from the service may transmit network and browser context information. Self-hosting reduces external requests but requires licensing, updates, and cache maintenance. Font files can be used with content versioning and long caching, and CSS references to older versions of resources should follow the font’s lifecycle. Removing an old font while the old CSS is still present on the client will result in a fallback change.

It is also necessary to limit the size and source of font resources. The download process should include timeout and integrity checks. Whether to prevent publishing when remote services are temporarily unavailable should be determined by the visual necessity; most text content should be recoverable, and brand fonts should not be used as a temporary placeholder. The system font scheme should be a mature and readily available option, not a temporary placeholder.

Layout Tokens Ensure Consistent Structure Across Fonts

The combination of font family, font size, line height, and paragraph spacing determines readability. Changing only the family while keeping the other values constant may result in either cramped or sparse text. It’s possible to define specific semantic tokens for text, headings, code, and controls, and evaluate the corresponding task when adjusting the font. These tokens don’t just hide all the sizes in variables; they express which areas need to remain consistent together.

The “simple” and “complex” (ZH/EN) versions within the control often appear misaligned due to differences in baseline. To ensure consistency, use the same line height, stable button sizes, and container alignment. First, check the font settings for each language, and then decide if any minor visual adjustments are needed. Do not apply a specific margin to a screenshot for a particular language; this can cause misalignment again if the loading state changes. The control’s height should accommodate all supported languages and text scaling, and should not be determined solely by the shortest label currently displayed.

The font used for code also needs to consider ligatures and symbols. Some ligatures can aid readability, while others may confuse beginners, leading them to misinterpret characters. If the article explains operators, it should ensure they are clearly distinguishable and can be copied. The font only affects display; the actual text that is copied cannot be changed. Screenshots of code cannot be directly copied, so it is best to provide a text version. The horizontal scrolling and line number layout for code blocks should follow stable rules to avoid line numbers becoming detached after font changes.

For different operating systems, font selection may vary, and testing should not be limited to the author’s machine. Clearly define the supported browsers and device conditions, and observe missing characters, line height, and the longest word. Test samples using real-world text passages and long titles; simply repeating characters does not represent reading quality. Manual observation can identify potential issues, but it is important to note that these observations should not be presented as the preferences of all readers, as this would be based on limited user research.

Finally, incorporate font resources into dependency management. File licenses, source versions, subset scripts, and cache addresses can all be tracked. When updating fonts, verify the size and character coverage. If a design tweak significantly increases resource usage, there should be a clear justification. If the brand visual benefits do not outweigh the costs, reducing font weight, using it locally, or reverting to the system font are all established decisions. A reliable reading experience is more important than enforcing a single font across the entire site.

Comparing Loading Stages Using the Same Technical Text

Select real-world samples containing Chinese characters, SQL identifiers, dates, and long English words, with a fixed container width and layout tokens. Save the fallback font, target font, and loading failure status separately. Compare the number of rows, paragraph height, key control positions, and visible text duration. A more elegant-looking font does not necessarily mean better performance; a more stable layout does not automatically mean easier readability. Each observation corresponds to a specific task, providing a basis for selection.

In the first experiment, only the font-display property was changed. In the second experiment, the font weight and candidate resources were also modified, to avoid the issue of being unable to attribute changes when font size, font, and container were modified simultaneously. The first visit resulted in no caching, and subsequent visits may immediately use the font. Both paths were observed separately. This approach provides a more accurate representation of the long-form reading experience than simply looking at a single layout score, especially when considering the potential for delayed replacement or skipping sections after a slow connection. When conducting user research, it is important to report internal checks and avoid claiming that all users prefer a specific font.

Code sample inspection: 0, O, 1, l, quotes, backticks, and comparison operators. Combining characters does not change the copied text, but may affect readability, especially in articles that explain grammar. Another task is to ensure that table numbers are aligned and easy to compare, which is not automatically guaranteed by using a fixed-width font family. Font selection should be based on actual character and style testing, not on the single line of text displayed on the download page.

The process of subsetting must follow the addition of new content.

If the font only contains characters from the current article, a new article that includes Traditional Chinese characters or mathematical symbols requires the controlled subset to be regenerated. The inventory records the source of the characters, the font version, licensing information, and the generation tool. The missing character check is based on the actual publicly available content. Private drafts should not be included in the public data output solely for the purpose of generating the font in advance, although the character set typically does not contain complete sentences, it should still adhere to a clear input range.

Segmenting by Unicode ranges allows for the reuse of common characters, but overlaps, gaps, and the number of requests need to be verified. When a browser chooses to cover characters, it may download multiple files, and the total cost of the page is not simply the size of the smallest individual file. Testing common Chinese, English, and punctuation mixed paragraphs, checking glyphs and actual requests. Characters that are not covered can use fallback, which is a legitimate mechanism, but may result in unexpected changes within the same term. This requires visual verification.

Different font weights also require consistent character coverage. When the regular font is complete but the headline font is missing characters, the page layout may be inconsistent, and the author may only check the regular font. Variable font declarations support axes and ranges, while static font declarations use true weights. You cannot simply change a filename to “600” and obtain the corresponding font. Upgrades to the generation tool may change the file size and metrics. Instead of just checking the exit status of the build, it is important to compare representative samples.

When Adjusting Metrics, Preserve Operating System Differences

System rollback procedures may vary across different operating systems. The size-adjust method used on the author’s machine may not work on all devices. You can choose a rollback method based on known metrics, but you still need to test its compatibility. The primary adjustment reduces differences in line breaks and height, but it will not ensure complete consistency in all fonts. Chinese punctuation, English width, and numbers will all display differently. Check the widest words and longest titles to avoid breaking the button by changing one sample.

The controls use a consistent height, uniform line height, and container alignment, which reduces layout changes caused by font switching. Avoid using negative margins to individually correct simplified, traditional Chinese, and English text, as the baseline may differ between the main font stage and the revert stage. After text enlargement, the layout must still accommodate labels. A stable size is a responsive constraint, not a fixed content. Normal line breaks are used, code is scrolled independently, and text overflow is not compensated for by shrinking the entire page.

Font preloading requires verifying the actual request identity

The preloaded URL and the font-face source must correspond to the same version and browser acquisition conditions. Incorrect type or cross-domain settings can lead to repeated downloads. After setting the tags, directly check the timeline to confirm reuse. If the initial page only uses standard weights, preloading all title and code fonts will consume key styles and images. Preloading is a priority tool, not a decorative label to indicate the importance of resources.

Font file versioning enables long caching, CSS updates reference new URLs, and older CSS files may still require the older versions. The removal strategy is based on the referenced pages, rather than just the latest build directory. Third-party services have independent availability and privacy dependencies, so confirm the license before self-hosting. The system fonts do not require downloading, and can be used as a viable solution. They cannot be excluded by default due to brand requirements.

How to Avoid Damaging the Article Task When Font Fails

Disable font requests; the main content, navigation, search, and language switching should still be readable and usable. Failure of icon fonts may cause buttons to disappear; prioritize reliable icons or text semantics for core tools. Error loading should not trigger infinite retries; if font enhancement fails, the user should be able to continue using a fallback. Maintaining brand consistency is a visual goal, while reading content is a fundamental task. The failure strategy should reflect this priority.

For pages that require specific text to be displayed, font coverage issues should be clearly documented in the build or acceptance report, rather than relying on hiding characters to fix the problem. Alternative text, assistive technology, and copying content should still maintain the original string. Converting text to images only addresses the visual appearance, sacrificing search, copy, and scaling functionality. This should not be a general fallback for font failures.

Font resources may also be rejected due to incorrect media types or cross-origin issues. The “blocked request” mechanism should differentiate between failed requests, download failures, and font parsing failures, rather than simply reverting to a font and declaring the file not loaded. Controlled previews should verify the actual request headers and resource formats, and fix deployment types instead of removing meaningful security policies. The fallback mechanism should ensure readability, while the diagnostic mechanism should provide clear reasons for failures that enhance the brand.

Documenting Selection Outcomes as a Finite Layout Agreement

The text records information about each family of fonts, including their weights, fallback options, loading strategies, and measurement conditions. It also specifies the reasons for rejecting a full family download or the most complex scheme. Subsequent design adjustments are made by first checking the impact on the contract, and then deciding whether to add resources. A limited and traceable selection is more stable than replacing the entire site every time a new font is encountered. The primary goal of font loading is for readers to first see the text, and then to enhance it without disrupting the existing layout. Even if the enhancement fails, the task should still be completed.

Check the entire article, not just the homepage

Long titles, dates with numbers, mixed-style and code blocks can all reveal font issues. On mobile devices, check the longest words, button labels, and navigation. On desktop devices, observe the length of reading lines and paragraph density. When font loading fails, the main text must still be readable; it should not display blank spaces due to unavailable brand resources.

Test the initial loading with a slow network and disabled caching, then test revisiting with existing cached data. Record the font download size and the layout changes after loading, and compare different strategies. Instead of claiming that a specific font will always improve performance, focus on the actual results. If the benefits are only minor visual changes but come with significant costs, consider removing the font or using it only for a small number of headings.

Here’s another scenario different from screen reading: the reader prints or saves the article as a PDF. The print style might change the font size, hide navigation, and expand code snippets. Screenshots don’t necessarily represent the complete paper version. When viewing a PDF containing Chinese text, formulas, and SQL, check for missing characters, headings at the page breaks, and excessively long code snippets. Document the testing environment, and avoid promoting the export behavior of a specific browser as a guarantee for all readers.

When printing, do not rely on horizontal scrolling to view and discard code. Instead, choose to allow line breaks, adjust the layout for printing, or provide separate source code entries, and verify that all information is present using a single-line query. If different fonts are used for pagination, re-check character spacing and indentation, rather than treating the screen font configuration as a binding agreement for printed output. Navigation buttons on the screen do not need to appear in the printed document, but the article’s identity and source address should be retained.

The exported file also requires a test: copy a section of Chinese text and code from a PDF, and compare it to the original characters rather than just looking at the appearance. Correct font does not automatically prove that the text extraction is correct; if the export tool changes the characters or order, use the original web text as a reliable source and explain the limitations. This check does not require the website to guarantee the behavior of all PDF tools, but only requires a clearly defined and verified export path and an unverified boundary.

References: font-display, Best Practices for Fonts.