Skip to content
AnswerWell geo Documentation

Research · 8 min read · Answerwell

Web Font Origin Delivery, font-display Loading, and CSS text-wrap

How to serve web fonts from your own origin, keep text visible while fonts load, reduce layout shift, and use text-wrap for headings and body copy.

This page brings together Cloudflare Fonts guidance on serving Google Fonts from your own origin with Chrome for Developers and Modern Web Guidance material on font-display, stable fallbacks, and CSS text-wrap properties. Together these address the usual goals: fewer third-party font requests, text that stays readable during load, less Cumulative Layout Shift (CLS), and sharper typography in headings and paragraphs.

Cloudflare Fonts: Google Fonts from your own origin

Section titled “Cloudflare Fonts: Google Fonts from your own origin”

Cloudflare Fonts is for sites that load fonts through Google Fonts. It rewrites those references so files are delivered from your zone instead of Google’s servers, without self-hosting font files or changing application code.

Cloudflare Fonts is a feature designed for websites that use Google Fonts. It rewrites Google Fonts to be delivered from a website’s own origin, eliminating the need to rely on third-party font providers. Cloudflare Fonts is tailored to improve website performance and user privacy without the need for any code changes or self-hosting of fonts.

— Cloudflare, Cloudflare Fonts

How Cloudflare Fonts rewrites HTML and where requests go

Section titled “How Cloudflare Fonts rewrites HTML and where requests go”

The feature edits response HTML: it removes Google Fonts <link> tags and injects inline CSS that points font files at your Cloudflare zone.

Cloudflare Fonts works by rewriting your webpage’s HTML. It removes Google Fonts links and replaces them with inline CSS. This CSS includes links to fonts from your own Cloudflare zone rather than from Google servers.

— Cloudflare, How Cloudflare Fonts works

Font fetches use your origin with the /cf-fonts/ path prefix, which you can see in analytics in the Cloudflare dashboard.

Font requests will be made to your origin with the /cf-fonts/ path prefix.

— Cloudflare, Cloudflare Fonts FAQ

Performance and privacy are the stated benefits: fewer DNS lookups and TLS handshakes to third parties, and no user data collection during font delivery.

By serving fonts from your own domain through Cloudflare’s optimized infrastructure, Cloudflare Fonts reduces DNS lookups, TLS connection setups and latency.

— Cloudflare, Cloudflare Fonts FAQ — performance

No, Cloudflare Fonts does not collect or log user data during the font delivery process.

— Cloudflare, Cloudflare Fonts FAQ — privacy

Cloudflare Fonts setup: dashboard toggle and configuration rules

Section titled “Cloudflare Fonts setup: dashboard toggle and configuration rules”

For the whole zone, enable the feature under Speed → Settings → Content Optimization, or use the linked Settings flow in the dashboard.

In the Cloudflare dashboard, go to the Speed > Settings page. Go to Content Optimization. For Cloudflare Fonts, switch the toggle to On.

— Cloudflare, Get started

Per-hostname control uses a configuration rule. The API boolean is fonts inside action_parameters:

"action_parameters": {
"fonts": false
}

See Configuration Rules settings — Fonts and Create a configuration rule via API for full API examples.

Cloudflare Fonts limitations: Google-only, CSP, APO, and fallback

Section titled “Cloudflare Fonts limitations: Google-only, CSP, APO, and fallback”
Topic What to expect
Font sources Google Fonts only (via <link>, not @import)
Automatic Platform Optimization (APO) Cloudflare Fonts does not run when APO is on; APO already optimizes Google Fonts similarly
Content Security Policy (CSP) Inline styles from the rewrite need compatible style-src; fonts from your origin need compatible font-src
Unsupported pages Falls back to loading Google Fonts again

Currently, Cloudflare Fonts exclusively supports Google Fonts transformation.

— Cloudflare, Limitations

Cloudflare Fonts does not operate when Automatic Platform Optimization (APO) is enabled.

— Cloudflare, Limitations

Cloudflare Fonts does not modify Content Security Policy (CSP) headers. Certain CSP configurations may make Cloudflare Fonts stop working, such as restrictions on inline styles through style-src, or restriction of fonts originating from the site’s own origin via font-src.

— Cloudflare, Limitations

With APO enabled, Google Fonts may already be proxied; font URLs can move from fonts.gstatic.com to your domain, and responses may include a cf-apo-via:proxy header. CSP must allow unsafe-inline on style-src or default-src and self on font-src or default-src when transformation is blocked—see APO troubleshooting FAQ.

If Cloudflare Fonts hits invalid /cf-fonts paths or unexpected runtime errors, requests are forwarded to your origin instead of returning 4xx/5xx directly from the edge, with extra input validation for security (changelog).

font-display: keep text visible while webfonts load

Section titled “font-display: keep text visible while webfonts load”

Lighthouse and Chrome performance insights treat missing or blocking font display strategies as a problem because users can see invisible text (FOIT).

Lighthouse flags any font URLs that may flash invisible text.

— Chrome for Developers, Ensure text remains visible during webfont load

Consider setting font-display to swap or optional to ensure text is consistently visible. swap can be further optimized to mitigate layout shifts with font metric overrides.

— Chrome for Developers, Font display insight

Use swap, optional, or fallback in @font-face so the browser can show a system face until the file is ready:

