Extension Font Settings: Generic Families, Scripts, and Size Controls
How the fontSettings extension API maps CSS generic families and ISO 15924 scripts to fonts, and how to get, set, and clear sizes.
This page summarizes Chrome’s extension documentation for the fontSettings API—the surface extension authors use when they need to read or change how the browser resolves fonts (typeface choice and default sizes), not when they style a single web page with CSS.
Use the chrome.fontSettings API to manage Chrome’s font settings.
— Chrome,
fontSettings(Manifest V3 reference)
Extensions that adjust reading comfort, enforce organization font policies, or sync preferences across profiles are the usual audience. The API mirrors settings a user could change in the browser UI, but exposes them programmatically behind the fontSettings permission (Manifest V2 reference).
fontSettings API: what it controls vs page CSS
Section titled “fontSettings API: what it controls vs page CSS”The fontSettings API does not replace author stylesheets. It changes browser-level preferences: which physical font backs each CSS generic font family, and default, minimum, and fixed-width font sizes in pixels. When a page uses font-family: sans-serif or declares a language, Chrome applies these preferences when choosing a typeface.
On Manifest V3, call browser.fontSettings; on Manifest V2, chrome.fontSettings supports the same methods, often with an optional callback in addition to the returned Promise (MV2 fontSettings).
Generic font families and language scripts: how the browser picks a font
Section titled “Generic font families and language scripts: how the browser picks a font”Chrome ties some settings to generic font families and to language scripts (ISO 15924 script codes). The two interact in ways that confuse people who expect “one font per script” everywhere.
Chrome allows for some font settings to depend on certain generic font families and language scripts. For example, the font used for sans-serif Simplified Chinese may be different than the font used for serif Japanese.
The generic font families supported by Chrome are based on CSS generic font families and are listed under GenericReference. When a web page specifies a generic font family, Chrome selects the font based on the corresponding setting. If no generic font family is specified, Chrome uses the setting for the “standard” generic font family.
When a web page specifies a language, Chrome selects the font based on the setting for the corresponding language script. If no language is specified, Chrome uses the setting for the default, or global, script.
The supported language scripts are specified by ISO 15924 script code and listed under ScriptCode. Technically, Chrome settings are not strictly per-script but also depend on language. For example, Chrome chooses the font for Cyrillic (ISO 15924 script code “Cyrl”) when a web page specifies the Russian language, and uses this font not just for Cyrillic script but for everything the font covers, such as Latin.
— Chrome, Generic font families and scripts (MV2)
In practice:
| Input on the page | Setting Chrome consults |
|---|---|
Named generic family (e.g. sansserif) |
Matching genericFamily entry |
| No generic family | "standard" generic family |
| Language on content | Script derived from language |
| No language | Global script (Zyyy when omitted in API calls) |
GenericFamily is documented as a CSS generic font family. FontName returns fontId (stable ID) and displayName (human-readable).
Separately, Cloudflare Browser Run documents which generic families and bundled faces exist in that remote browser environment (serif, sans-serif, monospace, cursive, fantasy, plus named families). That list describes an automation runtime, not the user’s fontSettings preferences—but it shows the same generic family names extensions and CSS rely on.
Permission fontSettings: what to declare in the manifest
Section titled “Permission fontSettings: what to declare in the manifest”Declare the fontSettings permission so the extension can call the API (MV2 permissions). Without it, getFont, setFont, and size methods are unavailable.
getFont and setFont: read and assign typefaces per family and script
Section titled “getFont and setFont: read and assign typefaces per family and script”getFont: which font ID applies for genericFamily and script?
Section titled “getFont: which font ID applies for genericFamily and script?”getFont needs details.genericFamily and optional details.script. If script is omitted, the global script setting (Zyyy) is used (getFont parameters).
Example from the docs—read the standard font for Arabic script:
browser.fontSettings.getFont( { genericFamily: 'standard', script: 'Arab' }, function(details) { console.log(details.fontId); });On MV2, the resolved fontId may differ from what you passed to setFont if the font is missing on the system; an empty fontId means fallback to the global script font setting (MV2 getFont).
setFont and clearFont: assign or remove an override
Section titled “setFont and clearFont: assign or remove an override”setFont takes fontId, genericFamily, and optional script (default global Zyyy). An empty fontId falls back to the global script font setting (setFont).
browser.fontSettings.setFont( { genericFamily: 'sansserif', script: 'Jpan', fontId: 'MS PGothic' });clearFont removes an extension-set font for the given genericFamily and optional script; omitting script clears the global script entry (clearFont).
Default, minimum, and fixed font size: pixelSize methods
Section titled “Default, minimum, and fixed font size: pixelSize methods”Size-related methods use pixelSize in pixels (setDefaultFontSize, setMinimumFontSize).
| Concern | Get | Set | Clear |
|---|---|---|---|
| Default page font size | getDefaultFontSize |
setDefaultFontSize |
clearDefaultFontSize |
| Minimum font size | getMinimumFontSize |
setMinimumFontSize |
clearMinimumFontSize |
| Fixed-width (monospace) default | getDefaultFixedFontSize |
setDefaultFixedFontSize |
clearDefaultFixedFontSize |
Callbacks for get/set size methods can include levelOfControl, indicating how strongly this extension owns the value relative to other extensions or the user (MV2 getDefaultFontSize parameters).
Change events: onDefaultFixedFontSizeChanged and font listeners
Section titled “Change events: onDefaultFixedFontSizeChanged and font listeners”Register listeners when your UI must react to updates:
onDefaultFixedFontSizeChanged— fires when the default fixed font size changes; callback receivespixelSizeandlevelOfControl(onDefaultFixedFontSizeChanged).- Font change notifications include
fontId,genericFamily, optionalscript, andlevelOfControl(MV2 listener parameters).
The docs point to a fontSettings API example in the chrome-extension-samples repository (named in MV3 examples and MV2 examples); install that sample to exercise the API interactively.
Common mistakes when using fontSettings in extensions
Section titled “Common mistakes when using fontSettings in extensions”- Treating
fontIdas guaranteed —getFontmay return a system-resolved ID, not the string you set (MV2getFont). - Omitting
scriptunintentionally — you read or write the global (Zyyy) slot instead of a locale-specific one. - Expecting strict per-script isolation — language on the page can drive Cyrillic and Latin from the same family choice (generic families and scripts).
- Confusing Workbox
fontFallback— workbox-recipes defines optionalfontFallbackas an offline URL for precaching, not a typography API; it does not callfontSettings. - Skipping the permission — calls fail without manifest
fontSettings(MV2 reference).
For readable typography in page content (contrast, sizing in CSS), see Chrome’s Accessibility coding guidelines (Typography section)—that guidance complements, but does not replace, user-level font preferences.
How to check this on your site
Section titled “How to check this on your site”-
Confirm your extension manifest includes the
fontSettingspermission per the MV3 API or MV2 API. -
In a development build, call
getFontwith a knowngenericFamilyandscript(e.g.standard+Arab) and logfontIdusing the documented example. -
Apply
setFont, reload a test page that uses the matching generic family and language, and callgetFontagain to confirm the returnedfontIdandlevelOfControl. -
If you change default or minimum sizes, use
getDefaultFontSize/getMinimumFontSizeand verifypixelSizematches what you set. -
You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact statement you are asking about, and we will correct or clarify it.