Skip to content

Your own CSS

Write your own CSS next to Kerf's, with the same scales and colour roles, and have it checked.

Adding a stylesheet

When Kerf has no word for something, such as a shadow, an animation or a one-off hero, write it in your own .css file. Put it in your input folder and link it after kerf.css, so your rules come later:

<link rel="stylesheet" href="/kerf.css">
<link rel="stylesheet" href="/site.css">

kerf build copies it to dist/ as written. With Vite, import or link it as usual; it's checked there too. Use your own class names for your own rules; k- classes belong to Kerf.

The variables

Every scale in your config is a CSS variable in kerf.css, so your CSS can use the same values as your markup:

VariableIs
var(--k-space-16)a value from the space scale (--k-space-0 to --k-space-64 by default)
var(--k-text-lg)a text step's font size, fluid if your scale is
var(--k-text-muted), var(--k-surface) …a colour role, which switches in dark mode
var(--k-radius)the brand radius
var(--k-font-mono)the monospace font
var(--k-shadow-1) to var(--k-shadow-3)the shadows, stronger in dark mode
.hero {
  padding: var(--k-space-48) var(--k-space-24);
  font-size: var(--k-text-3xl);
  background: var(--k-surface-raised);
  border-radius: var(--k-radius);
  box-shadow: var(--k-shadow-2);
}

What's checked

! src/site.css:12  padding: 13px — 13px not in space scale → try var(--k-space-12) or var(--k-space-16)
! src/site.css:20  color: #6b6b6b — #6b6b6b is not a colour role (it won't follow dark mode or the contrast checks) → try var(--k-text-muted)
! src/site.css:31  font-size: 15px — not a text step → try var(--k-text-base)
  • Spacing (padding, margin, gap and their sides) must be on the space scale, in px or rem.
  • font-size must be a text step.
  • Colours (color, backgrounds, borders, outlines, fill, stroke…) must be roles. The suggestion is the nearest role of the right kind: a surface for a background, a text role for text, a border role for a border.
  • These pass: var(…), calc() and other functions except colour ones (rgb(), oklch() and the like count as raw colours), 0, auto, percentages, em, currentColor, transparent and inherit. Shadows and your own custom properties aren't checked.
  • They're warnings, so a project with existing CSS still builds. Set rules: { css: "error" } in the config to fail the build instead.
  • For a deliberate exception, put /* kerf-ignore */ at the end of the line, or on its own line above it.

Contrast isn't checked in your own CSS: Kerf can't tell from a stylesheet which elements a rule will reach. Colour roles are checked against each other in the config, so using them keeps you close.