Your Game's Stylesheet
All of your game’s styling goes in one file, style/main.css. This page explains how that file relates to the engine’s own stylesheet, walks through the rules the starter game already put in it, and lists what to check when a change doesn’t show. You need a text editor and a browser, nothing else.
Two stylesheets, yours last
The starter game’s index.html loads two stylesheets, in this order:
<link rel="stylesheet" href="./engine/core/monogatari.css">
<link rel="stylesheet" href="./style/main.css">engine/core/monogatari.cssis the engine’s stylesheet. It holds every screen and component, plus the libraries the engine bundles: Kayros CSS, the animations and the icons. It’s compressed onto a few very long lines, so it’s hard to read, and it’s replaced whenever you update the engine. Don’t edit it.style/main.cssis yours. Anything you put there is kept.
When two CSS rules set the same thing on the same element, the browser picks the one with the more specific selector, and when they’re equally specific, the one that comes later. Your file comes later, so a rule of yours wins over an engine rule with the same selector. When the engine’s selector is more specific than yours, its rule still wins: write a selector at least as specific (see When a rule doesn’t apply).
TIP
Before writing a rule for a color, check CSS Variables. One variable can change the same color on every screen at once.
The rules the starter game gives you
The starter style/main.css is mostly empty rules, one for each part of the interface people change most often. Fill in the ones you need and leave the others empty: an empty rule does nothing.
For example, to give the choice buttons a gold border and a darker background, fill in the two choice rules:
/* Choice Buttons style */
[data-component="choice-container"] button {
border: 2px solid #d4a72c;
background-color: rgba(40, 20, 10, 0.75);
}
/* Choice Button Style on Hover */
[data-component="choice-container"] button:hover {
background-color: #d4a72c;
color: #28140a;
}

