[Specification](https://komalang.org/spec/) · Chapter 5 / 7

# Styles and themes

Attributes say what an element is and where it goes; its look comes from the theme, its classes and its style.

## Document CSS

A document's CSS is written in `css:` in the document settings (`===`). The value is read by its YAML shape, never guessed from its content.

```
===
title: Talk
css:
  - styles/talk.css
  - |
    title { color: #294d73; }
    page.dark { background: #17212d; color: white; }
===
```

- A literal block (`css: |`, `|-`, `|+`) is CSS written in the document.
- A one-line string ending in `.css` (in any case) is the path of a CSS file inside the document's folder. It may be quoted. It is relative, separated by `/`, with any leading `./` dropped. A URL, anything starting with `/`, and anything with `\`, an empty part or `..` is not a path.

- A sequence lists those two kinds, applied in the order written, joined as one CSS.
- Any other value (a folded `>`, a one-line string not ending in `.css`, a number, a map, an empty sequence, a sequence with a non-path string) is reported as `bad-value`, and none of it is applied.

CSS files are read under the same rules as images: only inside the document's folder, checked by their real path, never leaving the folder through `..` or links, UTF-8 and 256 KiB at most. A file that cannot be read is reported as `css-file-unavailable` (error), and only that file is left out. `url()` inside a file is relative to the document's folder. CSS from a URL is never read. `@import` is not read, in written CSS or in files, and is reported. Scoping, `page.class` and the checks are the same for written CSS and files.

Page settings have no `css:` (`setting-out-of-scope`); there is no per-page CSS. A page's look comes from the `class` in its page settings, put on the page's outer frame and selected by `page.class` in the document's CSS. No other selector of pages is added, except that a page's edge lines may be written as declarations in that page's `style:` ([Page-edge lines](#page-edges)). Line declarations on `page { … }` (`border` and the per-side `border-*`) apply to a line layer inside the page, not to its outer frame, and move nothing on the page.

`:::` followed by attributes opens a memo ([Memos](https://komalang.org/spec/elements/#memo)); otherwise it is a reserved mark with no use. A bare `:::` line in column 0, in the document's preamble or on a page, isolates its source up to the matching `:::` (or the next `+++` in column 0) and is reported as `misplaced-scoped-block`, pointing to the document's `css:`. A `::: name` line at the root is reserved for future declarations, reported as `unsupported-declaration`, and isolated the same way. An indented `:::` inside an element is Markdown text.

Tag, ID, class, compound and list selectors and `*` match only the document's Koma elements. The page itself is selected with `page { … }` and `page.class { … }`, written like an element. `page` is the name of a virtual parent, reserved as a tag name and never written in the source (a written `[page …]` is `unknown-tag`). `page` takes one class at most; an ID, two or more classes, combinators or pseudo-classes are reported and the block is not applied. The automatic page number is selected with the reserved name `page-number`, as `page-number { … }` (also inside `@layout name { … }`); it takes neither ID nor class, and if given one, the block is reported and not applied. `page-number` is reserved as a tag name and cannot be a custom tag. The page's three bands are selected the same way with the reserved names `page-header`, `page-body` and `page-footer` ([Layout grids](#layout-grid)): each alone in its rule, with neither ID nor class, also inside `@layout name { … }`; they hold no Markdown parts and cannot be custom tags. A grid written on `page` itself is reported as `legacy-page-grid` and not applied. `@slide { … }` and `@page-number { … }` are reported and not applied, like any unknown at-rule. Looks for one layout go inside `@layout name { … }` ([Looks for one layout](#layout-rules)). Unsupported combinators, attributes and pseudo-classes are reported, and no block is partly applied. No outside resource or executable code is loaded.

### Looks for one layout

`@layout name { … }` makes rules in the document's and the theme's CSS apply only to pages of one layout.

#### How to write

Write the layout's name after `@layout` ([Page layouts](https://komalang.org/spec/structure/#layouts), including a theme's named layouts), and ordinary rules inside `{ … }`. For example: `@layout cover { subtitle { font-size: 46px; font-weight: 400; } }`. `@layout cover { page { … } }` applies to the pages of that layout themselves. `padding` written on `page` decides the area of the flow directly on the page ([Placement](https://komalang.org/spec/semantics/#placement)).

#### Example

```koma
===
css: |
  @layout cover { subtitle { color: #b42318; } }
===

---
layout: cover
---

[title: The book swap]
[subtitle: Only the cover's subtitle is red]

+++

[title: An ordinary page]
[subtitle: The ordinary page keeps its default colour]
```

> Page 1: A cover page. The subtitle under the title The book swap is drawn in red.
>
> Page 2: An ordinary page. Its subtitle keeps the default colour.

#### Details

- It works the same way for every tag (`title`, `subtitle`, `label`, custom tags, classes, IDs). No tag has an exception of its own.
- Only rules may go inside. There is one name, unquoted. Declarations written directly inside, nested `@` rules, and a missing name or more than one are reported, and the block is not applied.

- When a rule for all pages and a rule of the layout both match the same element, the layout's rule wins whatever the order written (it weighs one class more).
- The official themes use this to give the cover's subtitle the look of the cover subtitle’s look (lead size, not bold, body colour).

### Markdown parts in elements

The document's and the theme's CSS can select the parts Markdown makes inside Koma elements (paragraphs, list items, headings, pictures, table headers and cells) by their HTML names.

#### How to write

Write the part's name after a selector of Koma elements and a space (`box.tint p { … }`, `callout li { … }`). A part's name alone selects it inside any element (`h3 { margin-block-end: 0.3em; }`). `+` between two parts selects the one right after (`p + p { margin-block-start: 0.6em; }`).

#### Details

- Parts: `p`, `li`, `h3`, `img`, `th`, `td`. `caption`, `figcaption` and `table` are selected as before. The list names `ul`, `ol`, and `dl` apply only on either side of `+`, alone or in a part-only `:is()`. A bare `ul`, a bare `:is(ul)`, or an element followed by `:is(ul, li)` does not select list containers. Generated `page` and `page-number` have no Markdown parts. Report these forms as `part-selector-unmatched` and omit that rule alone.
- Forms: `[selector of Koma elements] part`, or `part + part` (each a name, or `:is()` listing part names only). A part takes no ID, class, pseudo-class or attribute. `>`, `~`, a part after a part, and a Koma element after a part are not applied.

- The part names are reserved and never name a tag.
- Only what an element's own text writes in Markdown is selected: not the footnotes Koma draws, nor a frame's own text (`label`, `title` and so on), which its tag selects.

- In specificity a part counts as one type selector. The document's CSS is outside the theme layer and always wins over the theme.
- Other HTML names inside elements (`strong`, `a`, `blockquote` …) are not selected; text is styled by text classes ([Text inside elements](https://komalang.org/spec/text/#inline-markup)).

- A Markdown name written in a form that selects nothing (`ul { … }`, `box > li { … }`, `strong { … }`) leaves out that rule alone and is reported as `part-selector-unmatched`, naming the forms that work. Report at the document CSS selector, or at the `css:` setting when it references the stylesheet. Other rules apply. Editing, presentation, HTML, PDF and images share rendering. PowerPoint copies the result’s sizes, colours and spacing.

`@keyframes` in a verified theme and in document CSS are applied to the editor, presenting and HTML with their names kept apart per page. Only document CSS is separated per page; the order of theme then document, specificity, `!important` and ordinary `var()` are kept. CSS that cannot be separated is not partly applied, and the reason is given. PDF, PNG and PowerPoint are still output in the base style without animation, and say so. Stilling other media such as video is not promised.

## Themes

### What a theme decides

A theme decides the look of the slides and the default placement of the layouts.

- Theme CSS uses Koma selectors such as `theorem#result.important` and `page { … }`. Declare shared custom properties on the page and use the public theme tokens listed in [Public variables](#public-variables).

#### How to write

Choose it with `theme:` in the document settings ([Choosing a theme](#theme-reference)). Positions and sizes written in the document take precedence over the theme's defaults.

#### Details

- **What is published**: The public styling surface comprises tag, ID and class selectors for elements, Markdown component selectors ([Markdown parts in elements](#markdown-parts)), ordinary CSS declarations, and the variables listed in [Public variables](#public-variables).
- **Official themes**: default, talk and report. A theme (look and layouts) is kept apart from templates for a document's structure.

- **Math face**: the document YAML of theme.koma may set `mathFont: fira`, `mathFont: stix2` or `mathFont: newcm` (New Computer Modern Math). Without it, Fira; an unknown value is reported. Within a theme, inline and display math use the same face. The official themes use newcm for default, and Fira for talk and report. `--math-font: fira|stix2|newcm` in an element's `style` draws only the math inside that element in a face other than the theme's. Math is drawn to suit the kind of face of the text it sits in; only words in `\text{…}` follow the surrounding weight. Surrounding bold or italic adds no formatting to math. In every theme, bold and italic written explicitly in TeX are kept. The math data, licences, size and checks are recorded in the math boundary.
- **Text faces**: the local Noto assets are used for the default sans and code, and for serif when named. Licences, coverage, weight matching and the boundary of output are recorded in text faces. Choosing an element's role is the format panel’s rules.

- **Colours** (common to the three official themes): each theme writes on `page` the primary colour `--koma-primary`, the text on it `--koma-on-primary`, the secondary role `--koma-secondary` and its text colour `--koma-on-secondary` ([Colour roles](#colour-roles), [Text on role colours](#on-role-colours)), the line `--koma-line`, the body colour, the tint background derived by [Soft tint](#soft-tint), the figure caption colour `--koma-caption-color` (the body colour), and the footnote colour `--koma-footnote-color` and muted colour `--koma-muted` (both ink-2). `label` and `box.citation`, footnotes, footers and muted text use the same weak text colour (ink-2); figure captions, table captions and table notes the body colour; `page-number` a lighter grey; and an ordinary page's `subtitle` the primary colour. ink-2, the page-number grey and the soft ground are made from the primary's hue with default's saturation and default's contrast on white (ink-2 about 6:1, the page number about 3.4:1, the soft ground about 1.09:1). Body text and ink-2 reach 4.5:1 or more on the ground and the soft ground, and text on the primary colour 4.5:1 or more.
  - default: body `#16161d`, ink-2 `#5f626f`, page number `#888b98`, soft ground `#f4f5f9`, primary `#2d287f`.
  - talk: body `#17212d` (16.3:1 on white), ink-2 `#576564` (6.1:1), page number `#7d8f8d` (3.4:1), soft ground `#eff6f6`, primary `#0f6b63` (white text 6.4:1).
  - report: body `#17212d` (16.3:1), ink-2 `#5c646c` (6.0:1), page number `#858d95` (3.4:1), soft ground `#f3f5f8`, primary `#3b4754` (white text 9.5:1).
  - One grey for weak text: label, `box.citation`, footnotes, footers and muted text (`.muted`) are all ink-2. Only the page number stays a lighter grey. The default of themes that are not built in (`slide.css`) is one colour too (`#595959`), and `--koma-muted` points to `--koma-footnote-color`.
  - Figure captions, table captions and table notes take the body colour. Grey is left only to footnotes, footers, page numbers and labels. The three official themes set `--koma-caption-color` to the body colour, and table notes use `--koma-caption-color` (or else the surrounding text colour). HTML, PDF and PowerPoint agree.

- **Sizes follow the frame**: the body size is written in `--koma-font-size` (which the page kinds of [Values per kind of page](#page-kind-values) may change), figure captions are `figure { font-size: 0.7em }`, `box.citation` is `0.7em`, and tables write no size and inherit from the frame. So that a `font-size` on a box reaches the figure captions, sources and tables inside, none of these has a fixed px size.
- **Space between list items**: each theme writes on `page` a wide value `--koma-item-gap: 0.8em` and a narrow value `--koma-item-gap-min: 0.35em` (the names `--koma-list-item-gap` and `-min` are not read). Items normally take the wide value, and lists inside an item half of it. When a slide's frame does not fit, the gap narrows continuously to the narrow value before the text gets smaller. When a theme or document sets both to the same value, nothing narrows. Documents and posters take their kind's fixed value instead, 0.25em, which never narrows ([Values per kind of page](#page-kind-values)). Being in em, they follow the text size of the frame or box. The table of contents layout `outline` takes no space from line height; the body's wide value is default 1.05em, talk 0.67em, report 1.03em (the narrow value stays 0.35em, narrowing when it does not fit).

- **label**: the default weight is 400 (regular). A label is a small note above the title; in regular weight and the weak text colour, it does not compete with the (bold) title. Being regular, part of it can be bold, as in `**Study I** multi-qubit control`. No letter spacing is added. The three official themes keep 400 for the labels of ordinary pages and the cover, and make only a section opener's label a chapter heading, 700 in the primary colour ([Cover and section pages](#cover-and-section)).
- **Page number and footer**: the page number's default colour is the same grey as the label at the top left. A theme can set its colour with `page-number { … }` ([Page settings](https://komalang.org/spec/structure/#page-settings)). A page's `footer` defaults to the same weak text colour as footnotes (`--koma-footnote-color`). Both stand in the footer band ([The bottom band](#bottom-band)), which a theme selects as `page-footer { … }`; the header and the body are `page-header` and `page-body` ([Layout grids](#layout-grid)).

- **Default line breaking and typesetting** (a theme or the document's `css:` can change them with bare selectors such as `page`, `box`, `table` and `callout`; table captions are selected as `caption` and figure captions as `figcaption`, as in HTML, with no ID or class; the default rules have no specificity):
  - Between paragraphs: in slide bodies and boxes, paragraph, list and definition-list boundaries use the same proportional gap and automatic fitting as list items, using `--koma-item-gap` and `--koma-item-gap-min`. Documents, posters, captions, table notes, footnotes, and presenter notes use 0.5em between paragraphs, wider than a document's or a poster's list items ([Values per kind of page](#page-kind-values)). Keep the first and last edges clear. Authors may set adjacent-part CSS or explicit `--koma-paragraph-gap`. Nested list spacing follows the editing view’s rules. Display math, code, tables, quotations, diagrams, figures and grids take the block gap above and below, which closes up with the item gap ([HTML elements and reading order](https://komalang.org/spec/semantics/#html-elements)); elements in a flow use the flow gap ([Columns and rows](https://komalang.org/spec/semantics/#split)). Editor blank lines and HTML, PDF, and PowerPoint spacing agree.
  - Between caption text and the image or table edge, use 28 px by default, 12 px on articles, and 40 px on posters. Themes and documents can set `figcaption { margin-block-start: … }` and `caption { margin-block-end: … }`. Table notes sit at 75% of this gap below the table.
  - Text is broken so that the last line is not left with one word or character (`text-wrap: pretty`). Titles and subtitles are broken into lines of even length (`balance`).
  - When the document's language is Japanese (`lang: ja`), text breaks at phrase boundaries, table cells included (`word-break: auto-phrase`). But frames, elements and captions whose inner width is less than 8 characters of their text break anywhere (an extra line is better than a word cut in the middle).
  - Where the browser has no `auto-phrase` (as in the macOS app's WebKit view), the drawn text of a Japanese page gets a `<wbr>` at each phrase boundary from BudouX, the model Chromium's own phrase breaking uses, and those elements break only there (`word-break: keep-all; overflow-wrap: anywhere`, with no specificity). It is fetched on first need, kept for offline use, and never loaded where the browser breaks phrases itself; the pages are fitted again once it arrives. Math, code, preformatted text, drawings, editors and URLs get no breaks, nor does a place before a closing mark or after an opening one, and narrow blocks keep breaking anywhere. The source, tidying, the editor and copied text are unchanged.
  - Tables break only words longer than the column, anywhere (`overflow-wrap: anywhere`, on the table elements).
  - When the last line of a Japanese paragraph (paragraphs and list items of frames and elements in a `lang: ja` document) has two characters or fewer, the paragraph is drawn again narrower by 1 em at a time, up to 3 em, and the width that leaves at least three characters on the last line without adding a line is used. If none fits, the original width stays.
  - In paragraphs with kana or kanji, a line never breaks after a hyphen inside a Latin word (such as `heavy-hex`) (when drawing, a U+2060 goes after the hyphen; the source and tidying are unchanged).
  - Inline math stays on the line of the opening bracket right before it, and of the closing bracket or punctuation right after it (`（`, `）`, `、`, `。` and so on). Without an opening bracket, the one phrase right before it (a word and the kana after it, with any space or U+00A0 between; for example 約 in 「約 $1.57\Delta$」) stays on the math's line.
  - A space between a number and a unit (`GHz`, `ns`, `dB`, `mK`, `%` and so on; the list is in one place in the code) is drawn as a non-breaking space. The source and tidying are unchanged. A U+00A0 written stays.
  - Full-width brackets at the ends of lines on Japanese pages have their space trimmed in the three official themes (`text-spacing-trim: trim-both`, [Brackets at line ends](#bracket-spacing)).
  - HTML, PDF, images and editing break lines the same way.

### The source of a theme

A theme's original is a `.koma` document, with the fonts and images it needs beside it.

#### How to write

Write the theme in `theme.koma` and put its fonts and images in the same folder. How to write a theme document is in the section on themes whose original is a `.koma` document.

#### Details

- A folder that uses `theme.css` and the like is treated as another format.
- No script is run.

- How far a document can pin the version of the theme it uses is recorded in the record of pinning. There is no mechanism for managing or sharing themes.
- A theme folder's `layouts/` is not read, in either format. Its files are not used for drawing or checking, cannot be reached from the theme's CSS or a theme document's `css:` (they are reported as unavailable), and are not put into new packages, frozen themes or sharing copies. In a theme frozen earlier, its bytes are kept for checking the freeze but not read or counted toward size limits, and the rest of the theme applies. `koma lint` and `koma check` report a `layouts/` folder in the document's theme folder (for a theme document, its own folder) as `theme-layouts-unused` (a note). The source and the files are not changed.

### Choosing a theme

A document points to its theme with `theme:` in the document settings.

#### How to write

A built-in theme by name (`theme: default`, `theme: talk`, `theme: report`), a folder beside the document by relative path (`theme: ./themes/my-theme`), a URL by its address. A document without `theme:` is drawn with the default theme, `default`.

#### Details

- The default theme is named `default`. The UI shows Default in English and `標準` in Japanese.
- The app (a new document, choosing a theme) and `koma new` write `default`.

- A theme at a relative path travels with the document.
- A theme at a URL is fetched and kept locally (it works offline).

### Checking a theme's CSS

A theme's CSS is checked when it is loaded, so that other people's themes can be used safely.

#### How to write

A theme's CSS is ordinary CSS. The selectors written are confined to the slides, and outside resources are limited to the theme's folder and fonts.

#### Details

- Selectors are confined to the slides; the app's own screen cannot be changed.
- Outside resources (`@import`, outside `url()`) are limited to the theme's folder and fonts.

- What the check refuses is left out alone, as a browser leaves out a rule it cannot read: a rule with a selector that is not a Koma selector, a nested rule, an at-rule a theme may not use, a declaration that loads from outside the theme's folder, or text the CSS parser cannot read. The rest of the theme applies: its other rules, its layouts and its tags.
- Each is reported where it is written, as `theme-css` (a warning): at its line in `theme.koma` when the theme document is checked; with its style sheet's name and line, at the `css:` line, for a sheet the theme names; and with the theme's file and line, at the `theme:` line, when a document is checked. `koma lint`, `koma check` with or without `--layout`, and the language server report it; the app lists it with the theme's problems, naming the file and line. An export is refused while one remains, as it is for a document's CSS.

### The theme layer

A theme's CSS is drawn in the CSS cascade layer `koma-theme`, so the document's CSS and elements' `style` always win over the theme.

#### How to write

Layers are never written by hand. The document's CSS (`css:`), page edge lines in page settings' `style:` ([Page-edge lines](#page-edges)) and elements' `style` ([Elements](https://komalang.org/spec/elements/#element)) sit outside the layer, so they win whatever the specificity of the theme's rules (the theme CSS cascade layer).

#### Details

- In the layer: Koma's built-in slide rules (the base shared by every theme), the CSS of theme documents (official themes, themes in the document's folder, `theme.koma`), rules made from theme data (`theme.json`), and the per-page rules made from the theme's `@keyframes`. Inside the layer, specificity and order written decide (base, theme, theme data).
- Between pieces of document CSS, and between document CSS and elements' `style`, the ordinary CSS cascade holds (`style` wins).

- `!important`: as CSS defines, `!important` inside the layer beats `!important` outside it. What built-in rules fix with `!important` (measuring table widths, the left-only line of a `bar` box) does not change even with `!important` in the document. `!important` in an element's `style` beats `!important` inside the layer too.
- Neither a theme's nor a document's CSS may write `@layer` (like other unknown at-rules, it is reported and not applied). Only Koma decides the layer's name and order.

- The editor, presenting and the presenter view, theme previews, export (PDF, PNG, PowerPoint, HTML, `koma export`), the try-it embeds and the VS Code preview draw alike. While a theme document is open and being edited, its `css:` goes in the layer too. HTML export keeps the layer.

### Public variables

The CSS variables a theme or a document may set are the public ones listed here; every other look is written as ordinary CSS.

#### How to write

Public variables go on `page` (and its `@layout`): `page { --koma-primary: #2d287f; --koma-item-gap: 0.8em; }`. Anything else is a selector and ordinary declarations: `box.tint { padding: 0.75em 1em; border-radius: 12px; }`, `figcaption { margin-block-start: 28px; }`, `th { background: #f4f5f9; }`.

#### Details

- Public variables can be set in theme and document CSS.
  | Variable | Meaning | Related rule |
  | --- | --- | --- |
  | `--koma-primary`, `--koma-on-primary` | Primary colour and text over it. Koma chooses the text colour when omitted. | [What a theme decides](#theme), [Named styles](#style-classes) |
  | `--koma-secondary`, `--koma-on-secondary` | Secondary colour and text over it. Koma chooses the text colour when omitted. | [What a theme decides](#theme) |
  | `--koma-line` | Lines in `outline`, `bar`, tables, and divisions. | [What a theme decides](#theme), [Named styles](#style-classes) |
  | `--koma-muted`, `--koma-footnote-color`, `--koma-caption-color` | Muted text, footnotes and footer, and figure captions. | [What a theme decides](#theme) |
  | `--koma-chart-1` to `--koma-chart-6` | Chart series colours, independently of the primary and secondary roles. | CHT |
  | `--koma-item-gap`, `--koma-item-gap-min` | Maximum and minimum list spacing used for fitting a slide; a document's or a poster's fixed list spacing ([Values per kind of page](#page-kind-values)). | [What a theme decides](#theme) |
  | `--koma-font-size` | Body font size, which can vary by page kind. | [What a theme decides](#theme), [Values per kind of page](#page-kind-values) |
  | `--koma-padding-block`, `--koma-padding-inline` | Default page-kind padding. Set page-specific padding with `page { padding }` ([Placement](https://komalang.org/spec/semantics/#placement)). | [Values per kind of page](#page-kind-values) |
  | `--koma-gap` | Default split gap. | [Columns and rows](https://komalang.org/spec/semantics/#split) |
  | `--koma-transition-duration` | Duration of a page transition, 400 ms by default. | [Motion durations](#motion-durations) |
  | `--koma-step-duration` | Duration of an element's entrance effect, 250 ms by default. | [Motion durations](#motion-durations) |
  | `--math-font` | Math face within an element, set in its `style`. | [What a theme decides](#theme) |

- Unlisted `--koma-*` and `--_koma-*` variables are internal. Their names and meanings can change.
- Former public variables are ignored. There is no aliasing or `legacy-css-variable` migration. Use the current primary and secondary role pairs, `.mark` for highlights, and `box.tint` or `callout.tint` for tint. Use the relevant CSS declarations for spacing, margins, table appearance, box padding and radius, and title typography. Keep the rules for `--koma-heading-rule-*` ([Cover and section pages](#cover-and-section)) and `--koma-ja-text-spacing-trim` ([Brackets at line ends](#bracket-spacing)).

- Public variables express colour relationships or feed calculations such as fitting and page-kind defaults. Use ordinary CSS declarations for a single component's appearance.

### Colour roles

Themes use `--koma-primary` and `--koma-secondary` as colour roles for built-in styles.

- Primary is the document's principal colour. Default uses `#2d287f`, Talk `#0f6b63`, and Report `#3b4754`. It appears in `[text]{.primary}` ([Role classes](#role-classes)), the ordinary page `subtitle`, section `label`, `fill` boxes, `.chip` backgrounds, the table `accent` class, shapes and lines using `.primary`, tint ([Soft tint](#soft-tint)), and chart series one.
- Secondary is `#edb909` in all three official themes. It colours the left line of `bar` and its 8% background, as well as highlight `==…==` or `.mark`. Highlights mix 50% secondary into the page background using `color-mix(in srgb, var(--koma-secondary, var(--koma-primary)) 50%, var(--koma-background, #fff))`. Secondary also applies to `.secondary` shapes and lines, chart series two, and the markers of single-series charts. If secondary is absent, use primary.

- With no explicit `--koma-chart-1` to `--koma-chart-6`, series one and two use the role colours. Series three through six alternate the two colours at lighter 35% and 60% mixes with the page background.

### Text on role colours

Text placed on a role colour uses `--koma-on-primary` or `--koma-on-secondary`. When omitted at the rule or element that sets the role colour, Koma chooses whichever of white (`#ffffff`) or the page text colour gives the higher WCAG contrast ratio. If the chosen colour still falls below 4.5:1, `role-contrast` reports a note without altering rendering.

### Soft tint

Soft tints (`.tint` and plain callouts) mix `--koma-primary` at 6% into the page background (`color-mix(in srgb, var(--koma-primary) 6%, var(--koma-background, #fff))`) as an opaque fill.

### Role classes

Official themes provide `.primary` for primary-coloured inline text (`[word]{.primary}`) and `.primary` / `.secondary` for shapes and lines. Inline text has no `.secondary`, and boxes/callouts attach no built-in look to `.primary` or `.secondary`.

### Motion durations

Two CSS variables set motion duration. The user's reduced-motion preference disables the effects.

#### How to write

Set the variables on `page` or its `@layout`. For example, `page { --koma-transition-duration: 400ms; --koma-step-duration: 250ms; }`.

#### Details

- `--koma-transition-duration` controls the page transition and defaults to `400ms`. Use the value in effect on the incoming page.
- `--koma-step-duration` controls an entrance effect and defaults to `250ms`. Use the value on the outermost element entering at that step ([Entrance effects](https://komalang.org/spec/elements/#entrance-effects)). Normal CSS inheritance lets the page set the default. Element `style` or document CSS can override an element and its descendants.

- Use CSS times in `ms` or `s`. `0s` is immediate. Negative or invalid values fall back to the default without a diagnostic.
- `fade` is linear. `push` and `rise` use `ease-out`. Koma fixes easing.

- Under `prefers-reduced-motion: reduce`, transitions and steps are immediate. The playback device's preference takes precedence for presentation and HTML. Themes and documents cannot override it.
- Default, Talk, and Report rely on the defaults.

### Flow columns

A theme or document may write the multi-column and fragmentation properties of CSS on Koma elements and `page`, and authored block margins between items in a flow are kept.

#### Example

```koma
===
css: |
  box.sheet {
    columns: 2;
    column-gap: 36px;
    column-rule: 1px solid #c3c9d0;
    row-gap: 16px;
  }
  .span { column-span: all; }
  box.item { break-inside: avoid; }
===

[box .sheet:
  [box .span:
    # Tidepool field sheet

    South Cove · low tide at 14:20
  ]
  [box .item .outline:
    **1. High shore**

    Count barnacles in a 20 cm square near the dry line.
  ]
  [box .item .outline:
    **2. Mid shore**

    Note limpets and dog whelks under damp ledges.
  ]
  [box .item .outline:
    **3. Lower pools**

    Record water temperature $T$ and shade cover before moving on.
  ]
  [box .item .tint:
    **Reminder**

    Leave turned stones face down so organisms underneath stay shaded.
  ]
]
```

> Field sheet titled Tidepool field sheet spanning two columns, with four numbered cards balanced across the two columns separated by a thin rule.

#### Details

- On a container: `columns`, `column-count`, `column-width`, `column-gap`, `column-rule` and its `-width`, `-style` and `-color`, `column-fill`. On an item: `column-span`, `break-inside`, `break-before`, `break-after`.
- `gap` and `row-gap` written in theme or document CSS on an element set the space between what its flow holds, as `style="gap: …"` does ([Cards without positions](https://komalang.org/spec/semantics/#cards)); `gap` keeps its CSS meaning on the element too, so on a multi-column container it also sets the column gap.

- `margin-block-start` and `margin-block-end`, and the block sides of `margin-top`, `margin-bottom`, `margin-block` and `margin`, written on an element (not on a Markdown part or the page) add to the gap before and after it, in every flow, not only in columns. This is how a theme leaves answer space after a problem. A `margin` whose sides a variable may stand for is applied as written.
- Ruled lines are written as ordinary CSS, such as a `repeating-linear-gradient` background on the container behind items with a background of their own. There is no Koma-specific ruling property.

- Pseudo-elements and counters (`::before`, `counter-increment`) stay outside the public surface; numbers such as “Problem 1” and “(1)” are written in the source.

### Theme data

A theme's look is written in CSS alone; legacy theme data (`tokens`, `boxStyles` with look keys, `elements`) is no longer read or migrated.

#### How to write

In `theme.koma`'s `css:`, or `theme.css` for a folder theme. The display names of styles are written like `pageStyles`: `boxStyles: { quote: Quote }` (class name: display name).

#### Details

- `boxStyles` that only names classes (`quote: Quote`) is kept.

## Theme documents

A theme is edited as an ordinary `.koma` document, `theme.koma`. Opened in the editor, its frames can be edited on the canvas as samples of the layouts. Each sample page's `layout: name` setting stands for that layout, and the sample elements on it with a position and size define its frames ([Frames from sample elements](#theme-frames)). Custom tags are declared in the document YAML's `tags`, never implied by sample elements. Sample text is for previewing the theme and is never copied into documents that use it. Even when a frame of the same name as a tag is chosen by default, a tag's kind and its slot are different ideas, and the document's text, images and explicit coordinates are kept. Invalid, duplicated or unsupported names or coordinates keep their source and are reported. A theme may define the default placement of `cover`, `section`, `content` and `blank` too.

No YAML key is required to mark a document as a theme. It is opened and edited like any `.koma`, and its definitions are checked when it is chosen as a theme with `theme:` or in the app. By convention the theme's source is `theme.koma`; when a document meant as slides is chosen and lacks the layout definitions it needs, this is reported rather than guessed. A CSS-only theme needs no pages.

The `css:` in a theme document's document settings ([Document settings](https://komalang.org/spec/structure/#deck-settings): written CSS and CSS files in the theme's folder) is applied as the theme. Assets and CSS files are kept as paths relative to the theme document, and go through the same safe reading and scoping. A document selects a custom theme with a reference such as `theme: ./themes/editorial/theme.koma`. A theme folder can be pointed to as well, but two sources are never mixed. Elements on a layout page that are not frames become that layout's decoration ([Layout decoration](#theme-decoration)). Unsupported per-page CSS is reported, never mistaken as drawn.

Page styles are defined by `page.class` in the theme document's or the document's `css:`. A theme may give their display names in its document settings' `pageStyles` as class name: display name (`pageStyles: { dark: Dark background }`). Class names start with a lower-case letter followed by lower-case letters, digits and hyphens; display names are non-empty strings; anything else keeps its source and is reported. A class without a display name shows its class name. Display names of layouts are written the same way in `layoutNames`.

A theme `.koma` and a `.koma` template for documents, with content and pages, serve different purposes; making a document never changes the template. The command line can copy an official theme, or a local `theme.koma` with the images it needs, into a new folder for editing; the original theme and the document's reference are not changed, and the shared checks refuse missing files and unconfirmed fonts (editing copies records the boundary). The web menu and palette can make an editing copy too. A `theme.koma` being edited is copied with its unsaved text, and the document is never switched automatically. The theme version of a saved document can be pinned explicitly in the web app, the VS Code GUI and the command line; the limits are in the record of pinning. There is no dedicated way to create a new theme without a file name, and no GUI for managing themes. Existing `theme.css` and `theme.json` folders are not this `.koma` document format.

### Frames from sample elements

A theme's layout frames are defined by sample elements placed in the theme document.

#### How to write

On a layout page of `theme.koma` (a page whose settings have `layout:`), place elements with positions and sizes (`x`, `y`, `w`, `h`, in `%` or `px`). Each element is, as it stands, the definition of the frame of its name. `[title x=6% y=11% w=88% h=9%: sample]` is the `title` frame; `[box slot=left x=… : …]` is the `left` frame.

#### Details

- Only elements placed in frames by name (built-in tags with a default frame, custom tags declared in the document YAML, and elements with `slot=`) name a frame. A `box` without `slot`, flowing elements such as figures and tables, and unknown elements define no frame.
- The footer frame: on every layout, the footer stands with the footnotes in the footer band below the body ([The bottom band](#bottom-band)), at the frame's left edge and width; it grows upward with its content as the band does. An element whose document writes `y` or `h` is placed as written.

- When two elements define the same frame, the first is used and the second is reported as `theme-slot-duplicate`. A naming element with no position or size, a unit other than `%` or `px`, a size of 0 or less, or the same attribute written twice is not a frame definition, and is reported in the source panel as `theme-slot-no-geometry` (“Give the theme's frame a position and a size”). The source is not rewritten.
- Frames without a definition use the built-in default positions. Sample text is not copied into documents. Frames are ordered as in the sample, and new pages write frames in that order.

- Vertical order: on a layout whose theme CSS writes a grid on `page-body`, the sample's vertical position is the value the grid is made from, and the grid decides where the frame is drawn ([Layout grids](#layout-grid)). The sample frames remain for the horizontal position and width, for the position on layouts without a grid, and as the way to edit the sample on the canvas.
- Page edge lines: `page { border-bottom: … }` and `@layout name { page { … } }` in the theme's CSS draw a line at the edge of every page or of a layout's pages ([Page-edge lines](#page-edges)). The line is drawn inside the page and moves neither frames nor the bands. PowerPoint looks the same.

- The padding: `page { padding }` and `@layout name { page { padding-… } }` in the theme's CSS decide the room around the page's header, body and footer bands on that layout's pages, and so the flow's area, which fills the body ([Placement](https://komalang.org/spec/semantics/#placement), [Layout grids](#layout-grid)). They move no frame placed by its sample's `x` and `y`. The built-in themes (`default`, `talk`, `report`) align left and right with the body frame's sides (5%, 7%, 3.5%); on each layout with a grid they write its first frame's top as the top padding ([Layout grids](#layout-grid)). Elsewhere the top stays the page kind's default and the bottom is the page number's margin, with the footer band keeping the rest of the kind's bottom padding ([The bottom band](#bottom-band)), and the flow starts at the body's top left.

### Layout decoration

A layout's decorations are elements on a layout page of the theme document that name no frame.

#### How to write

On a layout page of `theme.koma`, place a `box`, `shape`, line, figure or the like with neither `slot` nor a frame name. There is no special notation. On every page using that layout, they are drawn at the written position and size, behind the page's edge lines ([Page-edge lines](#page-edges)) and its content.

#### Details

- They cannot be selected or moved from a document, and do not appear in the document's source panel. To change them, edit the theme. When the theme document itself is open, decorations are ordinary elements to edit. Speaker notes are never decorations.
- Whether covers and section openers have them depends on whether the theme places decorations on that layout's page.

- The canvas, page list, presenting, HTML, PDF and images draw them alike.

### Layout grids

Every page is a header, a body and a footer stacked inside the page's padding; a theme lays out a layout's frames with the CSS grid it writes on `page-body`, and the body's rows measure the body.

It replaces a grid written on `page` that measured the whole page (page bands).

#### How to write

In the theme's CSS, for each layout:

```
@layout content {
  page-body { grid-template-rows: minmax(43px, auto) 11px minmax(97px, auto) minmax(65px, auto) 65px minmax(0, 1fr); }
  label { grid-row: 1; }
  title { grid-row: 3; }
  subtitle { grid-row: 4; }
  main { grid-row: 6; }
}
```

`page-header`, `page-body` and `page-footer` name the three bands of the page, as `page-number` names its number ([Looks for one layout](#layout-rules)). They take neither ID nor class and are allowed inside `@layout name { … }`.

#### Details

- Structure: the page (`page`) keeps its size, its padding and the origin of `x` and `y`. Inside its padding stand, one under the next, the header (`auto`; with nothing in it, 0 high), the body (`minmax(0, 1fr)`) and the footer (`auto`, up to its `max-height`, [The bottom band](#bottom-band)). The three bands are drawn on every page of every document type (slide, article, poster) and every layout; an empty one takes no room, so nothing switches on what the page holds.
- Drawn as: `<section class="slide">` (the page) holds `.koma-page-header`, `.koma-page-body` and `.koma-page-footer` as its grid rows (Koma writes `display: grid; grid-template-rows: auto minmax(0, 1fr) auto` and the padding on the page itself). The page's decorations ([Layout decoration](#theme-decoration)) and its edge line ([Page-edge lines](#page-edges)) stay on their own layers over the whole page.

- Header: kept for the deck's running head, nothing written on a page; nothing is drawn in it yet, so it is 0 high. The deck's logo keeps its corner place over the page ([The document's logo](https://komalang.org/spec/structure/#logo)). `[label:]` is a slot of the body, not the header.
- Body: the frames of the layout (`label`, `title`, `subtitle`, `main`, cover fields, custom frames) are the body's direct children. The body is always a CSS grid, one `minmax(0, 1fr)` row and column unless the theme writes its own; authors never write its `display`. The page's flow ([Placement](https://komalang.org/spec/semantics/#placement)), what the page holds without `x` or `y`, is drawn in `.koma-page-flow`, a direct child of the body that fills the body's whole area and adds nothing to the height of its rows. Continuous text on articles and blank layouts therefore starts at the body's top and ends at the footer's top.

- Frames in the grid: the frames the theme gives a `grid-row` that the document writes neither `y` nor `h` for. A frame the document writes `y` or `h` for is placed as written, from the page's origin (out of the grid), and moves no other frame; the theme's `grid-row` does not apply to it.
- Placed elements: an element with `x` or `y` is placed from the page's top left corner, never the body's, whatever band its source belongs to ([Placement](https://komalang.org/spec/semantics/#placement)). The bands are not containing blocks; the page is.

- A frame is as tall as its row. A `minmax(least, auto)` row takes its least height even with little in it and grows with more; an `auto` row is 0 when its frame is not written.
- Declarations that apply in a theme's CSS: on `page-body`, `grid-template-rows`, `grid-template-columns`, `row-gap`, `column-gap` and `gap`; on `page-header`, `min-height` and `max-height`; on `page-footer`, `min-height`, `max-height`, `row-gap`, `column-gap` and `gap` ([The bottom band](#bottom-band)); on a frame, `grid-row`, `grid-column`, `align-self`, `justify-self`, `margin-block-start`, `margin-block-end` (and `margin-top`, `margin-bottom`), `min-height`, `max-height`. `page-header` and `page-footer` also take looks: `color`, `background`, `border`, `padding`, `font-size`, `font-weight`, `font-style`, `font-family`, `line-height`, `letter-spacing`, `text-align` and `opacity`, with their longhands, so a theme can draw a rule line over the footer. Custom properties apply to every band. Anything else on a band, such as `transform` and `translate`, which move only the drawing, or a look on `page-body`, is said where it is written and left out; the rest of the rule applies. Looks of the body stay on `page`, its decorations and its frames.

- A `%` in `grid-template-rows` is of the body's height, as in CSS for the grid container; a `%` margin is of the width. The official themes write rows in px of a 1080 px page (scaled with the page) and cut them to a 64th of a pixel as the samples' positions are. A row that only skipped the page's top margin or reserved the footer is not written: the padding and the footer are their own. Each layout with a grid writes its first frame's top as its top padding (`@layout content { page { padding-top: … } }`) and, when its last frame does not end at the body's bottom, the room under it as the footer band's `min-height`, so frames stand where their samples are while the footer is short.
- Horizontal position and width come from the sample frame (`x`, `w` of [Frames from sample elements](#theme-frames)), measured from the page's left edge as before; Koma subtracts the page's left padding when it places the frame in the body.

- Content pages: label, title and subtitle from the body's top, then `main` in the last `minmax(0, 1fr)` row. A two-line title pushes the subtitle and the main frame's top down; the main frame's bottom is the body's bottom. The title grows to three lines and is then fitted. An unwritten label or subtitle keeps its least height, so pages of one layout start their main frame at one place when the title is one line and the header is the same.
- Section openers: rows `1fr auto auto fixed`, all in the body. The title keeps its bottom and grows upward with more lines, the label right above it; the subtitle stands in the last row.

- Covers: title and subtitle from the body's top; authors, affiliations and date from the body's bottom in `auto` rows, so an unwritten one takes no room and the gap before it does not remain either.
- Migration: a `display`, `grid-template-rows`, `grid-template-columns`, `row-gap` or other grid declaration written on `page` is reported as `legacy-page-grid` (warning) at its rule and left out; the rest of the rule applies. `koma format --write` on a `.koma` document or `theme.koma` writes each such grid in its own CSS for the body, so its frames stay where they were drawn: a leading fixed row that holds no frame becomes the layout's top padding, a closing fixed row that holds no frame becomes the footer band's `min-height`, a closing row that holds frames ends at the body's bottom, a `%` of the page is written as that share of the page's height (`var(--page-height)`), and the frames' `grid-row` numbers follow their rows. The official themes are written this way. A grid in a CSS file the document names is reported but not rewritten. `legacy-page-grid` is removed in 0.2.0.

- Stacking frames (`stacks:`) are retired without compatibility fallback or migration notes.
- Canvas, page list, presenting, HTML, PDF, images and PowerPoint draw the same. Moving a grid frame on the canvas writes `x` and `y` from the page's origin, which takes it out of the grid.

### The bottom band

The footer band holds the footer, the footnotes and the page number; as it grows, the body above it shrinks, and the two never overlap.

It replaces a footer band in the last row of the layout's grid that left the body's bottom in place (page bands).

#### How to write

As before (`[footer: …]`, `[^1]`). The theme may cap the band with `page-footer { max-height: … }`, keep room for it with `min-height`, and draw it with looks such as `border-top` ([Layout grids](#layout-grid)).

#### Details

- In the band, the footer and the page's footnotes stand in one column, one under the next (`row-gap`, 0.5em by default), aligned to the band's foot; the page number stands to their right on the line of the last one, the page number's margin (`--koma-counter-margin`, 3% of the page's height) from the page's right edge. The band reaches right to that margin, past the page's right padding, where the page number has always stood. The column's left edge and width are the footer frame's ([Frames from sample elements](#theme-frames)); footnotes with no footer start where the default footer frame does, 5% from the page's left edge, and reach the page number.
- Drawn as: `.koma-page-footer` holds `.koma-footer-group` (the `[footer:]` element and `.slot[data-slot="references"]`) and `.page-counter`. A page with neither footer, footnotes nor page number has an empty band, 0 high.

- Room: the band is at least its `min-height` tall, its content aligned to its foot. Where the page's CSS writes no bottom padding, the page's bottom padding is the page number's margin and the band's `min-height` is the rest of the page kind's bottom padding, so the page number stays at its corner and the body ends where the page kind's padding does while the footer is short. A page rule that writes its bottom padding sets that margin itself, and the band then keeps no room of its own.
- Growth: the band takes the height of its content up to its `max-height` (a `%` is of the page's height inside its padding; one third when the theme writes none). The body takes what is left, so the main frame's bottom moves up by what the band gains, and frames in the body are fitted in their new size. Past its `max-height` the band's text is made smaller (to half), and what still does not fit is reported as `overflow`.

- Order: the header and the footer are measured first, then the body, so fitting never runs in a loop.
- The same band serves every layout and document type, with or without a grid in the body; there is no separate placement for pages without a footer or without a grid. A footer the document writes `y` or `h` for is placed as written from the page's origin; its footnotes stay in the band.

## Style classes

### Named styles

Style classes name appearances for boxes, callouts ([Callouts](https://komalang.org/spec/elements/#callout)), and shapes. The theme defines their CSS.

#### How to write

Write a class in the tag, as in `[box .tint: …]` or `[callout .card: …]`. Themes support the following choices in this order. Each background supports text contrast of at least 4.5:1.

| Name | Class | Appearance |
| --- | --- | --- |
| None | — | No fill or outline |
| Outline | `outline` | Rounded corners with a 2 px `--koma-line` border, 1.5 pt in PowerPoint |
| Card | `card` | White background, shadow and rounded corners |
| Tint | `tint` | Pale role-colour background and rounded corners |
| Bar | `bar` | Left line with a pale background derived from it |
| Fill | `fill` | Rounded `--koma-primary` fill and `--koma-on-primary` text |

#### Example

```koma
[title: Six styles]
[main:
  [col:
    [box:
      None
    ]
  ]
  [col:
    [box .outline style="flex: 1":
      Outline
    ]
  ]
  [col:
    [box .card style="flex: 1":
      Card
    ]
  ]
  [col:
    [box .tint style="flex: 1":
      Soft
    ]
  ]
  [col:
    [box .bar style="flex: 1":
      Bar
    ]
  ]
  [col:
    [box .fill style="flex: 1":
      Fill
    ]
  ]
]
```

> Six boxes side by side: None, Outline, Card, Soft, Bar and Fill.

#### Details

- Explicit element fields take precedence. Apply `border-color`, `border-width`, and `border-style` to all sides of Outline or the left side of Bar. Outline defaults to the theme line or a 22% text-colour mix with the background. Default's line and primary are `#d9dbe5` and `#2d287f`, Talk's are `#d8dadf` and `#0f6b63`, and Report's are `#d8dce2` and `#3b4754`. Their primary text is white. Authored `background-color` overrides the style background. Fill defaults to white text, falling back to `#111827` if white lacks 4.5:1 contrast. Authored text colour wins.
- Visible fill, border or shadow earns padding on a box or callout whether produced by a class or authored style. An unstyled box uses zero padding for alignment with surrounding content. For visible surfaces the defaults are `0.75em` vertically and `1em` horizontally, relative to the box's font size. Use ordinary CSS padding and radius to override them. All official themes use the default padding. Outline and Bar draw their lines inside padding so their appearance does not shift text.

- Explicit `padding` and side-specific CSS override the applicable defaults ([Elements](https://komalang.org/spec/elements/#element)). Top and bottom defaults are equal. Avoid adding a final paragraph, list, or nested element's trailing gap inside the box. Flow from the top, with callouts vertically centred ([Callouts](https://komalang.org/spec/elements/#callout)). The default radius is 12 px and Report uses 6 px. Padding fits within the box width.
- Tables use four combinable classes, `grid`, `striped`, `accent`, and `row-heads`, shown together in the three official theme examples. Theme completion offers the five visible styles, these table classes, text classes such as `tag`, `sup`, `sub`, `mark` and `underline`, and named theme styles. Source completion identifies theme looks and also offers document CSS classes. Custom classes always remain in source.

- Shapes accept all six choices. Tint uses the shape's pale colour, Fill its colour and white text, Outline a thick line, Bar a left line and pale fill, and Card white with shadow. The style preserves the shape outline. Figures support Card and Outline only.
- A theme may add a heading band with CSS on a styled box's first heading. The built-in themes leave it unspecified.

- Use an element's CSS `list-style-type` for a custom marker or numbering. Quoted marker strings such as `"✔ "` and CSS values such as `decimal` apply to immediate list children. Nested lists keep their own values. Editor, presentation and export agree. Invalid unquoted markers and unknown names report `bad-value` without applying. A theme can provide a default.
- A folder theme can declare additional names in `theme.json` under `boxStyles` and define their CSS in `theme.css`. Show these classes after built-in styles.

### Inline classes

The official themes have the text classes `.sup`, `.sub` and `.mark`.

#### How to write

In text, write `[1]{.sup}` and the like; superscript is usually `^{…}`, subscript `_{…}` and highlight `==…==` ([Text inside elements](https://komalang.org/spec/text/#inline-markup)). The names follow HTML's element names; they are written alongside `.chip` ([Text inside elements](https://komalang.org/spec/text/#inline-markup)) and can be redrawn with the document's CSS. The official themes (default, talk, report) have them, so `unknown-class` is not reported.

#### Details

- `.sup`: `vertical-align: super`, text at 0.75em, `line-height: 0` (the line does not get taller).
- `.sub`: `vertical-align: sub`, text at 0.75em, `line-height: 0`.

- A highlight is drawn as a band of the `--koma-mark` colour over the lower 40% of each line. Its colour and height ratio (`--koma-mark-height`, `40%` by default) can be changed with the document's CSS. Text colour, weight and line spacing are inherited, and no space is added. Each wrapped line is drawn the same way. Body text and the default band have a contrast of 4.5:1 or more. The compatibility class `.mark` can be set independently of the document's CSS.
- Text with both `.sup` and `.sub` gets `.sub`, written later in the theme's CSS.

- Superscripts and subscripts in math are written `$x^2$`. `.sup` and `.sub` are for characters in text (`1^{st}`, `H_{2}O`, note marks).

## Page kinds and edges

### Values per kind of page

A theme can hold `--koma-*` values for each kind of page ([Kinds of page](https://komalang.org/spec/structure/#page-kind)), and pages take a default layout by their kind. The values are chosen by the kind, not the size.

#### How to write

In the theme's CSS, write the `--koma-*` values for text size, padding and spacing for each kind: for example, smaller body text and paper-style margins for documents, and sizes read from afar for posters. A theme of your own can write per-kind values by the same contract ([What a theme decides](#theme)).

#### Details

- A theme with no values for a kind uses its slide values. The built-in themes (Default, Talk, Report) hold values for all three kinds.
- The same theme name is used for every kind. Changing the kind keeps the theme; only the theme's values for the kind change.

- A poster is read from one to two metres: printed on A0, its body text is at least 24 pt (48 px, 36 pt, in the built-in themes) and its title about three times that. Themes multiply their title sizes by `--koma-title-scale` (1 for slides and documents, 1.75 for posters).
- The default layout: when neither the page nor the document writes `layout`, slides take `content`, as before; documents and posters take `blank` (no frames; what the page holds flows from the top inside the page's padding, [Placement](https://komalang.org/spec/semantics/#placement)). A page that uses frames such as `[title:]` writes `layout:`. An added page takes the layout of the page before it.

- Vertical spacing on documents and posters is set as on paper: it follows the text's size and leading and how blocks relate, and it is fixed by the kind's values, never closed up or opened out to fill a box. From tightest to widest: a paragraph or a list right under a local heading (`--koma-local-heading-gap`, 0.125em in the built-in values); items of a list and the pairs of a definition list (`--koma-item-gap`, 0.25em, half that between the items of a nested list, [Definition lists](https://komalang.org/spec/text/#definition-list)); paragraphs, and a paragraph and a list (`--koma-paragraph-gap`, 0.5em); the space around a display block (a table, figure, display math, code, quotation, diagram or grid), after a heading too (`--koma-block-gap`, 12 px on documents and 40 px on posters); and the space above a local heading after a block (1.35em). Each em is the text's own, so the spacing follows the text size of a box. A theme can set these values for the kind ([What a theme decides](#theme)); a document's `css:` and an element's `style` override them. Slides keep their own spacing, which fitting closes up ([HTML elements and reading order](https://komalang.org/spec/semantics/#html-elements)).

### Page-edge lines

Page edge lines draw a line such as a band along the bottom of the page without a background image (`linear-gradient` and the like cannot be exported to PowerPoint).

#### How to write

A page takes `border`, the per-side `border-top`, `border-right`, `border-bottom` and `border-left`, and their `-width`, `-color` and `-style` (also `border-width`, `border-color` and `border-style`). `page { border-bottom: 8px solid #2d287f; }` in the document's or theme's CSS applies to every page, `page.class { … }` to pages of that class, `@layout content { page { … } }` to pages of that layout ([Looks for one layout](#layout-rules)), and `style:` in page settings (`---`) to that page only (`style: "border-bottom: 8px solid #2d287f"`).

#### Example

```koma
---
style: "border-bottom: 16px solid #2d287f"
---

[title: A page with an edge line]
[main: The band at the bottom is a line written in the page settings' style.]
```

> A thick dark navy band runs along the bottom edge of the page.

#### Details

- A page's `style:` takes only the line declarations above. Other declarations (such as `color`) have no effect, keep their source as written, and are reported as `bad-value` (warning). A page's other looks are decided by the document's CSS and the page's `class` ([Page settings](https://komalang.org/spec/structure/#page-settings)). `style:` in document settings (`===`) is `setting-out-of-scope`.
- Layering: by the ordinary CSS cascade, every page in the document's and theme's CSS, then the layout (one class heavier), then the page's own `style:` (strongest). Each declaration layers on its own, so a layout can change only the colour.

- Drawing: the line is drawn inside the page, along its edge, below what is on the page. The page's size, padding, the flow's area, and the positions of frames and elements do not change with the line (the line may overlap content). HTML, PDF and images are as the browser draws.

## Official themes

### Text faces

Text faces: the default sans and mono are bundled and used first, and faces named by a document or theme are taken from the computer.

#### How to write

Write a face's name in `font-family` in the document's or theme's CSS.

#### Details

- The default sans and mono (Noto Sans CJK JP, Noto Sans Mono CJK JP) are bundled with both `koma` and KomaDocs and used first in default drawing, so every computer shows the same look.
- The serif faces are bundled only with KomaDocs, not with `koma`. A document naming the serif face under `koma` is drawn with it if the computer has it, and otherwise gets the warning below.

- Faces named by a document or theme are taken from the computer.
- When a named face is not on the computer, it is not replaced silently: a warning is given (not a failure). Only the first name in each text's list of faces (the one the writer chose) counts; later fallback names and generic families such as `serif`, `sans-serif`, `monospace` and `system-ui` do not. The warning names the face and, when known, the face used instead.
  - `koma check --layout`: a `font-unavailable` warning per page.
  - `koma export`: a `font-unavailable` warning, once per face, in the `--json` findings and on standard error. The output is made, and the exit code is that of a warning.

- How it is told: once drawing has loaded the faces, a sample string is compared on a canvas with three generic families (monospace, serif, sans-serif); a name that changes none of their widths is “not there”. A face the page declares is judged by its loading state. `document.fonts.check()` answers “there” even for names with no face, so it is not used.

### Font weights

The bundled faces have a face per weight, and a weight the face lacks is drawn with the nearest one.

#### How to write

Write the weight in `font-weight`. sans has faces at 400, 500 and 700; serif and mono at 400 and 700.

#### Details

- Bundled faces: sans (Noto Sans CJK JP) has three, Regular 400, Medium 500 and Bold 700; serif and mono have two, Regular 400 and Bold 700. Medium is Noto CJK's pinned static face, subset and bundled by the same steps as the others (text faces). Variable fonts are out of scope.
- Each weight has its own `@font-face`, and the browser loads only the faces used. A document that does not use Medium gets nothing more.

- A face counts as missing only for a reason: no face matched, a face ended in error, the font set refused, or the face was still not in after 60 s. A face still loading after 15 s is slow, not missing, and is waited for. A failure is not remembered, so the next view or output asks again. Each fallback names its face and one of four reasons (no face matched, a face in error, refused, or timed out) in the page's `data-text-font-failure` and the web inspector's console.
- A weight the face lacks is drawn with the nearest face by CSS weight matching. The Medium face covers 500 to 600, so `font-weight: 600` in sans is drawn with Medium (500). In serif and mono, 600 is Bold (700). Built-in looks (page numbers, authors) write their weight as 700.

- `koma check --layout`: writing a weight a bundled face lacks gives the warning `font-weight-unavailable` (as `"Noto Serif CJK JP" has no 600; drawn at 700`), once per face and weight per page. Weight added by the browser's `bolder` for `strong` inside bold text does not count.
- HTML and PDF embed only the faces used (Medium only when Medium is used).

### Line height of titles

The line spacing of titles and subtitles depends on the document's language (`lang`, [Document settings](https://komalang.org/spec/structure/#deck-settings)).

#### How to write

Nothing needs to be written. To change it, write `title { line-height: … }` and the like in the document's or theme's CSS (no `:lang` is needed).

#### Details

- In a `lang: ja` document, titles (`title`) are 1.25 and subtitles (`subtitle`) 1.4. In `en`, other languages, and documents without `lang`, titles are 1.15 and subtitles 1.3. A page whose `lang` differs from the document's follows the page's language.
- Covers, section openers and ordinary pages use the same values; only the text size changes with the layout. The built-in CSS sets `--koma-title-line-height` and `--koma-subtitle-line-height` by the page's language, and titles and subtitles are drawn with them. The three official themes write no line spacing for titles and subtitles.

- Precedence: `line-height` in an element's `style` > `line-height` written in the document's or theme's CSS > the default by language.
- Titles that mix Japanese and Latin text are drawn with one line spacing per element too. The gap between title and subtitle, body line spacing and letter spacing do not change.

- A title that does not fit its frame shrinks as the rules for fitting text to its frame says, keeping its line spacing. The canvas, presenting, HTML, PDF, images and PowerPoint use the same line spacing.

### Brackets at line ends

The space of full-width brackets at line ends follows CSS Text 4's `text-spacing-trim`, and the official themes trim it on Japanese pages.

#### How to write

Write `text-spacing-trim` with a standard value (`normal`, `space-all`, `space-first`, `trim-start`, `trim-both`, `trim-all`, `auto`) in a theme's CSS, the document's `css:` or an element's `style` ([Elements](https://komalang.org/spec/elements/#element)).

#### Details

- Other values are `bad-value` in an element's `style`. The ordinary CSS cascade and inheritance apply.
- The three official themes (default, talk, report) use `trim-both` on Japanese pages (`lang: ja`; by [Page settings](https://komalang.org/spec/structure/#page-settings), a page without a language is read as Japanese too). The theme writes `--koma-ja-text-spacing-trim: trim-both` on `page`, and the built-in CSS puts that value as `text-spacing-trim` on Japanese pages only (a rule without specificity). Japanese pages of themes that do not write the variable, and pages that are not Japanese, are `normal`. A value written in the document's CSS (`page { text-spacing-trim: normal }`) or an element's `style` wins.

- When the browser knows the value, the browser typesets it. For values it does not know, Koma fills in only part of the standard, where the value applies, and only these two:
  - When a paragraph's first character is an opening bracket `（`, `「`, `『`, `【` or `〔`, the half space before it is trimmed (`trim-start`, `trim-both`, `trim-all`).
  - When a paragraph's last character is a closing bracket `）`, `」`, `』`, `】` or `〕`, the half space after it is trimmed (`trim-both`, `trim-all`).
  - A paragraph is one run of text of a paragraph, heading, table cell, definition-list term or explanation, or a frame such as a title. Footnotes and task items have a number or box in front, so only their ends count. Line ends wrapped inside a paragraph, after a line break (`<br>`), and between brackets side by side are left to the browser. The behaviour of `space-first`, `normal` and `auto` is not filled in.

- How it is filled in: when drawing, only those two characters are put in marked `span`s, and the trimming CSS (a −0.5 em outer margin on the `span`) is written only inside `@supports not (text-spacing-trim: <value>)` for each value. Where the browser can typeset the value it has no effect, so nothing is trimmed twice. There is no switching per renderer and no measuring on every keystroke. The value is read from a variable holding the same value as `text-spacing-trim` (`--koma-text-spacing-trim`, which Koma adds to each declaration), so even unknown values cascade the same way. The source and tidying are unchanged.
- When the Chromium Koma draws with knows `trim-both` (`CSS.supports('text-spacing-trim', 'trim-both')` is true), these filling `span`s and their CSS are removed.

- HTML, PDF, images and the canvas agree.

### Cover and section pages

The official themes' covers and section openers have no colour bands, no full-width hairlines and no short rule above the subtitle, and use the primary colour only for a section opener's label.

#### How to write

Choose the cover or section opener layout (`layout: cover`, `layout: section`); nothing else is needed. Sizes are px of 1920 × 1080, written in the theme's sample frames ([Frames from sample elements](#theme-frames)).

#### Details

- Section opener frames: a section opener's `label`, `title` and `subtitle` stand in the rows `1fr auto auto fixed` of the theme CSS's grid ([Layout grids](#layout-grid)), and do not use the three-line rule below, which is for covers only. The title keeps its bottom edge and grows upward by its lines, and the label stands right above the title's first line (with the sample frames' gap). With a one-line title it is as in the sample; with two or three lines the label stays with the title, and the title does not shrink. The subtitle's frame does not move.
- Title and subtitle frames (for section openers, as above): a cover's `title` frame is three lines of that layout's title size and line spacing (plus the built-in 0.15em space below the title, rounded up to px). The title sits at the frame's bottom (`align-content: end`, [Page layouts](https://komalang.org/spec/structure/#layouts)). The `subtitle` frame is two lines of that layout's subtitle size and line spacing, aligned to the top. Between the bottom of the title frame and the top of the subtitle frame: 28 px for default, 2.65% of the page height for report (about 28.6 px at 1080 px). So the boundary between title and subtitle stays put whether the title has one line or three. A title of more than three lines shrinks as the rules for fitting text to its frame says.
  - The line spacing used is that of Japanese documents ([Line height of titles](#title-line-height): title 1.25, subtitle 1.4; default's cover subtitle is 36 px × 1.4 × 2 = 100.8, so 101). In other languages the line spacing is tighter, leaving space above the title frame and below the subtitle frame.

- default: the left margin is 96.
  - Cover: the top line has `label` on the left (the same colour and weight 400 as body pages' labels, only the size 26 px). The top right is left free for the document's logo, with no theme element. `title` is 68 px, its frame at y=266 and 266 high (68 × 1.25 × 3 + 10.2, rounded up), its bottom at y=532. `subtitle` is at y=560 and 101 high (36 px, weight 400, the weak text colour ink-2). Below, aligned left: `authors` at y=862 (36 px, 700), `affiliations` at y=922 (28 px, ink-2), `date` at y=966 (28 px, ink-2). The bottom right is left free for the page number.
  - Section opener: `title` is 78 px, its frame at y=416 and 120 high, its bottom at y=536. `label` (30 px, 700, primary colour) is right above the title frame at y=372, 40 high. `subtitle` is at y=560, 140 high.
  - Ordinary pages and the table of contents (outside the cover and section rules; frame values only): an ordinary page (`content`) has `label` at y=4%, 4% high; `title` at y=9%, 9% high; `subtitle` at y=18%, 6% high; `main` at y=30%, 60% high. The table of contents (`outline`) has `label` at y=4%, 4% high; `title` at y=9%, 9% high; `main` at y=26%, 64% high. All are 5% from the left and 90% wide. There are gaps below the label (8%) and above the title (9%), and below the subtitle (24%) and above the body (30%), so nothing overlaps at 16:9 or 4:3.

- Spacing: the frames of covers, section openers and content pages stand in the rows of the theme CSS's grid ([Layout grids](#layout-grid)). The coordinates above are their places when the title is one line and every field is written.
  - On a cover, `authors`, `affiliations` and `date` go from the bottom, and an unwritten one takes no room (the fields above it move down). The gaps between them are written with `margin-block-start`.
  - On a content page, a two-line title moves the subtitle and the start of the body down. The body's bottom edge does not move; only a growing footer band moves it up ([The bottom band](#bottom-band)).
  - A one-line title sits right above the subtitle, leaving space above. Second and third lines grow upward.
  - Without a subtitle, its place is simply empty; the title and the lines below do not move.
  - Without `date` or `affiliations`, that line is simply empty; the other lines do not move.

- Report (the same parts and rules as Default, each in its theme's places): no colour bands, full-width lines or rules. On the cover, `label`, `affiliations` and `date`, and on covers and section openers `subtitle`, are ink-2 at weight 400 (the label at the same weight as body pages' labels, [What a theme decides](#theme)). `authors` is 700. A section opener's `label` is 700 in the primary colour, standing right above the title's first line ([Layout grids](#layout-grid)). Title and subtitle frames follow the rules above.
  - report: aligned left with the same frame roles and order as default. Left and right margins are 4%, and frames widen to the outer margin. Body text is 30 px. The ratios of each element's text, unitless line spacing, and spacing proportional to text size are shared with default.

- Talk has no default frames for `label` and `subtitle` on the cover, section openers, body pages and table of contents. The cover centres the title, with authors, affiliations and date packed below it. A section opener has only the title; body and table-of-contents pages give the body plenty of room below the title. The source and explicit coordinates are kept, and a tag without a position is treated as having no frame defined.
- The rule mechanism (the theme's choice): the built-in CSS draws a short rule in the primary colour before the subtitle of covers and section openers only when the theme writes `--koma-heading-rule-width`, `--koma-heading-rule-height` and `--koma-heading-rule-gap` on `page` (and `--koma-heading-rule-margin-inline: auto` to centre it). The three official themes do not. In a theme that does, HTML, PDF and images draw the same picture.
