Fonts
Custom fonts are registered with registerFont, then referenced by fontFamily in text styles.
System families need no registration: "serif", "sans-serif", "monospaced" work as
fontFamily values out of the box.
At a glance
const screen = UIScreen([
UIText("Custom type").style({ fontFamily: "Inter", fontWeight: 700, fontSize: 24, color: "white" }),
]).style({ bgColor: "black", p: 20 })
Promise.all([
registerFont("Inter", asset('./fonts/Inter.ttf'), { weight: 400 }),
registerFont("Inter", asset('./fonts/Inter-Bold.ttf'), { weight: 700 }),
]).then(() => screen.open())registerFont
registerFont(fontFamily: string, url: string, options?: {
weight?: number, // which fontWeight this file serves (400, 700, …)
style?: "normal" | "italic",
}): Promise<void>fontFamilyis the name you'll use in.style({ fontFamily }). Register one call per file: a family with regular + bold is tworegisterFontcalls with the same name and differentweights.url— a project font file viaasset('./fonts/X.ttf')(or an import), or a remotehttps://…URL as a plain string.- The promise resolves when the font is loaded and usable, and rejects on failure (bad URL, unparsable file).
Load fonts before opening the screen
A font applies reliably only to screens opened after it has loaded — text already on screen may keep the fallback font on some hosts. The standard pattern is to gate the entry point on the fonts:
Promise.all([
registerFont("Inter", asset('./fonts/Inter.ttf'), { weight: 400 }),
registerFont("Inter", asset('./fonts/Inter-Bold.ttf'), { weight: 700 }),
]).then(() => Router.init(homeScreen)) // or screen.open()Note
there is no style inheritance — fontFamily is set per UIText (extract a shared
Style<UIText> object rather than relying on a parent).
Pitfalls
// ✗ bare path — resolves only for remote http(s) URLs
registerFont("Inter", "./fonts/Inter.ttf")
// ✓ project files go through asset() (compile-time macro, literal string only)
registerFont("Inter", asset('./fonts/Inter.ttf'))
// ✗ opening the screen before the font resolves — text renders with the fallback
registerFont("Inter", asset('./fonts/Inter.ttf'))
screen.open()
// ✓ await it (Promise.all for several weights), then openSee also
- Text & content elements —
UIText,fontFamily/fontWeightstyles - Conventions —
asset()and project imports