Fonts & grid sizing
ghostty-webgpu derives one integer device-pixel cell grid from your font metrics and uses it across layout, pointer projection, selection, and every renderer. That keeps columns sharp and aligned across Retina displays and fractional zoom levels like 1.25x or 1.5x.
You will learn
Why loading web fonts before
open()prevents a fallback-font flashHow
size,lineHeight, andletterSpacingmap to physical cell dimensions- How Unicode cell widths, DEC mode 2027 graphemes, GSUB ligatures, and BiDi work
Load web fonts before opening
Section titled “Load web fonts before opening”import { Terminal } from 'ghostty-webgpu'
export async function mountWithFont(host: HTMLElement, fontUrl: string) { const face = new FontFace('Terminal Mono', `url(${fontUrl})`) document.fonts.add(await face.load()) const terminal = await Terminal.create({ appearance: { font: { family: '"Terminal Mono", monospace', size: 14 } }, }) await terminal.open(host) terminal.writeln('Font loaded before measuring the grid.') return () => terminal.dispose()}Await your FontFace (or document.fonts.load('400 14px "Your Font"') for CSS @font-face rules) before calling open(). When the face is already loaded, the synchronous initial fit measures your real font on frame one. If a font finishes loading after open(), the built-in document.fonts observer automatically re-measures the grid and clears the glyph atlas.
For ghostty-webgpu/worker, supply faces through the fonts creation option instead of document.fonts (see Run in a worker).
Changing font metrics at runtime
Section titled “Changing font metrics at runtime”Call terminal.setFont(partial) to update family, size, lineHeight, letterSpacing, weight, or boldWeight live.
sizeis the CSS em size in pixels. Measured cell height comes from the font’s ascent plus descent, so a 14 px font atlineHeight: 1.2produces a taller cell than 14 px. Inspectterminal.appearance.grid.cellHeightto see the exact fitted pixel height.lineHeightmultiplies the natural font box (minimum0.5). Values below1center glyphs inside a shorter cell and clip them to their cell span.letterSpacingadjusts horizontal advance in CSS pixels; negative values work as long as the fitted device cell width stays positive.
How integer device-pixel rounding prevents subpixel seams
At fractional pixel ratios such as 1.25 or 1.5, naive CSS pixel cell
widths drift by a fraction of a pixel on every column, leaving visible gaps in box-drawing
characters and TUI borders.
ghostty-webgpu rounds cell width and height to whole device pixels so
cssCellWidth * pixelRatio and cssCellHeight * pixelRatio are exact
integers. Pointer hit-testing, DOM overlays, and GPU vertex positions all read that same
canonical grid. See the
font geometry specification
for the exact equations.
Unicode widths, ligatures, and BiDi
Section titled “Unicode widths, ligatures, and BiDi”- Cell widths and graphemes:
libghostty-vtowns whether a code point occupies 1 or 2 cells; browser font fallback only draws inside that span. When an application enables DEC mode 2027 (grapheme clustering), ZWJ sequences such as👩💻occupy 2 cells and stay intact even across byte-by-byte writes. - Programming ligatures: Off by default. Pass
ligaturestoTerminal.create()to read the font’sGSUBtable and shape joined runs without changing underlying cell ownership. - Bidirectional text: Off by default. Pass
bidi: trueto lazy-load Unicode 13.0 bidirectional row reordering (bidi-js) for right-to-left scripts.
Recap
Await
FontFace.load()ordocument.fonts.load()beforeopen()so frame one uses your real font metrics.Use
terminal.setFont()for runtime size, family, or line-height updates; the grid and atlas refit automatically.Enable
ligaturesorbidi: trueinTerminal.create()when you need GSUB shaping or RTL reordering.