Components
Buttons, cards, alerts, badges, menus, dialogs, prose and forms: what each one needs and what Kerf checks.
Buttons and cards
A component is a named recipe, followed by its variants. Kerf ships button and card, plus alert and badge (below), and you can add your own in the config:
<a href="/signup" s="button primary">Sign up</a>
<a href="/docs" s="button">Read the docs</a>
<article s="card">…</article>
Components that are interactive (like button) get hover and active shades derived from their background, a focus ring, and the tap-target check. Utilities override the component: s="button primary pad-x 24". An element can have one component. See Config for writing your own.
A disabled button looks disabled, whether it has disabled or aria-disabled="true" (which keeps it focusable, so a screen reader can find it and say why). Hover and press don't change it.
Alerts and badges
alert is a message box and badge a small label, each with a variant for every status: danger, success, warning and info. Without a variant they're neutral.
<div s="alert success" role="status">Saved. Your changes are live.</div>
<div s="alert danger" role="alert">Payment failed: the card was declined.</div>
<span s="badge warning">Expires soon</span>
Draft New Paid Expires soon Overdue
Each status has two colour roles you can use on their own: surface-success for a tinted background and text-success for text, and the same for the others. They keep fixed hues (red, green, amber, blue) whatever your brand colour, and are checked against each other and the page in both modes. See Colour.
- Say what happened in words, not only in colour (WCAG 1.4.1): “Payment failed”, not a red box with “Payment”.
- A message that appears after the page loads needs
role="status"(orrole="alert"when it's urgent), so screen readers announce it. - Status colours reach the stylesheet only when something uses them: a site without alerts doesn't carry them.
Dialogs
A <dialog> is a raised panel on your surface colour with a dimmed page behind it, no wider than the screen. The browser handles focus and Escape. A button with command="show-modal" opens it without JavaScript, and a <form method="dialog"> inside closes it (so does a button with command="close").
<button command="show-modal" commandfor="confirm" s="button">Delete</button>
<dialog id="confirm" aria-labelledby="confirm-title" s="stack 16">
<h2 id="confirm-title" s="lg bold">Delete this post?</h2>
<p s="text-muted">It can't be undone.</p>
<form method="dialog" s="row 12 justify end">
<button s="button">Cancel</button>
<button value="delete" s="button primary">Delete</button>
</form>
</dialog>
A dialog with no name is an error, and one with no close button a warning; its content is checked for contrast on the dialog's own background. See Checks.
Prose
Content from Markdown or a CMS arrives as plain HTML, with nowhere to write s=. Put prose on its container and everything inside is styled from your system: headings on the text scale, paragraphs and lists spaced on the space scale, quotes and captions in text-muted.
<article s="prose measure">
<?= $post->html ?>
</article>
A heading from Markdown
A paragraph, with a link and some code. The space above a heading is wider than below it, so it belongs to what follows.
- A list item
- Another one
A quote, in the muted text colour.
- Its rules have no specificity, so
s=on anything inside still wins. - Its quotes and links are checked for contrast on the background it sits on.
prosecan't change by breakpoint.
Forms
Form fields need no words: input, select and textarea get a border in border-field, the brand radius, a focus ring, and the tap-target height. Checkboxes and radios take the accent colour.
<form s="stack 16">
<label s="stack 4">Email <input type="email" name="email"></label>
<label s="row 8"><input type="checkbox" name="news"> Send me the newsletter</label>
<button s="button primary">Sign up</button>
</form>
aria-invalid="true"draws the border twice as thick intext-danger, so an error isn't shown by colour alone. Put the message intext-dangerand link it witharia-describedby.- Disabled fields are greyed and show a not-allowed cursor.
- Every field needs a label: a placeholder isn't one. See Checks.
Tables, code and disclosures
These are styled as soon as a page uses them, with no words: tables get ruled rows, code blocks a raised panel that scrolls sideways inside itself, and <summary> the tap-target height and a focus ring. Wrap a wide table in s="scroll" so it scrolls instead of the page.
<div s="scroll">
<table>…</table>
</div>
<details>
<summary>Show more</summary>
…
</details>
Your own components
Add components in the config: a base, variants, and whether it's interactive. Kerf checks each variant's colours and tap target when it loads the config. See Config.