# From design tokens to theme templates

> How a Vyasa theme is layered: a validated token set compiled to CSS, a tree of sections, optional templates, and a stylesheet for the rest, each layer allowed to do less than the next.

Published 2026-12-03 · Canonical: https://techgopal.com/post/design-tokens-to-theme-templates

---

> **Summary.** A Vyasa theme is four layers, and each one is allowed to do less than the next. Design tokens describe colours, type and widths and are compiled to CSS. A layout tree composes sections. Optional templates change the markup around sections. A stylesheet reaches whatever is left. The rule that shapes all of it: a theme is data, so most of a site's look comes from the layers that cannot run code. This post walks the layers from the bottom up, with the validation rules that make the tokens safe to accept from anyone. It describes Vyasa 0.4.1.

## Key facts

## Layer 1: tokens

The token document describes seven colour roles (`bg`, `surface`, `text`, `text_muted`, `border`, `primary`, `on_primary`), each with a light and a dark value, plus type (heading and body families, a base size from 12 to 24 px, a scale ratio), spacing, a corner radius, a shadow level and layout widths. Two breakpoints live here too, which surprises people: CSS cannot read a custom property inside `@media`, so the breakpoints are interpolated into the generated stylesheets and have to live in the token document to be themeable at all.

Two decisions in that schema matter more than the fields themselves.

**Unknown keys are errors.** The structs reject unknown fields. A misspelt `primry` is a rejected theme, not a theme where the primary colour quietly stays at its default.

**Defaults complete partial input.** A document as small as `{"version": 1}` is valid and equals the built-in neutral palette. The docs note one reason: partial documents, such as truncated AI output, are completed with defaults instead of being thrown away.

### Validation

The rules are a short table, not a long argument. Colours must be `#rgb` or `#rrggbb`. Ranges are bounded: base size 12 to 24, radius 0 to 32, content width 480 to 1920, spacing steps ascending with at most eight steps. Font families may only contain letters, digits, space, underscore and hyphen, which is a guard against CSS injection through a font name. Font sources must start with `https://`.

Some problems are errors and some are warnings. Errors block compilation. Warnings come back alongside valid CSS so an editor can show them without blocking: contrast below WCAG AA (4.5) for the text-on-background pairs, checked separately for light and dark, a dark palette that overrides only some roles, a duplicate font family.

### Compilation

The token set compiles to one `:root` block of `--vy-*` custom properties, dark overrides under both `@media (prefers-color-scheme: dark)` and `[data-theme="dark"]`, and an `@font-face` rule per declared face. The manual toggle wins over the system preference because it comes later in the output. The output is deterministic, so the public site can cache compiled theme CSS by content hash.

## Layer 2: a tree of sections

An earlier layout was a flat list of blog primitives with one global palette. It could stack things but never put them beside each other and never restyle one band, so a hero above three columns above a dark call to action could not be expressed, however good the rest of the theme was.

The layout is now a tree of sections, one tree per template type. Each section has an id, a kind, settings validated against that kind, optional children and an optional scope that overrides colours for that band. Containers (`band`, `columns`, `grid`, `group`) wrap children; every other kind renders what its resolver produced. Children on a leaf are an error rather than being ignored, so a mistake surfaces when you save, not as a missing section. Nesting is capped at five levels.

A section can also be hidden on one screen size, and `columns` take separate counts for desktop, tablet and mobile.

A repeating section can bind to a content source instead of hand-entered items: a post type, a sort, a limit and optional filters. A source whose plugin is disabled renders as an empty section, never an error. Bound sections render into cached pages like everything else, and a new entry appears when publishing invalidates the cache. The docs are blunt that this should not be "fixed" into per-request queries: the cache is why the public site survives traffic.

## Layer 3: templates

Templates change the markup around the sections. They are optional Tera files in a flat `templates/` folder. The renderer resolves a per-type file before the generic one (`single-book` before `single`), and on a single entry it first tries a file named for the entry's slug. One page can have its own markup without a new content type. A slug with no matching file changes nothing.

Template names are validated by shape, so a template for a type that never exists is dead weight, not an error.

## Layer 4: the stylesheet

`theme.css` is for what the tokens cannot say. The class names it targets are stable and documented in the base stylesheet, and animation lives here. The base stylesheet zeroes transitions under `prefers-reduced-motion`, and a theme's own rules should respect the same query.

## Where each layer stops

This is the design point I care about. Tokens restyle the whole site, so a theme that ships only tokens is already a complete theme, and it cannot run anything. The layout composes. Templates change markup. Only a script (`assets/theme.js`, or a template that writes a `<script>`) can run code, and that is the one case that needs a signature, which I covered in the signing post. A theme that stays in the first four layers installs without one.

The result is the opposite of how many themes grow: you start at the layer that cannot hurt anyone and move up only when you need to.

## Limits and honesty

- Package limits are fixed: 25 MiB compressed, 200 entries, 5 MiB for one entry.
- The token schema is version 1. If it needs a field I did not think of, that is a version bump, not a quiet addition.
- The whole system is for sites like the ones I run. I have not tried to make it express every design.

If a rule here looks wrong, please open an issue on the Vyasa repository.


---

**Feature number:** 010

**Main search phrase:** CMS theme design tokens

**Secondary search phrases:** theme tokens to CSS, CMS theme layers

**Summary (answer first):** How a Vyasa theme is layered: a validated token set compiled to CSS, a tree of sections, optional templates, and a stylesheet for the rest, each layer allowed to do less than the next.

**Chips:** Vyasa 0.4.1 | Design tokens | Themes

