Skip to content

Markup

One attribute, s=, with words from your design system. Kerf rewrites it to classes.

The s= attribute

Items are separated by spaces. A word that takes a value is followed by it. Anything Kerf doesn't know is an error, with the closest word it does know.

<div s="card stack 16">
<a s="button primary">
<p s="sm text-muted">
<section s="bg-accent on-accent pad 32">

s= is merged with any class already on the element, so your own classes keep working:

<nav class="site-nav" s="row 16">  →  <nav class="site-nav k-row-16">

Utilities

Values come from your config. The default space scale is 0 4 8 12 16 24 32 48 64 and the text scale xs sm base lg xl 2xl 3xl. Each utility can appear once per element: pad 8 pad 16 is an error.

WriteMeansValues
pad 16paddingspace scale
pad-x 16, pad-y 16padding left and right, top and bottomspace scale
pad-t 16, pad-b 16padding on the top only, or the bottom onlyspace scale
gap 16space between childrenspace scale
stack 16children in a columnspace scale
row 16children in a row that wraps, centred verticallyspace scale
grid 3, span 2equal columns; an item across columns1 to 12
max 1024at most this wide, centredwidth scale
measurea readable line length (about 65 characters)
align startline children up across the layoutstart, center, end, stretch, baseline
justify betweenspread children along the layoutstart, center, end, between
screenat least as tall as the viewport
centercentre the content both ways
scrollscroll sideways inside, not the page (wide tables, code)
stickystays in view while the page scrolls (a sidebar)
hide, showhide; show again (usually with a breakpoint)
ratio 16:9a fixed shape (aspect ratio)whole width:height
cover, containhow an image or video fills its shape: crop to fill, or show all
round, round fullcorners with the brand radius; a circle or pill
shadow 2a shadow, stronger in dark mode (Shadows and motion)1, 2, 3
prosestyles everything inside: content from Markdown or a CMS (Prose)
visually-hiddenhidden but read by screen readers; shown while it has keyboard focus (skip links)
sm, lg, 3xl …text size, with line height and letter spacingtext scale
boldweightnormal, medium, semibold, bold
monothe monospace font
no-underlineno underline, for links that stand on their own (cards); not for links in a sentence
text-mutedtext colour: any colour rolecolour roles
bg-accentbackground colourcolour roles
border-border1px border in a colourcolour roles
border-t-border, border-b-border1px border on the top or bottom onlycolour roles
menua panel of links that a button opens on small screens; a row from the breakpoint you give it one (Menus)
hover:bg-accenta colour, round or shadow on hover and keyboard focus (Hover)colour roles

Layout, images and video are covered in detail on the Layout page.

Components

A component is a named recipe, followed by its variants: s="button primary", s="card". button, card, alert and badge are built in, and you add your own in the config. Utilities override a component, and an element can have only one.

Buttons, cards, alerts, badges, menus, dialogs, forms and prose each have a section on Components.

Breakpoints

Put a breakpoint and a colon in front of a utility to apply it from that width up. Without a prefix, a utility applies at every width, so you write for phones first.

<div s="stack 16 md:row 24">           column on phones, row from 768px
<h1 s="xl lg:3xl bold">                bigger from 1024px
<div s="stack 16 md:grid 2 lg:grid 3"> one, two, three columns
PrefixFrom
sm:640px
md:768px
lg:1024px
xl:1280px

Breakpoints are emitted in em, so they follow the reader's font size, and you can rename or replace them in the config. Colours, components, hover:, prose and menu can't change by breakpoint: contrast is checked once per element, and a colour that changes with the window would need checking at every width.

Hover

Put hover: in front of a colour, round or shadow to change it while the pointer is over the element. Keyboard users get the same look when they tab to it, or to a link or button inside it, so nothing is mouse-only. On touch screens only the keyboard part applies, so a tap doesn't leave it stuck.

<a href="/post" s="card no-underline hover:bg-surface-raised hover:border-accent">…</a>
<tr s="hover:bg-surface-raised">…</tr>
<a href="/docs/" s="text-muted hover:text">Docs</a>
  • Only colours (hover:text, hover:bg-…, hover:border-…), hover:round and hover:shadow are allowed. Spacing and size would make the page jump under the pointer.
  • hover:border-… changes the colour of a border the element already has; without one, Kerf warns.
  • Contrast is checked on hover too: the element's own hover colours, and text inside it on its hover background. See Checks.
  • Hover can't change by breakpoint, for the same reason colours can't.

Shadows and motion

shadow 1, 2 and 3 lift an element off the page, from a hairline to a floating panel. They're tinted with your darkest neutral rather than grey, and three times stronger in dark mode, where a faint shadow disappears. Your own CSS can use them as var(--k-shadow-2).

<a href="/post" s="card no-underline shadow 1 hover:shadow 3">…</a>
shadow 1
shadow 2
hover:shadow 3

Hover changes and interactive components ease over 0.15s. For people whose system asks for reduced motion, they change at once, and so does every animation and smooth scroll on the page, your own included.

Hand-written classes

Every item has a class name, and k- classes written by hand are read back, so they get CSS and checks too. Useful where s= can't go, like a class added by JavaScript.

s=class
pad 16k-pad-16
md:row 24k-md-row-24
text-mutedk-fg-text-muted
bg-accentk-bg-accent
lgk-text-lg
boldk-weight-bold
button primaryk-button k-button--primary

k- class names inside <script> and template code are found too, and included in the stylesheet: el.classList.toggle("k-hide") works.

Plain HTML

Elements without s= follow the theme too: the page has your surface, text colour and font; links use text-link (inside a <nav> without an underline until hovered, and the link with aria-current="page" in the text colour, semibold); links in a <nav> and <summary> are at least 44px tall to tap; links get the same focus ring as buttons; lists laid out with stack, row or grid lose their bullets; form fields, code blocks (a step smaller than the text) and tables are styled when a page has them; images never overflow their container. These base styles have no specificity, so any class overrides them (dialogs keep their open and closed state).