CSS

CSS tokens

Built-in HTML themes expose stable CSS custom properties in the --calepin-* namespace. Prefer overriding these tokens from local theme CSS rather than targeting private theme internals.

/* themes/my-theme/css/custom.css */
:root {
  --calepin-color-background: #f6f7f9;
  --calepin-color-text: #111827;
  --calepin-color-accent: #2563eb;
  --calepin-color-border: #d1d5db;
}

body {
  font-family: Inter, system-ui, sans-serif;
  background: var(--calepin-color-background);
  color: var(--calepin-color-text);
}

pre {
  border: 1px solid var(--calepin-color-border);
}

In Calepin HTML output, #title() is rendered as the page <h1>, so the first Typst heading = becomes <h2>, == as <h3>, and so on. If you target heading selectors in CSS, use this mapping unless your theme remaps heading markup.

Light and dark themes

To define distinct values for light and dark mode, use html[data-theme="light"] and html[data-theme="dark"] selectors in your local theme stylesheet:

html[data-theme="light"] {
  --calepin-color-background: #f6f7f9;
  --calepin-color-text: #111827;
  --calepin-color-accent: #2563eb;
}

html[data-theme="dark"] {
  --calepin-color-background: #101826;
  --calepin-color-text: #f8fafc;
  --calepin-color-accent: #60a5fa;
}

Calepin sets html[data-theme="light"] or html[data-theme="dark"] when the theme toggle is forced by user preference, explicit control, or URL/state storage. If no explicit mode is set, the browser preference is used for initial mode.

Style raw HTML

Use a local theme that extends typst when you want a simple, unstyled HTML base.

Create a directory with a manifest, a layout, and a stylesheet:

raw/
  theme.toml
  layouts/
    document.html
  css/
    raw.css

Edit the manifest raw/theme.toml:

extends = "typst"

Edit raw/layouts/document.html to wrap Typst’s generated HTML and inline the theme CSS files:

{{ doc.head }}
  <meta charset="UTF-8">
  <title>{{ doc.title }}</title>
  {% for file in css %}
  <style>
{{ file.content }}
  </style>
  {% endfor %}
{{ doc.body_open }}
  <main class="page">
    {{ doc.body }}
  </main>
{{ doc.body_close }}

The important pieces are doc.head, doc.body_open, doc.body, and doc.body_close, which preserve the HTML shell Typst produced. The css loop loads files from the theme’s css/ directory, including raw.css.

Compile the notebook:

calepin compile notebook.typ --format html --set theme=raw

List of tokens

GroupTokenPurpose
Colors--calepin-color-backgroundPage background in normal UI surfaces.
--calepin-color-textPrimary body text color.
--calepin-color-mutedMuted/de-emphasized text.
--calepin-color-borderUI border color.
--calepin-color-accentPrimary accent color (links, buttons, highlights).
--calepin-color-accent-hoverAccent color for hover states.
--calepin-color-accent-softSoft tint derived from accent.
--calepin-color-accent-contrastText/icon contrast color on accent backgrounds.
--calepin-color-linkDefault link color.
--calepin-color-link-hoverLink hover color.
--calepin-color-focusFocus ring/text emphasis color.
--calepin-color-selectionText-selection background color.
--calepin-color-infoInfo state color.
--calepin-color-successSuccess state color.
--calepin-color-warningWarning state color.
--calepin-color-dangerDanger/error state color.
--calepin-color-importantImportant state color.
--calepin-color-info-softTranslucent info variant.
--calepin-color-success-softTranslucent success variant.
--calepin-color-warning-softTranslucent warning variant.
--calepin-color-danger-softTranslucent danger variant.
--calepin-color-important-softTranslucent important variant.
Callouts--calepin-callout-note-colorCallout tone for note blocks.
--calepin-callout-tip-colorCallout tone for tip blocks.
--calepin-callout-warning-colorCallout tone for warning blocks.
--calepin-callout-caution-colorCallout tone for caution blocks.
--calepin-callout-important-colorCallout tone for important blocks.
Surfaces--calepin-surfacePrimary surface color for cards/panels.
--calepin-surface-mutedMuted surface tone.
--calepin-surface-raisedRaised surface tone.
--calepin-surface-insetInset surface tone.
--calepin-surface-codeCode block background.
--calepin-surface-outputCode/output container background.
Typography--calepin-font-bodyPrimary text font stack.
--calepin-font-headingHeading font stack.
--calepin-font-monoMonospace font stack.
--calepin-font-sizeBase font size multiplier.
--calepin-font-size-smSmall text font size.
--calepin-font-size-asideAside/sidenote font size.
--calepin-line-heightDefault line height for body text.
--calepin-line-height-tightTighter line height for headings.
--calepin-heading-weightDefault heading weight.
--calepin-code-font-sizeCode and preformatted font size.
Spacing--calepin-space-xsExtra-small spacing token.
--calepin-space-smSmall spacing token.
--calepin-space-mdMedium spacing token.
--calepin-space-lgLarge spacing token.
--calepin-space-xlExtra-large spacing token.
--calepin-space-2xl2XL spacing token.
--calepin-block-gapVertical block spacing.
--calepin-inline-gapHorizontal inline spacing.
--calepin-section-gapVertical section spacing.
Layout--calepin-content-widthMax width for main content regions.
--calepin-wide-widthMax width for wide content regions.
--calepin-page-widthComputed page width for two-column layout.
--calepin-margin-widthSidenote/margin note width.
--calepin-margin-gapGap between body and margin region.
--calepin-page-padding-inlineInline page padding.
--calepin-topbar-heightTopbar height token.
--calepin-sidebar-widthDesktop sidebar width.
--calepin-sidebar-mobile-widthMobile drawer width.
--calepin-shell-gapGap between shell grid tracks.
--calepin-toc-indentIndent used by generated TOC trees.
Borders--calepin-border-widthBorder width used across theme.
--calepin-borderShorthand border style using `--calepin-color-border`.
--calepin-radius-smSmall corner radius.
--calepin-radius-mdMedium corner radius.
--calepin-radius-lgLarge corner radius.
Shadows--calepin-shadow-cardDefault card shadow.
--calepin-focus-ringFocus ring style.
Layers--calepin-z-topbarZ-index for top bar.
--calepin-z-backdropBackdrop and overlays.
--calepin-z-drawerSide drawer z-index.
--calepin-z-popoverPopover/dialog z-index.
--calepin-z-modalModal z-index.
Syntax--calepin-syntax-foregroundSyntax text color for code blocks.
--calepin-syntax-backgroundSyntax background color for code blocks.
--calepin-syntax-borderSyntax border color derived from foreground/background.