loading
Warning:
Chromium only, over HTTPS The Local Font Access API ships in Chromium-based browsers on desktop. The first query prompts for the local-fonts permission and so must run inside a user gesture.
Note:
A dismissed prompt looks like no fonts A refusal and an unsupported browser both come back as an empty list, on purpose - so a page cannot detect that the user said no. Check IsSupported first if you need to tell the two apart.

Support check

IsSupported

True when the runtime exposes window.queryLocalFonts. During prerender/SSR the check returns false rather than throwing, so defer it to OnAfterRenderAsync.

C#
@inject Bit.Butil.LocalFonts localFonts

var supported = await localFonts.IsSupported();
Live sample
support output
Results will appear here when you interact with the samples.

List installed fonts

Query

Returns every installed face - which on a designer's machine can be thousands - or just the ones named by PostScript name. Group by Family to build a picker that reads like the desktop's.

C#
var fonts = await localFonts.Query();
foreach (var group in fonts.GroupBy(f => f.Family))
{
    // group.Key is the family; each font has PostscriptName, FullName, Style
}

// or a specific face:
var one = await localFonts.Query("Arial-BoldMT");
Live sample
PostScript names (comma separated, blank for all)
query output
Results will appear here when you interact with the samples.

Read a font file

GetData

The raw SFNT bytes of one face - what an exporter needs in order to embed the font the user picked. A font file is routinely several megabytes, so fetch one only for a face that was actually chosen.

C#
var bytes = await localFonts.GetData("Arial-BoldMT");
// bytes is the SFNT blob, ready to embed
Live sample
font data output
Results will appear here when you interact with the samples.

API reference

Member
Signature
Description
IsSupported
ValueTask<bool> IsSupported()
True when the runtime exposes window.queryLocalFonts. Returns default (false) during prerender/SSR instead of throwing.
Query
ValueTask<LocalFont[]> Query(params string[] postscriptNames)
The installed fonts, or the named subset. Empty when unsupported or when the prompt was dismissed. Needs a user gesture the first time.
GetData
ValueTask<byte[]?> GetData(string postscriptName)
The raw SFNT bytes of one face, or null when it is not installed or permission was refused.
LocalFont
class LocalFont { string PostscriptName; string FullName; string Family; string Style; }
One installed face: its unique name, its display name, its family and its style.
An unhandled error has occurred. Reload 🗙