Open original
Info
Demo 2.10

Importing fonts

There are three ways to get a font onto a page, and they trade convenience against speed and privacy.

1. Host the file yourself

@font-face {
	font-family: "My Font";
	src: url("myfont.woff2") format("woff2");
	font-display: swap;
}

Then use font-family: "My Font" as normal. The name in @font-face is one you invent.

This is what I do. It’s the fastest, it doesn’t hand your visitors’ data to anybody, and the font can’t vanish because someone else changed their service.

Use .woff2 ~ it’s the smallest format and every browser supports it.

2. A hosted service

Google Fonts and friends give you a <link> to paste in. Easy, and completely fine to start with. It does mean an extra connection to somebody else’s server before your text can render.

3. System fonts

font-family: system-ui, sans-serif;

No download at all ~ you get whatever the reader’s device already uses. Instant, and it always feels native. Underrated!

Two things that will bite you

Always list a fallback. font-family: "My Font", system-ui, sans-serif ~ if the file fails to load, you still have text.

Always set font-display: swap. Otherwise browsers may hide your text entirely while the font downloads, and blank text is worse than the wrong font.

Try it here

Drag a .woff2 file straight onto this editor, uncomment the @font-face block, and change the filename to match.

Next demoBasic interactivity using <code>:hover</code> and <code>:active</code> states
Keyboard Shortcuts
⌘ Z / ⌘ ⇧ ZCtrl Z / Ctrl ⇧ Z Undo / redo
Tab / ⇧ TabTab / ⇧ Tab Indent / unindent selection
⌘ ] / ⌘ [Ctrl ] / Ctrl [ Indent / unindent lines
⌘ ACtrl A Select all
⌘ DCtrl D Select next occurrence of selection
⌘ /Ctrl / Comment / uncomment lines
Ctrl SpaceCtrl Space Autocomplete
Ctrl EnterCtrl Enter Reset layout
⌘ ⌥ [ / ⌘ ⌥ ]Ctrl ⇧ [ / Ctrl ⇧ ] Fold / unfold block
Code
The editor didn't load — try refreshing the page. Navigation, shortcuts and the info panel still work in the meantime.
Preview
Dimensions0 × 0
Delay
Console