Skip to content

Config

kerf.config.js describes your design system. Everything is optional except the brand hue.

kerf init writes kerf.config.js, or kerf.config.mjs when your package.json isn't "type": "module". Kerf finds either; --config <file> points at another.

Example

import { defineConfig } from "@kerfcss/kerf";

export default defineConfig({
  brand: { hue: 250, chroma: 0.16, radius: 4, font: "Inter", mono: "JetBrains Mono" },
  color: { "text-muted": "neutral.600" },
  space: [0, 4, 8, 12, 16, 24, 32, 48, 64],
  text: { base: 16, ratio: 1.25, mobileRatio: 1.2 },
  widths: [320, 480, 640, 768, 1024, 1280],
  breakpoints: { sm: 640, md: 768, lg: 1024, xl: 1280 },
  rules: { contrast: "AA", tapTarget: 44, css: "warning" },
  components: {
    tag: { base: { "pad-x": 8, "pad-y": 4, text: "sm", bg: "surface-raised", radius: true } },
  },
  input: "src",
  outDir: "dist",
});

brand

OptionDefaultWhat it does
huerequired0 to 360, the OKLCH hue the palettes are made from
chroma0.16how colourful the brand palette is
radius4corner radius in px: round, radius: true in components, form fields, code and dialogs
fontsystem fontsone family ("Inter", given a fallback) or a full stack with commas, used as written
monosystem monospacethe font for code and the mono utility, the same way

color

Colour roles: a palette step (brand.600, neutral.950, danger.700), white or black, or { light, dark }. Merged with the defaults. See Colour and contrast.

space

The only spacing values that exist, in px. Default [0, 4, 8, 12, 16, 24, 32, 48, 64]. Anything else in pad (and pad-x, pad-y, pad-t, pad-b), gap, stack or row is an error that names the nearest values. Your list replaces the default.

text

OptionDefaultWhat it does
base16body size in px
ratio1.25each step is this much bigger than the last
steps["xs", "sm", "base", "lg", "xl", "2xl", "3xl"]the names, smallest first; must include base
mobileRationonea smaller ratio for phones; steps above base grow from it to ratio between 360px and 1280px wide

Line height and letter spacing come from the size: 1.5 for body text, tighter as headings grow.

widths and breakpoints

widths: the values max N accepts, in px. Default [320, 480, 640, 768, 1024, 1280].

breakpoints: names and minimum widths in px for prefixes like md:. Default { sm: 640, md: 768, lg: 1024, xl: 1280 }. Names are lowercase letters and digits starting with a letter, and can't be a word Kerf already uses (such as hover). They're written in em, so they follow the reader's font size.

Both replace the defaults rather than adding to them. color and components are merged with the defaults by name.

rules

OptionDefaultWhat it does
contrast"AA""AA" or "AAA"
tapTarget44minimum height in px of interactive components, text fields, select, textarea and <summary>
css"warning""error" fails the build on off-scale spacing, font sizes that aren't text steps and raw colours in your own CSS (Your own CSS)

components

A component is a set of the words s= uses, without breakpoints or hover:, plus radius: true. variants change only what differs. interactive: true makes it work the same on <a> and <button>, and adds hover and active shades (hover sets how many steps, default 1), a focus ring, a disabled style and the tap-target check. Shades are only derived when bg is a palette colour, not white or black.

components: {
  chip: {
    interactive: true,
    base: { "pad-y": 12, "pad-x": 16, bg: "surface-raised", radius: true },
    variants: { selected: { bg: "accent", fg: "on-accent" } },
  },
}

In markup: s="chip" and s="chip selected". Recipes are checked like markup: values on the scales, contrast for every variant and state, and the tap target.

Built in: button (with primary), card, and alert and badge (each with danger, success, warning and info). They fit themselves to your space and text scales. Define a component with the same name to replace one completely, variants included.

input, outDir and css

These are for kerf build, kerf check and the editor. The Vite plugin uses Vite's own output folder, and with Next.js kerf init sets input to app or src/app.

OptionDefaultWhat it does
input"src"the source folder: HTML and templates are compiled, everything else copied. Folders starting with _ hold layouts and includes and aren't built as pages
outDir"dist"where kerf build writes; separate from input (neither inside the other), and not the project folder or above it
css"kerf.css"the stylesheet's file name inside outDir (not the same as rules.css)