kit.yaml
kit.yaml sits at the root of the kit. It names the kit and holds everything the templates share: design tokens, copy constants, the styles of Markdown inlines, and the rules and Go types that apply to every template.
Know the keys
| Key | Value | What it does |
|---|---|---|
name | string, required | The kit's name (Kit.Name()). lttr kit check prints it |
version | integer | Your kit's version (Kit.Version(), 0 when absent). lttr gives it no meaning |
default | a component name | The component loose top-level Markdown goes into. Without it, loose Markdown is a compile error |
dark | true or false | The kit supports dark mode. The lint then requires the color-scheme meta |
tokens | mapping | Design values: colours, fonts, sizes |
vars | mapping of strings | Copy constants such as the brand name. Config.Vars overrides them |
spans | mapping | The classes allowed in [text]{.class} |
inline | mapping | The styles of links, code, strong, em and strike |
limits | button, link | Template-wide caps on :button and :link |
types | list | The Go types components may bind |
frontmatter | mapping | The kit's own frontmatter keys, typed like attributes |
Any other key is a load error at its position:
$ lttr kit check ./emailkit
emailkit/kit.yaml:11:1: unknown key "colour"
Name the kit
Plain's header sets the name, the default component and dark mode:
# Plain: a small, neutral starter kit for lttr.
#
# One left-aligned column on a light canvas, a system sans-serif stack,
# square buttons and light/dark colours. Copy it with `lttr kit init` and
# change anything: tokens here, markup in layout.html, blocks.html and
# components/*/html.tmpl.
name: plain
version: 1
default: section
dark: true
default must name one of the kit's components. dark: true means the kit carries a dark palette: see Email-safe HTML.
Define tokens
Tokens are the design values templates read with {{token "name"}}, or through {{style "prop" "name"}}. Plain's tokens are colours, two font stacks and sizes:
tokens:
# Colour tokens may use any CSS colour syntax: a hex value, or a
# function like rgb(47 111 235), rgba(31,35,40,0.9) or hsl(217 90% 70%).
color.canvas: { light: "#F6F8FA", dark: "#010409" }
color.surface: { light: "#FFFFFF", dark: "#0D1117" }
color.text: { light: "#1F2328", dark: "#E6EDF3" }
color.muted: { light: "#59636E", dark: "#9198A1" }
color.accent: { light: "#2F6FEB", dark: "#4493F8" }
color.button: { light: "#2F6FEB", dark: "#2F6FEB" }
color.on_button: { light: "#FFFFFF", dark: "#FFFFFF" }
color.border: { light: "#D1D9E0", dark: "#3D444D" }
color.subtle: { light: "#EFF2F5", dark: "#262C36" }
# Quote family names with spaces in single quotes: "'Helvetica Neue',Arial,sans-serif".
font.sans: "-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif"
font.mono: "ui-monospace,SFMono-Regular,Menlo,Consolas,monospace"
# Sizes in px. Templates cannot do arithmetic, so derived sizes get
# their own token: keep size.content equal to size.width - 2 * size.side.
size.width: 560 # the message column
size.side: 32 # side padding of every component
size.side_mobile: 16 # side padding below 600px
size.content: 496 # size.width - 2 * size.side: the widest image
size.block: 16 # space below every Markdown block
size.gap: 32 # space below a component with no blocks
size.text: 16
size.line: 24
size.small: 13
size.small_line: 20
size.h1: 28
size.h1_line: 36
size.h1_mobile: 24
size.h1_mobile_line: 32
size.h2: 20
size.h2_line: 28
- Names start with an ASCII letter, followed by letters, digits,
_,-and.. Thecolor.,font.andsize.prefixes are a convention, not a rule. - A colour is a mapping with
light,darkor both.{{token}}gives the light value and{{dark}}the dark one. - Any other token is a single value.
- Sizes are plain integers, in px by convention: templates write
{{token "size.side"}}px. Templates cannot do arithmetic, so a derived size gets its own token, as the comment abovesize.widthsays.
Keep token values CSS-safe
Token values are written into styles.css unescaped, so a value may not be empty or contain <, >, {, }, ;, ", \ or a control character. A rejected token is then unknown to everything that names it:
$ lttr kit check ./emailkit
emailkit/kit.yaml:26:14: tokens.font.mono: unsafe character '"' in "\"Menlo\",ui-monospace,SFMono-Regular,Menlo,Consolas,monospace"
emailkit/kit.yaml:56:17: spans.mono.font: unknown token "font.mono"
emailkit/kit.yaml:62:26: inline.code.font-family: unknown token "font.mono"
Quote font family names with single quotes. The tutorial kit swaps Plain's system stack for a quoted one (this excerpt ends before the sizes, which are Plain's, unchanged):
tokens:
color.canvas: { light: "#F6F8FA", dark: "#010409" }
color.surface: { light: "#FFFFFF", dark: "#0D1117" }
color.text: { light: "#1F2328", dark: "#E6EDF3" }
color.muted: { light: "#59636E", dark: "#9198A1" }
color.accent: { light: "#1A7F37", dark: "#3FB950" } # was Plain's blue
color.button: { light: "#1A7F37", dark: "#1A7F37" } # was Plain's blue
color.on_button: { light: "#FFFFFF", dark: "#FFFFFF" }
color.border: { light: "#D1D9E0", dark: "#3D444D" }
color.subtle: { light: "#EFF2F5", dark: "#262C36" }
# Quote family names with spaces in single quotes: "'Helvetica Neue',Arial,sans-serif".
font.sans: "'Helvetica Neue',Arial,sans-serif" # was the system stack
font.mono: "ui-monospace,SFMono-Regular,Menlo,Consolas,monospace"
A quoted stack works because Plain's templates write fonts through the core style function, which accepts paired single quotes: {{style "font-family" "font.sans"}} renders font-family:'Helvetica Neue',Arial,sans-serif;. Written straight into a style attribute as font-family:{{token "font.sans"}}, the same token would be rejected by html/template's CSS filter and render as ZgotmplZ, which the lint reports:
$ lttr kit check ./emailkit
emailkit/samples/receipt-free.md: html: contains "ZgotmplZ" at byte 5409 and 1 more (a value html/template rejected)
emailkit/samples/welcome.md: html: contains "ZgotmplZ" at byte 5396 (a value html/template rejected)
lttr kit check: ./emailkit: 2 problems
Write colours in any CSS syntax. A colour token may be #1A7F37, a keyword such as white, or a function: rgb(26 127 55), rgba(31,35,40,0.9), hsl(135 60% 50%). Plain, and every kit copied from it, writes colour tokens into style attributes through the same style function, {{style "color" "color.accent"}}, so a functional colour reaches the HTML intact. A colour in an HTML attribute such as bgcolor="{{token "color.canvas"}}" is escaped as text and is fine too. Only a colour written straight into a style attribute, as color:{{token "color.accent"}};, is rejected when it holds (, and the lint catches it. With color.accent: { light: "rgb(26 127 55)", … } and one link written that way in the footer:
$ lttr kit check ./emailkit
emailkit/samples/receipt-free.md: html: contains "ZgotmplZ" at byte 13687 (a value html/template rejected)
emailkit/samples/welcome.md: html: contains "ZgotmplZ" at byte 10556 (a value html/template rejected)
lttr kit check: ./emailkit: 2 problems
The core button function is stricter: its fill and text colours must be #hex or a keyword, and anything else renders as ZgotmplZ. Plain's button component doesn't use it.
Resolve token names
A token name can stand in for a value in several places. Each resolves it the same way: a value that names a token becomes the token's value, the light value for a colour.
| Where | Example | A name that is not a token |
|---|---|---|
{{token "name"}} in a template | {{token "size.text"}} | A load error, token: unknown token "size.txt" (did you mean size.text?). A token with only a dark value is an error too |
{{dark "name"}} in a template | {{dark "color.canvas"}} | A load error. So is a token with no dark value |
{{style "prop" "value" …}} in an HTML template | {{style "font-family" "font.sans"}} | Written as a literal CSS value. A literal that reads as a token name in one of the kit's token groups, such as "color.txt", must be a token: a load error, style: unknown token "color.txt" (did you mean color.text?) |
spans and inline in kit.yaml | link: { color: color.accent } | A dotted name that names no token is an error (unknown token, with a suggestion when a token is close). Anything else is a literal CSS value |
spans.*.size and component spacing | bottom: size.gap | Must be a non-negative integer, or a token whose value is one |
token, dark and var check a literal argument when the kit loads, and so does style for a literal value shaped like a token name. An argument computed in the template is checked when it renders.
Set vars
Vars are string constants for copy: the brand, the site URL, the sender's address.
vars:
brand: Example
site: https://example.com
company: Example Inc.
address: 100 Main Street, Springfield
asset_base: https://example.com/assets
- Templates read them with
{{var "brand"}}. An unknown name is a load error:var: unknown var "compnay" (did you mean company?). Config.Varsoverrides them per renderer. Every key must be a kit var, and a value may not contain<,>or a control character, because vars can reachstyles.css.asset_basealways exists, even whenkit.yamldoes not declare it.Config.AssetBasesets it, notConfig.Vars. Plain builds its logo URL from it:{{var "asset_base"}}/logo.png.
See Profiles and config for Config.
Style spans and inline Markdown
spans lists the classes a template may use in [text]{.class}. inline styles the Markdown inlines:
spans:
muted: { color: color.muted }
accent: { color: color.accent }
mono: { font: font.mono }
small: { size: size.small }
bold: { weight: bold }
inline:
link: { color: color.accent, text-decoration: underline }
code: { font-family: font.mono, font-size: 14px, background-color: color.subtle, padding: 1px 4px }
strong: { font-weight: 600 }
strike: { color: color.muted, text-decoration: line-through }
- A span sets any of
color,fontandweight(a token name or a literal) andsize(px, or a size token). Class names match[a-z][a-z0-9_-]*. A span with several classes combines them, later classes winning. inlinehas one entry per inline kind:link,code,strong,emandstrike. Each is an ordered mapping of CSS properties ([a-z-]+) to a token name or a literal, written into the element'sstyleattribute in that order.- A class that
spansdoes not declare is a compile error in the template:unknown span class ".loud". See Actions and spans.
Cap buttons and links
limits caps the :button and :link inline components across a whole template. Plain sets none. With limits: { button: 1 }, a second :button is a compile error:
$ lttr lint -kit ./emailkit templates/launch.md
templates/launch.md:12:1: more than one :button in the template
A component can set its own limits for the buttons and links inside its content. See Component schemas.
Register Go types
types lists the Go types that component bindings may name. The tutorial kit binds one:
# Go types components may bind. The kit's Go package registers each one
# with kit.Types, so this kit loads from Go, not from the CLI.
types: [Invoice]
Every listed name must be registered from Go with kit.Types, or the kit does not load:
$ lttr kit check examples/tutorial/kit
examples/tutorial/kit/kit.yaml:12:9: types: "Invoice" is not registered
examples/tutorial/kit: kit directories load without Go types; check kits that bind Go types from Go (see README)
See Go types and funcs.
Declare frontmatter keys
frontmatter declares keys a Markdown template may set in its frontmatter, besides the core template, profile, subject, preheader and from. Each key is typed exactly like a component attribute (type, required, required_with, default, values; see Component schemas). For example, frontmatter: { campaign: { type: enum, values: [spring, autumn] } } makes campaign: a checked key:
$ lttr lint -kit ./emailkit templates/spring.md
templates/spring.md:5:1: frontmatter: "campaign" must be one of spring, autumn
- Layouts and component templates read the value as
.Doc.Front.campaign. Blocks do not see.Doc. - An unset key takes its default, else the zero value of its type:
""for text, url and enum, an empty list,0,false, or a nilinline. So{{if .Doc.Front.campaign}}is false, and printing it writes nothing, never<no value>. - Redeclaring a core key is a load error:
frontmatter: "subject" is a core key.
See Frontmatter for the template side.
Next steps
- Component schemas:
component.yaml, key by key. - Templates and views: where
token,dark,varandstylefit.
What is a kit
A kit is a directory of YAML and Go templates that gives lttr its look and its components. The files, how Go loads them, and the two kits lttr ships.
Component schemas
component.yaml, key by key — attributes, bindings, content rules, children, ordering, limits and spacing — and the compile errors each rule produces.