Horror edition · Harlowe 3 · CSS

Twine Field Guide

Twine turns linked passages of text into a playable web game, and it is perfect for horror. Every choice is a door the player does not have to open. Write a passage, add [[a link]], and Twine draws the arrow. This guide covers links, variables, sanity meters, jump scares, timers, creepy styling and publishing, with code you can copy straight into your own story.

Ashgrove House

An eight-passage Twine horror story. Your great-aunt Edith has left you her house, and something in it has been waiting. Every passage shows its real Harlowe source on the right, and the Variables tab tracks what you carry and how much sanity you have left. The rooms are tagged with effects from the Effects lab below: the parlour is candle, the attic is storm, the cellar is blood. There are five endings.

passage Front Hall
Sanity

From empty map to published game

Twine runs in the browser at twinery.org or as a desktop app. The desktop app saves stories as files in a Documents/Twine folder, which is safer for coursework.

Open Twine

Go to twinery.org. Choose Use it online or download the app for Windows, macOS or Linux.

Create a story

In the Library, click + New and name it. You land on the story map with one passage, marked with a green rocket as the start.

Check the format

Open Story › Details. Leave the story format on Harlowe 3 for this guide. The format decides which code syntax works.

Write and link

Double-click a passage to edit. Type [[Open the cellar door]] and a new passage with that name appears on the map, joined by an arrow.

Test as you go

Build › Test plays the story with a debug panel showing every variable. Build › Play shows the player's view.

Publish

Build › Publish to File produces one .html file that runs in any browser. Upload it to itch.io as an HTML game or hand it in as is.

Code cookbook

Paste any snippet into a passage. Macros look like (name: value), hooks are the square brackets that follow them, and variables start with $. The Horror filter collects the scare techniques.

CSS studio

Every Harlowe story is plain HTML using custom tags such as tw-story, tw-passage and tw-link, so ordinary CSS restyles it. Paste CSS into Story › Stylesheet. Pick one of eight complete themes, then edit the code on the left and watch the preview change.

Story Stylesheet
Live preview

Hover over the words in the dust. Every theme hides them until the mouse finds them.

SelectorWhat it styles
tw-storyThe whole page: background, base font, text colour.
tw-passageThe block of text for the current passage.
tw-link, .enchantment-linkPassage links, and links created by (link:) style macros.
tw-link:hoverA link under the mouse pointer.
tw-sidebarThe undo and redo arrows. display: none hides them, so players cannot undo their way out.
tw-hook[name="dust"]One named hook, written |dust>[ ... ] in the passage.
tw-story[tags~="haunted"]Any passage that carries the tag haunted (Harlowe 3.2 and later).
.glitchYour own class, used in a passage as <span class="glitch">...</span>.

Effects lab

Twenty-three horror effects, each running live. Every one is plain CSS for Story › Stylesheet. Most switch on with a passage tag, so the effect only appears where you choose. Some need a line of HTML in the passage, and the torch needs a few lines of Story JavaScript.

Copy the CSS tab into Story › Stylesheet. Stylesheet rules apply to the whole story.
Add the tag shown on the card to a passage with + Tag, or paste the Passage tab into a passage.
If the card has a JavaScript tab, paste it into Story › JavaScript. Then press Build › Test.

The grey chips on each card show which element the effect draws on. Two effects that use the same pseudo-element, such as tw-story::before, cannot run on the same passage because the second rule replaces the first. To combine them, move one effect onto a free slot like tw-passage::after, or give a passage several tags, for example candle heartbeat, where the slots differ.

Harlowe vs SugarCube

Twine ships with several story formats. Harlowe is the default and the friendliest to start with. SugarCube is closer to JavaScript and popular for bigger games. The same idea, written both ways:

TaskHarlowe 3SugarCube 2

Gotchas

The mistakes that haunt almost everyone once.

  • Passage names are case-sensitive.[[cellar]] and [[Cellar]] point at two different passages.
  • Broken links show on the map.A link to a passage that does not exist draws a broken arrow. Usually it is a typo in the name after ->.
  • Curly quotes break macros.Text pasted from Word turns " into “smart quotes”. Retype them in Twine.
  • Use to, never =.(set: $x to 1) works. (set: $x = 1) is an error.
  • No gaps in macro syntax.Write (set: not ( set :, and keep the hook touching: (if: $x)[yes].
  • Temp variables expire._item only lives in the current passage. Use $item to keep it.
  • Sound needs a click first.Browsers block autoplaying audio until the player has clicked something, so put screams after a link, not on the first passage.
  • Browser Twine stores stories in the browser.Clearing site data deletes them. Use Library › Archive to back up, or the desktop app.
  • Images during testing.Relative paths like images/cellar.jpg only work once the published HTML sits next to the images folder.
  • Version control.Build › Export as Twee gives a plain text file that diffs cleanly in Git.

Build challenges

Each one adds a single new technique on top of the last.

Warm-up

Two doors

Five passages, one choice, two endings: one where the player escapes and one where they do not. Links only.

Variables

Locked out

The exit only appears once the player holds both the key and the torch. Use (a:) and contains.

Structure

Sanity meter

A header passage that draws the player's sanity on every page and turns the text red when it drops to 2 or below.

Time

The lights go out

A 60 second (live:) countdown. At zero, (go-to:) a pitch-black ending passage.

Style

Two worlds

Tag the haunted passages haunted and give them a completely different look from the ordinary ones.

Stretch

The unreliable room

A passage that changes every time it is visited using visits, plus whispers that rewrite themselves every few seconds with (live:) and (either:).

Reference