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.
| Write | Means | Values |
|---|---|---|
pad 16 | padding | space scale |
pad-x 16, pad-y 16 | padding left and right, top and bottom | space scale |
pad-t 16, pad-b 16 | padding on the top only, or the bottom only | space scale |
gap 16 | space between children | space scale |
stack 16 | children in a column | space scale |
row 16 | children in a row that wraps, centred vertically | space scale |
grid 3, span 2 | equal columns; an item across columns | 1 to 12 |
max 1024 | at most this wide, centred | width scale |
measure | a readable line length (about 65 characters) | |
align start | line children up across the layout | start, center, end, stretch, baseline |
justify between | spread children along the layout | start, center, end, between |
screen | at least as tall as the viewport | |
center | centre the content both ways | |
scroll | scroll sideways inside, not the page (wide tables, code) | |
sticky | stays in view while the page scrolls (a sidebar) | |
hide, show | hide; show again (usually with a breakpoint) | |
ratio 16:9 | a fixed shape (aspect ratio) | whole width:height |
cover, contain | how an image or video fills its shape: crop to fill, or show all | |
round, round full | corners with the brand radius; a circle or pill | |
shadow 2 | a shadow, stronger in dark mode (Shadows and motion) | 1, 2, 3 |
prose | styles everything inside: content from Markdown or a CMS (Prose) | |
visually-hidden | hidden but read by screen readers; shown while it has keyboard focus (skip links) | |
sm, lg, 3xl … | text size, with line height and letter spacing | text scale |
bold | weight | normal, medium, semibold, bold |
mono | the monospace font | |
no-underline | no underline, for links that stand on their own (cards); not for links in a sentence | |
text-muted | text colour: any colour role | colour roles |
bg-accent | background colour | colour roles |
border-border | 1px border in a colour | colour roles |
border-t-border, border-b-border | 1px border on the top or bottom only | colour roles |
menu | a panel of links that a button opens on small screens; a row from the breakpoint you give it one (Menus) | |
hover:bg-accent | a 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
| Prefix | From |
|---|---|
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:roundandhover:shadoware 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>
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 16 | k-pad-16 |
md:row 24 | k-md-row-24 |
text-muted | k-fg-text-muted |
bg-accent | k-bg-accent |
lg | k-text-lg |
bold | k-weight-bold |
button primary | k-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).