Here is what each rule in the file selects.
| Selector | What it styles |
|---|---|
body |
The whole page: the default text color, font and size, and the background behind the menu screens. |
button and button:hover |
Every button that has no more specific rule: the main menu, the choices, the save and load screens, the messages. |
[data-screen] |
Every screen: the main menu, the game, settings, save, load, help, credits and the others. |
[data-screen="main"] and [data-screen="main"] button |
The main menu screen and its buttons. |
[data-component="save-slot"] |
Each save slot on the save and load screens. |
[data-component="save-slot"] [data-content="background"] |
The slot’s picture, which is the element’s background. |
[data-component="save-slot"] figcaption |
The date and time under a slot’s picture. |
[data-component="save-slot"] button |
The round delete button in a slot’s corner. |
[data-component="choice-container"] button and …:hover |
The buttons of a choice. |
[data-component="text-box"] |
The text box, where the dialog appears. |
[data-ui="who"] |
The speaking character’s name in the text box. Its color can’t be set here: see the note below. |
[data-component="centered-dialog"] |
Text shown in the middle of the screen (centered lines). |
[data-screen="game"] [data-character] |
Every character sprite on the game screen. |
[data-screen="game"] [data-image] |
Every image shown with show image. |
[data-component="quick-menu"] |
The quick menu (Back, Hide, Log, Auto, Save, Load, Settings, Quit). |
[data-component="quick-menu"] button and button:hover |
The quick menu’s buttons. The same two rules inside the 601-pixel block at the end of the file change them only from that width up, where the quick menu is a bar at the bottom. |
[data-component="quick-menu"] svg |
The icons of the quick menu’s buttons (see Icons). |
input[type=range] rules |
The track of the sliders on the settings screen: -webkit- for Chromium-based browsers, -moz- for Firefox. The -ms- rules were for Internet Explorer and the first Edge. |
The bottom of the file has empty @media blocks for wider and wider screens, from 601 pixels up. Responsiveness explains them and the widths where the engine’s own layout changes.
A game started from 2.8.1 or earlier has an older copy of this file. Three of its selectors match nothing ([data-component="save-slot"] figure, [data-component="save-slot"] img and [data-component="quick-menu"] > span > .fa), and its quick menu rules select span, which reaches only the buttons’ text labels. To style what their comments say, change them to the selectors in the table.
NOTE
The engine writes the name's color straight onto the name element every time a character speaks: the character's color from monogatari.characters(), or the --character-name-color variable for characters without one. A style written on the element beats any rule in a stylesheet, so color inside [data-ui="who"] never shows. Set the --character-name-color variable instead, or give the character a color. Other properties in the rule, such as font-weight or font-size, work.
Choose selectors that last
The engine finds its own elements through attributes, so those attributes are the safest things to select:
[data-screen="settings"]selects a screen by its name.[data-component="text-box"], or the tag nametext-box, selects a component.[data-content="…"]and[data-ui="…"]select the parts inside a component:[data-component="text-box"] [data-content="text"]is the area the dialog types into.
HTML Data Attributes lists them all, and each component’s page shows its markup. Avoid selectors that depend on the exact order of elements, such as :nth-child(3): a later version of the engine can add an element and move what you meant to style.
Pictures in CSS
A background or a decoration is a picture file and a url() that points at it. The path is relative to style/main.css, which is why it starts with ../:
[data-screen="main"] {
background-image: url('../assets/ui/title.jpg');
}The engine already sizes screen backgrounds to cover the whole screen, centered, without repeating, so that one line is enough. Pictures can also come from an https:// address: the starter game’s index.html allows images from the game’s own folder, from data: addresses and from any https site. Image Menus builds a whole menu this way.
When a change doesn’t show
How a reload behaves depends on how you opened the game:
- Opened from a file (the address bar starts with
file://): a reload shows your change. - Served over plain
http://from an address other thanlocalhostor127.0.0.1: browsers don’t run service workers there, so a reload shows your change. - Served over
https://, or on your own computer athttp://localhostorhttp://127.0.0.1: the starter game installs a service worker, a script that keeps a copy of the game’s files so it loads quickly and works offline. It checks that copy each time the game loads:- After you edit
style/main.css, a reload shows the new stylesheet: the service worker asks the server for it every time. - A picture or font in the
assetsfolder that you replace with a file of the same name still shows the old file on the first reload, which fetches the new one meanwhile; the second reload shows it. - A reload while holding Shift skips every copy and shows everything new at once (checked in Chromium). Firefox can keep a stylesheet it loaded the first time you opened the game, before the service worker was set up: close Firefox and open the game again.
- After you edit
Open Your Game compares the two ways of opening a game in full.
When a rule doesn’t apply
Go through these in order:
- Was the file saved, and is the browser showing the new copy? See When a change doesn’t show.
- Is the CSS valid? A missing
}or;makes the browser skip the rest of the rule, and sometimes the rules after it. Look at the lines right above the rule that doesn’t work. - Does the selector match the element? In a desktop browser, right-click the element and choose Inspect. The developer tools open with the element selected, and the Styles panel lists every rule that applies to it, the most specific first. If your rule isn’t in the list, the selector doesn’t match: compare it with the attributes you see on the element.
- Is another rule winning? In the same panel, a crossed-out line was overridden by a rule above it. Make your selector at least as specific as that rule’s: copying its selector into your file and adding your properties is the quickest way.
- Is the value written on the element itself? The engine sets some styles directly on elements, which beats every stylesheet rule: the character name’s color, a sprite’s animation length when a statement says
duration, and the text box’sdisplay. The panel shows these at the top, underelement.style. Add!importantafter your value to win over them, and only there.
On a phone or tablet, most browsers have no developer tools. Use a loud test value instead: add outline: 4px solid red; to the rule and reload. If a red frame appears around the element, the selector matches and the problem is elsewhere; if it doesn’t, the selector is wrong.
Related pages
- CSS Variables: the colors and sizes you can change without writing selectors.
- CSS Classes and HTML Data Attributes: the hooks to select.
- Components: the markup of each part of the interface.