Getting started
Kerf is a CSS framework that enforces your design system and accessibility when you build, not in review.
What it does
You describe your design system once: a brand hue, a spacing scale, a type scale, colour roles and a few components. In markup you write s="…" with words from that system, and Kerf turns it into classes and a stylesheet holding exactly what your pages use.
<a href="/start" s="button primary">Start</a>
<p s="text-muted pad-y 16">No account needed.</p>
While it does that, it checks the work. A value that isn't on a scale, text that doesn't meet WCAG contrast on the background it actually sits on, a button smaller than a finger, a field without a label, an image without alt, a link or button with no name: each is a build error with the file, the line (where there is one) and a fix. Some things, like a skipped heading level, are warnings.
✗ src/index.html:2 pad 13 — not in space scale → nearest: 12 or 16
✗ src/index.html:4 fg:text on bg:accent — contrast 2.2:1, needs 4.5:1 → try fg:on-accent
Install
Kerf needs Node 20 or later.
npm install --save-dev @kerfcss/kerf
npx kerf init
kerf init writes kerf.config.js (.mjs if your package.json isn't "type": "module"), an AGENTS.md for AI coding agents unless you have one, and, if there's no src/ folder yet, a starter page. --hue <0-360> sets the brand colour (default 250).
Build
npx kerf build # src/ → dist/, with dist/kerf.css
npx kerf build --watch # again on every save (-w for short)
npx kerf check # the checks only, nothing written
npx kerf check --json # the same, as JSON for CI and coding agents
Link the stylesheet from your pages. Kerf adds a content hash to the link when it builds, so browsers never keep an old copy:
<link rel="stylesheet" href="/kerf.css">
With Vite or Next.js, use the plugin instead: see Vite and Next.js. For checks as you type, install the VS Code extension (more on editors).
A first page
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Hello</title>
<link rel="stylesheet" href="/kerf.css">
</head>
<body s="screen center">
<main s="stack 16 pad 24 max 480">
<h1 s="3xl bold">Hello</h1>
<p s="text-muted">Built with Kerf.</p>
<a href="/next" s="button primary">Next</a>
</main>
</body>
</html>
After kerf build, s="stack 16 pad 24 max 480" is class="k-stack-16 k-pad-24 k-max-480", and kerf.css has a rule for each word the page uses, the button and the base styles, and nothing else.
Where next
- Markup: everything you can write in
s= - Layout: stacks, rows, grids, widths and breakpoints
- Components: buttons, cards, alerts, menus, dialogs, forms and prose
- Colour and contrast: palettes, roles and dark mode
- Config: every option
- Checks: what fails a build, and why
- Templates: layouts and includes for HTML; PHP, Blade, Twig, JSX, Vue, Svelte and more
- Your own CSS: the variables, and how your CSS is checked
- Tools: every command, Vite, Next.js and the editor extension