Skip to content

Accessibility checks

What Kerf checks in your markup so that every field, link, image and control works with a keyboard and a screen reader. Errors stop the build; warnings don't. Reading a diagnostic explains the format.

Forms

✗ src/index.html:8  <input type="email"> has no label (a placeholder isn't a label: it disappears as you type) → try <label> around it, or an id and <label for>
! src/index.html:11  <input> is aria-invalid but doesn't say why → try aria-describedby="<id of the error message>"
! src/index.html:5  <input type="email"> has no autocomplete: browsers can't fill it in → try autocomplete="email"

Every field needs a name a screen reader can announce: a <label> around it, <label for>, aria-label, aria-labelledby or title.

Fields for the person's own details need autocomplete, so browsers, phones and password managers can fill them in (WCAG 1.3.5); this is a warning. Kerf knows them by type (email, tel, password) and by a name or id like first_name, postcode or company, and suggests the token. A password field named like new_password gets new-password.

Names, language and headings

✗ src/index.html:3  <img> has no alt → try alt="what it shows", or alt="" if it's decoration
✗ src/index.html:9  link to /cart has no name (a screen reader would read out the address) → try text in it (visually-hidden if it shows only an icon), alt on its image, or aria-label
✗ src/index.html:1  <html> has no lang: screen readers would guess the language → try <html lang="en">
! src/index.html:14  <h4> after <h2> skips a level → try <h3>, and s="…" for its size
✗ src/index.html:10  <iframe> has no title: a screen reader announces it as just a frame → try title="what it shows", e.g. title="Map of the office"
! src/index.html:9  link text "Read more" says nothing on its own: screen reader users often move from link to link → try words that say where it goes, or Read more<span class="k-visually-hidden"> about …</span>
  • Images need alt: what the image shows, or alt="" for decoration. role="presentation" and aria-hidden="true" count as decoration.
  • Links and buttons need a name: text in them (visually-hidden text counts), the alt of an image in them, an <svg> with a <title>, aria-label, aria-labelledby or title. An icon with alt="" alone isn't one.
  • A link in a sentence keeps its underline: no-underline on a link inside a <p> is an error, since colour alone doesn't mark it as a link (WCAG 1.4.1). Links that stand on their own, like cards, can drop it.
  • Link text that says nothing on its own ("Read more", "Click here", "Learn more") is a warning: screen reader users often list a page's links, or move from one to the next. Say where it goes, or add visually-hidden text after it; aria-label works too.
  • An <iframe> needs a title, so a screen reader can say what's in it.
  • A page's <html> needs lang.
  • disabled on a link is an error: links have no disabled state, so it still works. Leave out href and add aria-disabled="true", or use a <button disabled>.
  • Headings shouldn't skip a level, and a page should start at <h1>; this is a warning. Pick the level for the outline and the size with s=. Components and partials can start at any level.
  • Template code and components can supply a name, so Kerf doesn't guess: <a href="/">{label}</a> passes.

ids

✗ src/index.html:4  for="emial" — no element has id="emial" → try for="email"
✗ src/index.html:6  id="q" is used 2 times (lines 6, 9): labels and aria find only the first → try a different id for each

What points at an id has to find one: <label for>, aria-labelledby, aria-describedby, aria-controls, popovertarget, commandfor, list and form. A typo there looks fine on screen, but the screen reader announces the field with no name. Kerf suggests the nearest id on the page.

In a whole page these are errors. In a partial or a component the id may be in another file, so a missing one is a warning; ids written with template code, and anything inside a <template>, are left alone. An id used twice is an error in HTML and a warning in templates, where the two may be in different branches of an if.

Keyboard and zoom

✗ src/index.html:2  user-scalable=no stops people zooming in to read → try content="width=device-width, initial-scale=1"
✗ src/index.html:7  tabindex="2" moves it ahead of everything else in keyboard order → try tabindex="0", and move it in the page to change the order
✗ src/index.html:8  a <button> inside a link: one control can't hold another → try the button next to the link, not inside it
  • A viewport with user-scalable=no, or a maximum-scale under 2, stops people zooming in to read (WCAG 1.4.4). The fix is the same content without them.
  • tabindex above 0 moves an element ahead of everything else when moving with Tab, whatever its place on the page. Use 0, and the order of the page for the order.
  • A button, field or link inside a link or button: which one a click or Enter means is up to the browser, and a screen reader announces only one. Put them side by side.

Tables

! src/index.html:12  <table> has no header cells: a screen reader can't say which column a value is in → try <th> for the header row (in a <thead>), or role="presentation" if it's only layout

A table of data needs <th> cells, so a screen reader can say "Price: £12" and not just "£12". This is a warning; a table used only for layout takes role="presentation", and tables filled in by template code or components are skipped.

Dialogs

✗ src/index.html:8  <dialog> has no name: a screen reader announces it when it opens → try aria-labelledby="its heading's id"
! src/index.html:8  <dialog> has no close button: Escape works, but touch and mouse users need one → try <form method="dialog"><button>Close</button></form>

A dialog needs aria-label or aria-labelledby. A close button is a <form method="dialog">, a button with formmethod="dialog", or one with command="close" or "request-close"; one closed by your own script is a warning you can ignore. See Dialogs.

Buttons that open things

✗ src/index.html:3  popovertarget="m" opens <ul id="m">, which has no popover attribute: the button does nothing → try popover on <ul id="m">
✗ src/index.html:4  command="show-model" isn't one: show-modal, close or request-close (dialogs), toggle-popover, show-popover or hide-popover, or your own starting with -- → try command="show-modal"
✗ src/index.html:5  command="show-modal" works on a <dialog>, and #p is a <div> → try command="show-popover"

Buttons open popovers with popovertarget, and dialogs and popovers with command and commandfor, without JavaScript. When one of these is wrong the browser says nothing and the button does nothing, so Kerf checks them: the target needs popover (or has to be a <dialog> for show-modal, close and request-close), command and popovertargetaction need a value the browser knows, and command and commandfor need each other. Your own commands start with -- and are left alone. A target that doesn't exist is an ids error.

Tabs

✗ src/index.html:6  tabs has 2 buttons and 1 panel: each button shows one panel → try a panel for each button, after the row of buttons
! src/index.html:6  the row of tabs has no name: a screen reader announces it as just a tab list → try aria-label="…" on the row of buttons, e.g. aria-label="Billing"
✗ src/index.html:1  this page has tabs but doesn't load kerf.js: without it the buttons stay hidden and every panel shows → try <script src="/kerf.js" defer></script> in the <head>

tabs needs a row of buttons first and then a panel for each; anything else is an error, since the script can't wire it up. A row with no aria-label is a warning. A whole HTML page with tabs has to load kerf.js, or a module script (which can import "@kerfcss/kerf/tabs"). Partials, components and server templates are left to the page that includes them, and tabs written by template code aren't counted. See Tabs.

Images and video

✗ src/index.html:6  <img> has no width or height: the page jumps when it loads → try width="…" height="…" (the file's size in px; s="ratio …" to show it in another shape)
! src/index.html:6  cover without ratio does nothing: the image keeps its own shape → try ratio 16:9 cover
! src/index.html:9  cover on <div> does nothing: it fits an image or video into its box → try cover on the <img> or <video> itself
! src/index.html:11  <video> has no captions: people who can't hear it miss what's said → try <track kind="captions" src="….vtt" srclang="en">, or ignore this if nobody speaks in it

An <img> without width and height is an error: the browser can't keep its space before it loads, so the page jumps, which Google measures as layout shift (CLS). Use the file's own size; s="ratio …" shows it in another shape, and CSS keeps it no wider than its container. Images with hidden are skipped, and template code can supply the size. cover and contain without ratio (or screen), or on an element that isn't an <img>, <video>, <object> or <embed>, are warnings: they would change nothing. Components and custom elements are skipped, since they may pass them on. See Images and video.

A <video> with controls and no <track kind="captions"> (or subtitles) is a warning: people who can't hear it miss what's said. Background videos without controls are skipped.