@font-face {
font-family: 'Pacifico';
font-style: normal;
font-weight: 400;
src: local('Pacifico Regular'), local('Pacifico-Regular'),
url(https://fonts.gstatic.com/s/pacifico/v12/FwZY7-Qmy14u9lezJ-6H6MmBp0u-.woff2)
format('woff2');
font-display: swap;
}

For Google Fonts <link> URLs, append &display=swap, &display=optional, or &display=fallback as described in Ensure text remains visible during webfont load.

Showing a system font first trades FOIT for a flash of unstyled text (FOUT) and can still affect CLS when the webfont swaps in. Pairing font-display: optional with selective preloads may help CLS, but over-preloading can hurt other metrics—Chrome recommends validating with A/B tests (same doc). Performance guidance adds: preload only critical above-the-fold woff2 fonts with crossorigin, subset weights and glyphs, and avoid preloading every font or adding redundant fetchpriority="high".

Visually stable font fallbacks and font-size-adjust

Section titled “Visually stable font fallbacks and font-size-adjust”

When the active font changes, different x-heights and metrics change line breaks and box size even at the same font-size, which feeds CLS and hurts readability.

When web fonts load, they often replace a fallback font that has different dimensions, even if both are set to the same font-size. This causes “layout shift” (Cumulative Layout Shift)…

— Chrome for Developers, Visually Stable Font Fallbacks

font-size-adjust normalizes perceived size, usually against x-height:

.text-content {
font-family: "MyWebFont", "Arial", sans-serif;
font-size: 1rem;
font-size-adjust: from-font;
}

Use from-font on the primary stack, or a numeric aspect ratio when mixing families (Visually Stable Mixed Fonts). Where font-size-adjust is unsupported, tune @font-face with size-adjust, ascent-override, descent-override, and line-gap-override—see Aurora and Improved font fallbacks (linked from the font display insight).

Build-time inlining of small Google Fonts stylesheets (with preconnect to fonts.gstatic.com) can remove a blocking stylesheet round trip at runtime (Font inlining); that is separate from Cloudflare’s HTML rewrite but targets the same class of latency.

text-wrap: balance and text-wrap: pretty for headings and body

Section titled “text-wrap: balance and text-wrap: pretty for headings and body”

Modern CSS text-wrap values change how lines break without JavaScript headline balancers.

For short, multi-line titles, text-wrap: balance asks the browser to even out line lengths (binary search on width in Chromium, with a line cap for cost control):

With text-wrap: balance from CSS Text 4, you can request the browser to figure out the best balanced line wrapping solution for the text. The browser does know all the factors, like font size, language, and allocated area.

— Chrome for Developers, CSS text-wrap: balance

This will, and should be, the primary use case for text-wrap: balance.

— Chrome for Developers, Balance headlines

h1, h2, h3, h4, h5, h6 {
text-wrap: balance;
}
Property Best for Line limit (typical) Performance
text-wrap: balance Headings, table headers ~6 lines (Chromium), up to ~10 (Firefox) Higher; do not use on *
text-wrap: pretty Paragraphs, lists, blockquotes Multi-line body copy Medium; targets orphans on last lines
text-wrap: wrap (default) Maximum speed None Lowest

For short text blocks like headings, use text-wrap: balance… The text-wrap: pretty CSS property allows you to improve the typographic quality of body text… prevent “orphans” (single words on the last line of a paragraph)…

— Chrome for Developers, Improve Text Layout and Legibility

Apply text-wrap: pretty to p, blockquote, li, and similar long copy (same guide). Unsupported browsers ignore these properties and use normal wrapping (fallback strategies).

text-wrap: balance limits: performance, width, and white-space

Section titled “text-wrap: balance limits: performance, width, and white-space”

Balancing costs layout work and is capped to a few wrapped lines:

The task of balancing text is not free… it only works for six wrapped lines and under.

— Chrome for Developers, Limitations — text-wrap: balance

It is not a good idea to apply text-wrap balancing to your entire design.

— Chrome for Developers, Performance considerations

text-wrap: balance does not shrink the element’s inline size—only line breaks inside the existing width—so headings inside bordered cards can look lopsided (Balancing won’t change the inline-size). If white-space prevents wrapping, unset it where balance should apply (Interactions with white-space).

Typography guidance also recommends rem for font-size, unitless line-height, ~80ch max width for body copy, and at least legible sizes (Lighthouse SEO notes aiming for ≥12px on most text: Document doesn’t use legible font sizes).

Common mistakes when combining delivery, loading, and wrapping

Section titled “Common mistakes when combining delivery, loading, and wrapping”
  • Enabling Cloudflare Fonts while APO already rewrites fonts, then wondering why the Fonts toggle appears ineffective (Limitations).
  • Strict CSP (style-src without inline allowance, or font-src without self) blocking rewritten CSS or same-origin font files (Limitations, APO FAQ).
  • Loading Google Fonts only via CSS @import—not supported by Cloudflare Fonts (Limitations).
  • Using font-display: block or omitting font-display, failing Lighthouse’s visible-text audits (font-display).
  • Applying text-wrap: balance globally or on long paragraphs, hitting line limits and wasting layout time (Improve Text Layout and Legibility).
  • Expecting text-wrap: balance to “shrink wrap” heading boxes; use layout or text-fit lockup patterns only when you explicitly need full-width lines (Equal-Width Text Lines).
  1. Follow Cloudflare Fonts troubleshooting: with Fonts off, confirm fonts.googleapis.com and fonts.gstatic.com requests; enable Fonts, disable cache, reload, and confirm /cf-fonts/ on your zone and disappearance of direct Google font hosts.

  2. View page source and verify a <link href="https://fonts.googleapis.com/..."> exists in origin HTML when testing Cloudflare Fonts—server-side optimizers that remove that tag can prevent rewriting (Feature is not working).

  3. Run Lighthouse and open the Ensure text remains visible during webfont load audit; confirm font-display is swap, optional, or fallback on flagged faces (audit doc).

  4. In DevTools, throttle or block webfont files and compare layout with and without font-size-adjust: from-font or metric overrides (Visually Stable Font Fallbacks).

  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact sentence you are asking about, and we will correct or clarify it.