Documentation
On this page
Forms
Cirth styles standard form elements. Start with the HTML that describes the data you need, then let the browser provide input, keyboard and submission behavior.
<form>
<fieldset>
<legend>Account</legend>
<label>
Full name
<input type="text" name="name" autocomplete="name" required>
</label>
<label>
Email
<input type="email" name="email" autocomplete="email"
aria-describedby="email-help" required>
<small id="email-help">Receipts go here. We never share it.</small>
</label>
</fieldset>
<fieldset>
<legend>Plan</legend>
<label>
<input type="radio" name="plan" value="free" checked>
Free
</label>
<label>
<input type="radio" name="plan" value="team">
Team, billed monthly
</label>
</fieldset>
<button type="submit">Create account</button>
</form>
This form asks for two account values and one plan. The browser collects
controls that have a name. For example, the checked plan produces either
plan=free or plan=team. Your application still has to receive, validate
and store that data.
Label, control, help text #
A label gives a control its accessible name and makes the label text
clickable. The example nests each control inside its label. If the two
elements cannot be nested, give the control an id and use the same value in
the label's for attribute:
<label for="company">Company</label>
<input id="company" name="company" type="text">
The attributes have different jobs:
ididentifies one element in the page. Labels and ARIA references use it.nameidentifies the value when the browser submits the form.valueis the submitted value. For text fields it also provides an initial value; for radios and checkboxes it identifies the selected choice.autocompletetells the browser what kind of saved information may fill the field. Use a standard token such asname,emailorpostal-code.requiredadds a native constraint. A supporting browser will not submit the form while the control has no acceptable value.
A small immediately after a control is styled as help text. Its id lets
aria-describedby connect the explanation to the control, so assistive
technology can announce it after the label. aria-describedby adds a
description; it does not replace the label.
Grouping with fieldset and legend #
A fieldset groups controls that answer one question. Its first legend
names that group. This relationship is especially important for radio buttons,
because a label such as "Team" only makes sense after the group question
"Plan" is known.
The browser exposes the group and its name to assistive technology. Setting
disabled on the fieldset disables its form controls together. Cirth removes
the browser's fieldset frame and styles the legend as the group's heading.
Native behavior and Cirth styling #
The browser owns editing, selection, keyboard input, autocomplete, constraint validation and form submission. Cirth adds a consistent control height, surface, edge, spacing, typography and visible states. It does not send form data, validate business rules or write error messages.
Text fields, select and textarea fill their container by default. Buttons
size to their text. One-line controls and buttons share a 44px minimum height,
so they align when placed together.
Layout #
- Stack labels in source order for the clearest reading and keyboard order.
- Use Grid when related fields need to share a row. It wraps when the available width becomes too small.
- An input with a
sizeattribute keeps its native content-based width instead of filling the row. - Use Group when a field and button must form one joined control.
Do not use visual position to change the meaning or order of fields. The DOM order remains the order used by keyboards and assistive technology.
Accessibility #
- Give every control a visible label. A placeholder is an example or hint; it disappears during editing and is not a label.
- Choose an input
typethat matches the data. Browsers can then provide a suitable mobile keyboard and native constraints. - Put persistent instructions in help text connected with
aria-describedby. - Describe errors in words and associate them with the field. Cirth supplies state styling, not the error message or application validation.
- Keep the native element whenever it already represents the interaction.
Styling a
divto look like an input does not give it input behavior.
Controls #
- Text inputsText, email, password, URL, phone and number.
- SelectOne or several choices from a list.
- TextareaMulti-line text.
- Validation and statesValid, invalid, disabled and read-only.
- Checkbox, radio and switchToggles, single choices and segmented choices.
- ColorThe native colour picker.
- DateDate, time, month and week fields.
- FileFile uploads.
- RangeA value on a scale.
- SearchA search field.
Tokens #
| Token | What it sets |
|---|---|
--cirth-form-element-background-color |
Optional field fill; otherwise the field uses its current surface |
--cirth-form-element-border-color |
Field edge |
--cirth-form-element-color |
Entered text |
--cirth-form-element-placeholder-color |
Placeholder text |
--cirth-form-element-focus-color |
Focus ring |
--cirth-form-element-spacing-vertical, --cirth-form-element-spacing-horizontal |
Field padding |
--cirth-form-label-font-weight |
Label weight |
Customization explains where to set token overrides and how they participate in the cascade.
Common mistakes #
- Omitting
name, which leaves a control out of ordinary form submission. - Reusing an
id, which makesfor,aria-describedbyand other references ambiguous. - Using a placeholder as the only label.
- Treating browser validation as server validation. Data must still be checked by the application.