# Site templates and style

Themes set a site's colors. Templates set everything else: fonts, the text size and type scale, spacing, the column, the header, how posts are listed and the footer. Blogs and portfolios can use them. Docs sites have their own look (see `docs/docs-sites.md`).

Everything is in `.hatch/site.json`, typed and checked, so a person, the Publish panel and a coding agent all edit the same few settings instead of raw CSS.

```json
{
  "title": "Ada Lindqvist",
  "kind": "blog",
  "folders": ["Blog"],
  "template": "quiet",
  "style": {
    "tagline": "Design Engineer",
    "width": 644,
    "type": { "h2": { "weight": 550 } }
  }
}
```

## Templates

| id | Looks like |
|---|---|
| `hatch` | The default: a sticky header, headings in a clear scale |
| `quiet` | One text size, headings by weight only, lots of room, the name with a line under it, warm off-white |
| `index` | Small type, every post on one page grouped by year, dark grey |
| `essay` | A book serif at 17px, warm paper colors, headings with presence, title and date rows |
| `compact` | Small sans type on the left, underlined links, nothing extra |

A template is only a starting point. Anything in `style` wins over it.

Colors: `style.colors` in the site's own settings win over everything. A template's colors (quiet, index, essay and compact have them) apply only until a theme is picked for that mode in `theme`.

### Your own templates

A look can be saved as a template in the vault, one file per template in `.hatch/site-templates/<id>.json`:

```json
{
  "name": "Small and plain",
  "help": "14px sans on the left, black on white",
  "base": "quiet",
  "style": { "size": 14, "width": 480, "align": "left" }
}
```

`base` is the built-in it starts from (leave it out for `hatch`) and `style` takes the same settings as site.json. A site picks it by its id: `"template": "small-and-plain"`. The site's own `style` still goes on top. The id is the file name: lowercase letters, numbers and dashes, never a built-in's id. In the Look panel, "Save this look as a template" writes the file and picks it. To use a look in another vault, copy the file.


### Looks from plugins

