Making a theme
A theme is a small JSON file in your vault at .hatch/themes/<id>.json. Only three colors are required.
{
"id": "forest",
"name": "Forest",
"appearance": "dark",
"tokens": { "bg": "#121a16", "text": "#e3ece6", "accent": "#7fc79a" }
}
Hatch fills in every other token from those three: surfaces, borders, muted text, links, tags, code and callouts.
Readable by default
After filling in tokens, Hatch checks every pair of text and background colors that carries meaning. Anything under WCAG AA (4.5:1 for text, 3:1 for controls) is nudged until it passes, including values you set yourself. A theme can't ship unreadable labels.
More contrast
When the system asks for more contrast (prefers-contrast: more), hints use the secondary text color and dividers get one step stronger.
- Every theme carries two extra tokens for this:
borderHcandborderStrongHc. - Hatch works them out from your
borderStrongandborderControl, so you don't need to set them. You can if you want other colors. base.csspoints--h-borderand--h-border-strongat them inside the media query. A token is never defined from itself there, which would leave it empty.
Overriding tokens
You can set any token from ThemeTokens in packages/theme/src/index.ts, for example link, tag, codeText or surfaceElevated. Values must be plain colors: hex, rgb(), rgba(), hsl() or hsla(). Shadows accept plain box-shadow lists. Anything else is ignored, so a theme can't load images or URLs.
Code colors
Code blocks are colored by seven tokens: syntaxComment, syntaxKeyword, syntaxString, syntaxNumber, syntaxFunction, syntaxType and syntaxProperty. A theme that leaves them out gets Hatch's palette, nudged until each color reads on its own codeBg.
To change them without writing JSON, open the theme studio and expand Code colors. Only the colors you change are saved.
The highlighter is @hatch/highlight. It knows JavaScript and TypeScript, Python, Rust, Go, Java and its relatives, C and C++, shell, SQL, CSS, HTML and XML, JSON, YAML, TOML and diffs. Other fences stay plain.
Fonts
Add "fonts": { "text": "serif" } to use Source Serif for note text. sans and mono also work. Fonts ship with the app, so nothing downloads.
Try it
Settings, Community themes, then "Create a starter theme". Edit the file and press "Reload themes".
Controls
Buttons, fields and badges share one set of tokens in packages/theme/src/base.css:
- Heights:
--h-control-sm(26px),--h-control(30px),--h-control-lg(40px),--h-field(32px),--h-menu-item(32px). - Radius:
--h-radius-xs(4px) for small buttons and badges,--h-radius-sm(6px) for buttons and fields,--h-radius(8px) for large buttons,--h-radius-lg(10px) for menus and dialogs. --h-shadow-md(theshadowMdtoken) is under menus and popovers.--h-shadow-lg(shadowLg) is under dialogs and toasts.--h-shadow-buttonlights a button from above.--h-shadow-button-primaryis for dark buttons.--h-focus-ringis the keyboard focus look: a ring in the theme's focus color, with a gap and a soft halo.- Checkboxes and radio buttons have one look,
CONTROLS_CSSinpackages/theme/src/controls.ts. Puth-checkboxon a checkbox andh-radio-inputon a radio button. The app installs the rules with its theme, and sites carry them insite.css.
Published sites use the same numbers. They come from FOUNDATION in packages/theme/src/foundation.ts, and a test keeps that file and base.css in step.
Button classes: .h-btn with primary, flat, ghost or danger, and sm or lg. Badges: .h-badge with caps, accent, success, warning or danger.