Skip to content

Styling a vzk site

Use this guide when changing how a vzk site looks: the classes its markup wears, the site’s stylesheet and tokens, and a file’s own <style>. Start from describe_vocabulary --topic looks for a whole stylesheet.

Every class a file writes out is compiled into the site’s stylesheet, so a class name is one whole literal. A name joined from a value, such as "text-" + size or class="text-{size}", is refused.

<article class={["card", lead && "card-lead"]}>

class takes a literal, or a list whose missing and false entries drop out. Where a class varies with a value, choose between whole names with a lookup:

<h1 class={{ calm: "soft", bold: "loud" }[fields.tone]}>{fields.cta}</h1>

A class whose names cannot be read before a page is drawn (a row’s value, a function’s answer) is a warning, VZK0304: no rule is made for those names, so the element may be drawn unstyled. A visitor’s text is never a class.

A class given to a component lands on its root element: <Frame class="aspect-square rounded-surface" alt="Dan beside his van" />.

The site’s scale is its own stylesheet.css: read it with cat stylesheet.css. Prefer its tokens to fixed numbers:

  • spacing, used by utilities such as gap-md and py-xl;
  • page rhythm such as px-gutter, pt-band-top and pb-band-bottom;
  • measures such as max-w-page, max-w-headline and max-w-lead;
  • colour roles such as bg-surface, bg-raised, text-ink, text-body and text-muted;
  • type registers such as text-display, text-title, text-lead, text-fine for small print, font-heading and font-strong.

A component class is a decision the look owns: btn-primary, btn-compact, btn-outline, btn-block, link-underline, link-quiet, frame, frame-empty and eyebrow. A file never branches on which look is active: a new look changes the stylesheet while the markup keeps the same tokens and component classes.

<div id="prices" class="px-gutter md:px-gutter-lg pt-band-top md:pt-band-top-lg max-w-page mx-auto">
<p class="eyebrow text-muted">Prices</p>
<h1 class="font-heading font-strong text-display md:text-display-lg text-ink text-balance">What it costs, before I start.</h1>
</div>

A colour, a size or a space that two places use gets a name in @theme, and the classes of a piece that recurs, such as a card or a badge, become a component class with @utility. Then changing the look is one line of the stylesheet, not an edit to every page:

@theme {
--color-highlight: #0b6e4f;
--text-quote: 22px;
}
@utility card {
@apply bg-raised rounded-surface p-md md:p-lg;
}

Give a new token a name that no other token read by the same utility has. text- reads both --text-* sizes and --color-* colours, so beside the looks’ --text-brand a --color-brand turns text-brand into a colour, and the site’s name loses its size.

An arbitrary value such as text-[15px] or max-w-[640px] is for a one-off, a number only one element has. When the site’s stylesheet.css doesn’t have a token this guide names, add it to @theme with the looks’ value rather than writing the number: --text-fine: 13px;.

Write for a phone first. A class with no prefix is what a phone gets, and a wider screen changes only what it needs to, under the standard prefixes: md: above all, where the look’s -lg tokens take over (md:px-gutter-lg, md:text-display-lg), then lg: where a layout needs a third step.

<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-md">

Don’t carry a copied site’s media queries over as max-[900px]: or min-[1180px]: classes. Look at what the old page does on a phone and on a desktop, write the phone’s as the plain class, and put the desktop’s under md: or lg:.

A table’s fields hold what the owner writes: words, pictures, prices and choices. Never keep a colour, a gradient, a class or a piece of CSS in a field to write into class or style: the owner couldn’t change the look without editing every row, and a class read off a row gets no rule (VZK0304). Where items differ in look, let the field that already decides it pick the class, such as a post’s category. Only where no field does, give the table a choice field for the variant. The file maps each option to a whole class:

<article :for={item in tables.services} class={["card", { warm: "card-warm", dark: "card-dark" }[item.tone]]}>

card-warm and card-dark are component classes in stylesheet.css, and an option with no class of its own, such as plain, wears card alone.

stylesheet.css is one whole file, changed on a branch with edit or written whole, then committed with git commit: font imports, tokens in @theme, look-owned components in @utility, base rules in @layer base, and any site-wide rule utilities cannot express. @plugin, @config, @source, @reference and non-URL imports are refused, and so is Tailwind’s built output. It must compile before the commit is accepted.

A file’s <style> is CSS for the markup of that file and nothing else. It comes after the markup:

<script server>
const { tone = "plain" } = props
</script>
<div class={["callout", tone == "warm" && "callout-warm"]}>
<p class="callout-title"><slot name="title">Note</slot></p>
<p><slot /></p>
</div>
<style>
.callout {
border-left: 4px solid currentColor;
padding: 0.5rem 1rem;
p {
margin: 0;
}
}
.callout-warm {
border-color: #b45309;
}
.callout-title {
font-weight: 700;
}
</style>
  • It is plain CSS, with nesting. A rule reaches only the markup written in its own file, wherever that is drawn, so two files may both style .card.
  • A component’s root is styled from the file that uses it by giving the component a class: <Callout class="wide" /> and .wide { ... }.
  • :global(...) is the way out. .prose :global(p) reaches what markdown(...) draws, and .menu:global(.open) a class a script adds.
  • It may hold style rules, @media, @supports, @container, @layer with a block, @starting-style, @keyframes, and @apply inside a rule. @import, @font-face and @property belong in stylesheet.css.
  • A selector that matches nothing in its file is a warning, and a style that cannot be read as CSS is an error.

Use a file’s style for a rule one file alone owns, and the stylesheet for what several files share. style="width: {n}%" on an element takes a number or plain text as each value, for a visual value one element alone owns.