Lesson Notes — Styling Your Twine Story with a Stylesheet
Course 2: Game Design & Development Principles / Unit 5: Game Design Storytelling & Nonlinear Narratives / Lesson 9: Styling Your Twine Story with a Stylesheet
Save your work every day: Export your story and save it to Google Drive at the end of every class. Twine only saves your story in the browser on the laptop you are using, and you may not get the same laptop next time.
Lesson overview
When you export your Twine game, you get an .html file that plays in a web browser. A stylesheet controls how that page looks: the colors, the fonts, the box around each passage, and the links. Stylesheets are written in CSS. Every Twine story has its own stylesheet, and whatever you put in it is saved inside your exported .html file.
Before you start: check your story format
This lesson uses Harlowe, the story format Twine uses by default. To check, open your story and look at the story’s Details under the Story menu. If your story uses a different format, such as SugarCube, the names you style are different.
Step 1: Open the stylesheet
- Open your story in Twine.
- At the top, open the Story menu and choose Stylesheet. (In older versions of Twine this is called Edit Story Stylesheet.)
- A blank editor opens. Anything you type here changes how your whole game looks.
Step 2: How a CSS rule works
Each rule has a selector (what to style), then curly braces holding one or more property: value; pairs (how to style it).
tw-story { background-color: black; color: white; }
This says: for the whole story page, make the background black and the text white.
The parts of a Harlowe story you can style
| Selector | What it styles |
|---|---|
tw-story |
The whole story page |
tw-passage |
The passage the player is reading |
tw-sidebar |
The undo and redo arrows on the left side |
tw-link, .enchantment-link |
The choices the player clicks |
tw-link:hover, .enchantment-link:hover |
A choice while the mouse is over it |
.visited |
Choices that lead to a passage the player has already seen |
Properties to try
| Property | What it changes | Example value |
|---|---|---|
background-color |
Background color | black or #1a1a2e |
color |
Text color | white or #f5f5f5 |
font-family |
The font | Georgia, serif |
font-size |
Text size | 1.2em |
padding |
Space inside a box | 20px |
border |
A line around a box | 2px solid gold |
border-radius |
Rounded corners | 10px |
Colors can be names like red or hex color codes like #ff0000.
Step 3: Paste in a starter stylesheet
Copy this into your stylesheet, then change the values to fit your game.
/* Whole page */
tw-story {
background-color: #1a1a2e;
color: #f5f5f5;
font-family: Georgia, serif;
}
/* The passage box */
tw-passage {
background-color: #26264d;
padding: 20px;
border: 2px solid #c9a227;
border-radius: 10px;
}
/* Choices */
tw-link, .enchantment-link {
color: #ffd166;
}
/* Choices when the mouse is over them */
tw-link:hover, .enchantment-link:hover {
color: #ffffff;
}
/* Choices that go to a passage already seen */
.visited {
color: #c9a227;
}
Step 4: Test your look
- Click Play (or Test) to open your game in the browser.
- Change one value at a time and play again, so you can see what each change does.
- Make sure your text is easy to read against the background.
Step 5: Export and save
- Export your story as an .html file (Build, then Publish to File).
- Open the .html file in your browser. Your new look is part of the file.
- Save the file to your Google Drive.
Finished early? Keep building
When your stylesheet is done, add up to 10 more passages to your story. Give each one dialogue and choices.
Check your understanding
- Where in Twine do you find your story’s stylesheet?
- In
tw-passage { padding: 20px; }, which part is the selector, the property and the value? - Which selector would you use to change the color of the choices?
- How does the look you picked fit the mood of your game?
Use this lesson’s Key Terms page to build your glossary.