Fonts
The default font
The engine’s stylesheet sets the whole game in Open Sans, falling back to the browser’s standard sans-serif font:
body {
font-family: 'Open Sans', sans-serif;
}The engine doesn’t include the Open Sans font files. A player who has Open Sans installed on their device sees it; everyone else sees their browser’s standard sans-serif font, which differs from one device to another. To be sure every player sees the same letters, give your game a font of its own, as below.
Everything inherits the body font: the menus, the buttons and fields, the text box and the dialog log. Code blocks use a monospace font.
Use a font file from your game’s folder
This way the font travels with your game and works offline. It works the same whether you open index.html from a file or serve the game (checked in Chromium and Firefox).
Put the font file in your game’s
assets/fonts/folder (the starter game already has it)..woff2files are the smallest;.ttfworks too. For this example the file isassets/fonts/story-serif.woff2.Open
style/main.cssand add a@font-facerule at the very top. It gives the file a name to use in your CSS:@font-face { font-family: 'Story Serif'; src: url('../assets/fonts/story-serif.woff2'); }The path in
url()is relative tostyle/main.css, which is why it starts with../.Fill in the starter file’s
bodyrule with the name, followed by fonts to use if the file can’t load:/* General Style */ body { font-family: 'Story Serif', Georgia, serif; }Save and reload. Every text in the game, from the main menu to the dialog, uses the new font.


Check the font’s license allows you to include it in a game you share: many free fonts do, some only for personal use.
NOTE
When the game is served from a web address, the starter game's service worker keeps a copy of everything in assets. If you replace a font file with another of the same name, the first reload (or a player’s next visit) still shows the old one, and the one after it the new font. See Your Game’s Stylesheet.
Use a font from a font service
A font service, such as Google Fonts, gives you a line that loads the font from its website. Two changes are needed, because the starter game’s index.html only lets stylesheets load from the game’s own folder:
Open
index.htmland find the line that starts with<meta http-equiv="Content-Security-Policy", near the top. Inside itscontent, add the service’s address afterstyle-src 'self' 'unsafe-inline'. For Google Fonts, this part:style-src 'self' 'unsafe-inline';becomes:
style-src 'self' 'unsafe-inline' https://fonts.googleapis.com;Put the service’s
@importline on the first line ofstyle/main.css(CSS ignores an@importthat comes after other rules), then use the font in thebodyrule:@import url('https://fonts.googleapis.com/css2?family=EB+Garamond:wght@400;600&display=swap');/* General Style */ body { font-family: 'EB Garamond', Georgia, serif; }
Without the first step, the browser blocks the service’s stylesheet (the console shows a message about the Content Security Policy) and the game falls back to the next font in the list. The font files themselves come from another address (fonts.gstatic.com for Google Fonts), which the starter policy already allows, like any https address. Both steps were checked in Chromium and Firefox, served and opened from a file.
A game that loads its font from a service needs an internet connection to show it. For a game that should work offline, or a desktop build, use a font file instead.
A font for one part of the game
Set font-family on the part instead of on body. A handwritten font for the dialog only, with the menus left as they are:
[data-component="text-box"] {
font-family: 'Story Hand', cursive;
}Other parts to give a font of their own: the character’s name ([data-ui="who"]), the main menu ([data-screen="main"]), the choices ([data-component="choice-container"] button), the titles of the menu screens ([data-screen] h2). Each needs its own @font-face rule if it comes from a file.
Text size
The text grows with the screen. body starts at 1rem (16 pixels), and the engine raises it on screens that are both wide and tall enough:
| Screen at least | Text size |
|---|---|
| any size | 1rem (16px) |
| 768 × 432 pixels | 1.2rem (19.2px) |
| 992 × 558 pixels | 1.35rem (21.6px) |
| 1200 × 675 pixels | 1.5rem (24px) |
The titles of the menu screens (h1, h2) are 3rem, and 3.5rem from 992 × 558 pixels. Responsiveness lists everything else that changes with the screen.
To make the dialog larger or smaller and still grow with the screen, use em, which is relative to the size around it, instead of rem or pixels:
[data-component="text-box"] {
font-size: 1.1em;
}The dialog is now 10% larger than the rest of the text at every screen size: 26.4 pixels instead of 24 on a 1280 × 720 screen, 17.6 instead of 16 on a phone. A font-size in rem or pixels is the same on every screen. A body { font-size: … } rule in your file replaces the engine’s sizes at every width, because yours comes later.
Related pages
- Your Game’s Stylesheet: where these rules go.
- Responsiveness: the widths and heights where the layout changes.
- Icons: icons are small drawings (SVG), not letters of a font, but their size follows
font-size.