Skip to content

Forms

Field

An accessible layout wrapper for one form control.

stableCSS onlyhydrateless/field.css

An accessible layout wrapper for a single form control: a label, the control, optional help text, and a validation message, all wired together. In the framework bindings, Hydrateless inputs placed inside a Field pick up its id, aria-describedby, aria-invalid, and required automatically; useField() exposes the same wiring for custom controls. CSS-only.

Field

Live

We never share it.

Invalid state

Add data-hl-invalid to the field, aria-invalid="true" to the control, and render an .hl-error message referenced by aria-describedby.

Live

Enter a valid email address.

Custom controls with useField

Any control can join a Field. useField() returns { id, describedBy, invalid, required } (or null outside a Field) so you can wire your own element.

Live

Used for links and buttons.

Props

The framework bindings expose these props (and forward the rest to the root element).

PropTypeDefaultDescription
requiredbooleanfalseShow the required marker on the label and set `required` on the wired control.
invalidbooleanfalseApply the error styling and set `aria-invalid="true"` on the wired control.

CSS variables

Override these on any ancestor to theme the component. See the theme studio to preview changes live.

CSS variableUsed for
--hl-fg-mutedHelp text color.
--hl-danger-subtle-fgError text and required marker color.
--hl-space-1-5Gap between label, control, and message.

Accessibility

  • The label is associated with the control through for/id, and help and error text through aria-describedby, so both are announced on focus.
  • Set aria-invalid="true" on the control when invalid so the error is announced; the framework Field does this for you.

Released under the MIT License.