A plugin with the `site` permission can bring looks too (`ctx.site.addLook`, see [plugins.md](https://hatch-docs.pages.dev/building-on-hatch/writing-a-hatch-plugin/)). They show with your templates and are picked the same way. Your own template with the same id always wins, and a plugin's look with problems isn't offered.

## Style

Every setting is a named choice or a number in a range. `site.schema.json` (written next to `site.json`) lists them all with their ranges, so editors autocomplete and flag mistakes.

| Setting | Takes | What it does |
|---|---|---|
| `font.body`, `font.headings` | `sans`, `system`, `serif`, `book`, `mono`, or a name from `fonts` | Typefaces |
| `size` | 13 to 22 | Body text in px |
| `leading` | 1.2 to 2 | Body line height |
| `width` | 360 to 960 | The column in px |
| `scale` | 1 to 1.6 | Heading sizes: h3 is size × √scale, h2 size × scale, the title size × scale². 1 is flat, headings differ by weight only |
| `headingWeight` | 300 to 800 | |
| `space` | 0.75 to 2.5 | Vertical room. 1 is normal, 2 airy. Phones get a third of anything above 1 |
| `radius` | 0 to 20 | Corners of code, cards and pictures |
| `align` | `center`, `left` | Where the column sits |
| `header` | `bar`, `plain`, `stacked`, `none` | Sticky with a line; in the page with no line; the name with the tagline under it; no header at all (/ still opens search) |
| `logoSize` | 16 to 96 | The logo beside the site name, in px. The picture is site.json’s `logo` (and `logoDark`) |
| `logoShape` | `square`, `round` | Soft corners, or a circle for a photo of you |
| `tagline` | text | A line under the site name |
| `nav`, `search`, `themeToggle` | `show`, `hide` | The header's page links, Search button and light/dark switch. Hidden search still opens with `/` |
| `hero` | `show`, `hide` | The home page's intro heading. Hidden, it stays for screen readers |
| `posts` | `list`, `stacked`, `rows`, `years`, `table` | How posts are listed. `table` has columns for title, tags (when any post has them) and date |
| `postsLabel` | text | The heading over the home page's post list |
| `labels` | `quiet`, `strong`, `heading` | Home page section titles, including the home note's own `##` headings |
| `dates` | `show`, `hide` | Dates on posts and in lists |
| `readingTime` | `show`, `hide` | "4 min read" beside a post's date (off by default) |
| `related` | `show`, `hide` | Up to three posts that share tags, under each post (off by default). A tag on most posts only counts when nothing rarer is shared |
| `backlinks` | `show`, `hide` | "Linked from": published pages that link to a post, under it (off by default). Links inside `%% comments %%` don't count |
| `dropCap` | `show`, `hide` | A post's first letter large and dropped into the text, in the heading font (off by default) |
| `pager` | `cards`, `plain`, `hide` | Older and Newer under a post |
| `footer` | `bar`, `plain` | |
| `hover` | `list`, `underline`, `dim`, `none` | Pointing at a post or project in a list: the list’s own look, the title underlines, the other rows fade, or nothing |
| `links` | `underline`, `subtle`, `plain` | Links in text |
| `italic` | `normal`, `serif` | Italic in a serif, set into sans text |
| `code` | `fill`, `outline` | Code as a tinted box, or outlined on the page color |
| `colors.light`, `colors.dark` | `{ "bg", "text", "accent" }` hex colors | Take the place of the site's themes. Hatch works out the rest and keeps text readable |
| `fonts` | `[{ "name", "file", "weight", "style" }]` | Font files (.woff2, .woff, .ttf, .otf) from the vault. They're copied with the site and .woff2 files are preloaded |
| `type.<role>` | `font`, `size`, `weight`, `tracking`, `leading`, `color` (`text`, `muted`, `faint`, `accent`), `case`, `italic` | One text role at a time |

Text roles: `title` (a post's title and the home heading), `h2`, `h3`, `body`, `homeBody` (text on the home page only), `brand` (the site name), `tagline`, `nav`, `label` (section titles), `meta` (dates), `postTitle`, `postDesc` (in post lists), `code`.

Pages cross-fading into each other is `"transitions": true` in site.json (Look panel, Details tab, "Fade between pages"). It's off by default, and readers who ask their device for less motion never see it.

## The Look panel's preview

The preview above the Look settings redraws as settings change. A click on a part of the page (the header, the post list, the footer, the text) opens the tab with that part's settings. Links in it open that page of the site in the preview, so post settings (reading time, drop cap, the post slot) can be seen on a post; the back button returns home. Desktop and Phone switch the width: Phone draws the page at 390px, so the site's own phone layout shows. `previewPage(files, path, { pick: true })` adds the click-to-part reporting (`PreviewPart`: header, posts, footer, text).

## Header, footer and post slots

Notes can show on every page of a blog or portfolio, or under every post, set in site.json:

```json
"slots": { "header": "Parts/Links.md", "footer": "Parts/Colophon.md", "post": "Parts/Under posts.md" }
```

The header note sits beside the site name (one line of text, like `[twitter](https://…) / [github](https://…)`), and the footer note sits above the footer line. Links work as they do in pages, and a link that starts with `/`, like `blog`, goes to that address on the site, for pages Hatch makes such as the post list. The notes themselves don't need to be published. The post note sits under every post's text, above "Linked from" and related posts: the place for an author card or a newsletter box. Your own components from `.hatch/components` work in all three, so an author card can be one component used in one note. In the Look panel they're "Words in the header" (Header tab), "Under each post" (Posts tab) and "Words above the footer" (Details tab).

## Series

Posts that belong together name the same series in their properties, and each one shows a small box above its text: "Part 2 of 4 in Grids", with every part linked in date order.

```md
---
date: 2026-02-01
series: Grids
---
```

A series needs at least two published posts. Related posts never suggest a post's own series parts, since the box already links them.

Two more properties show beside the date when a note has them, for digital gardens: `stage: seedling` (or budding, evergreen, any short word) as a small label, and `updated: 2026-03-02` as "Updated Mar 2, 2026" when it's later than the date. With `header: none`, every post gets a "← All posts" link above it so readers can still get around.

## Link previews

Posts without a `cover` get a made picture for link previews (X, Slack, iMessage): the title, the site's name and the date, in the site's colors and heading font, saved beside the post as `card.<hash>.png` (a new name when the title changes, so previews update). Publishing or downloading from the app makes them, once the site has its address (`url`, which preview tags need); `"cards": false` in site.json turns them off. A post with a cover uses its cover.

## Home pages

The home note decides the order. Its `##` headings become sections, a `cards` block with `look: list` is a quiet list of projects, and a `posts` block puts the post list where you want it (otherwise it goes at the end):

````md
## Today

Working on a course about careful interfaces.

## Projects

```cards
look: list
items:
  - title: Ripple
    text: A tiny notification component.
    link: https://example.com/
```

```posts
title: Writing
```

## More

Find me on GitHub.
````

## Preview, build and measure from the command line

```sh
npx tsx packages/publish/src/site-cli.ts preview <vault folder> [--port 4321]
npx tsx packages/publish/src/site-cli.ts build <vault folder> [--out site] [--url https://…] [--cloudflare-analytics]
npx tsx packages/publish/src/site-cli.ts measure <url> [--json]
```

(Installed, the command is `hatch-site`.)

- `preview` builds the vault's site, serves it at http://localhost:4321/ (this computer only, with clean addresses) and rebuilds on every change in the vault, reusing the pages of notes that didn't change. It prints publish warnings and style problems after each build.
- `build` writes the site to a folder (`site/` in the vault unless `--out` says otherwise) for any static host, such as Cloudflare Pages, Netlify or GitHub Pages. It replaces an earlier build there and refuses a folder that holds anything else. It adds a `_headers` file, which Cloudflare Pages and Netlify read, with the same content security policy Hatch's server sends and a year of caching for files named by their content (`staticHeaders()` in `staticHost.ts`). `--url` sets the public address for this build (canonical links, feed, sitemap) without changing site.json. With a public address, a blog or portfolio also gets link preview pictures for the home page and every post without a cover, drawn with Playwright when it is installed. `--cloudflare-analytics` lets Cloudflare Web Analytics (free, no cookies) through that policy: turn Web Analytics on in the Pages project and Cloudflare adds its script. Forms, votes, newsletters and private sites need a Hatch server; a static copy has pages, feeds, search and assets.
- `measure` opens a live page in a browser (it needs Playwright), reads its colors, text font, size and line height, column width and position, headings and header, and prints a starting `style` for site.json. Everything is clamped to the settings' ranges, and what has no setting (a font Hatch doesn't have, a column narrower than 360px) is listed under "Not carried over". `--json` prints the raw numbers too. It only visits the address you give it.

## Checking

`checkStyle(template, style)` from `@hatch/publish` returns every problem in plain words with where it is (`style.width is 2000; it takes 360 to 960.`). Publishing lists the same problems as warnings. A site still builds with problems: what can't be used is left out, and nothing in `style` can add raw CSS.

## For agents

- Over MCP, call `site_look` first: every setting, its range, the plain words that mean it ("airier" is `space`, "bolder headings" is `headingWeight`), the templates, and the site's current style with its problems. `check_site_style` checks a style before you save it.
- Without MCP, the same map is `styleGuide()` from `@hatch/publish` and the `Asks:` part of each description in `site.schema.json`.
- Change the look by editing `template` and `style` in `.hatch/site.json`. Don't write CSS for anything a setting covers.
- Start from the template closest to what you're matching, then change the fewest settings.
- To make a look reusable, write it to `.hatch/site-templates/<id>.json` (see Your own templates). `site_look` lists saved templates and their problems.
- To match a site, run `hatch-site measure <url>` for a starting style, then compare by eye with `hatch-site preview` and change the rest (spacing between sections, section titles, post list look).
- The `css` setting (a stylesheet in the vault) is still there for the rare thing `style` can't say.

## Where the code is

- `packages/publish/src/siteStyle.ts`: templates, the rules, `checkStyle`, `resolveStyle` and the schema.
- `packages/publish/src/siteStyleCss.ts`: the CSS a resolved style writes.
- `packages/publish/src/siteTemplates.ts`: templates saved in the vault: reading, checking and saving them.
- `packages/publish/src/site-cli.ts`, `staticHost.ts` and `styleMeasure.ts`: the preview, build and measure commands.
- `packages/publish/src/styleFields.ts`: every setting's label, group, choices and plain asks. The Look panel (`components/SiteLook.tsx`) is drawn from it.
- `packages/publish/src/templates.ts`: the header (tagline, hidden parts) and post list variants.
- `packages/publish/src/site.ts`: applies it to blogs and portfolios, fonts, and the `posts` block.
- `packages/publish/src/renderCache.ts`: `createBuildCache()`, kept between builds (`buildSite(vault, config, { cache })`) so a rebuild only parses and draws notes that changed. Previews use it; output is the same without it.
- Tests: `packages/publish/src/siteStyle.test.ts`.
