Form fields need no class. Inside .rd, on a page or in an island, the plain elements take the library's look; a host form outside .rd never does. The library adds a frame, inner spacing, a 1rem text size and the states below. A field and a button of the default size are equally tall, so they line up in a row. The field keeps small corners (--field-radius, 4px) next to the button’s capsule on purpose: the field is a surface to type into, the button an action.
Text fields, textarea, select
The text fields are input without a type and the types text, email, password, search, tel, url and number. The date and time types (date, time, datetime-local, month, week) take the same frame and height; the browser draws their segments and picker inside it. The types submit, button and reset are buttons. A placeholder is --text-color-light (5.7:1 on white; the browser's own grey is 2.3:1). A textarea grows downwards only. A select draws its own arrow in the text colour; a list box (multiple or size) keeps the browser's. The arrow is a background image under appearance: none: a page rule that sets the background shorthand on a select clears the arrow and leaves no affordance. Set background-color only, or add appearance: auto to keep the native control.
Checkbox and radio
Drawn by the library (appearance: none): a 1em box that sits on the text line like a glyph, filled with --field-accent when checked. Wrap the control in its <label>: the whole line becomes the hit area. A checkbox set to indeterminate by script shows a bar.
<label><input type="checkbox" name="news"> Release notes</label>
<label><input type="radio" name="plan" checked> Monthly</label>
Range, colour, file
The range is a 2px line in the text colour with a round thumb framed in the same colour, drawn by the library in every browser. The range and the colour well are --space-lg tall, not tied to the height of a text field; the well is a square. The file input is a frame across the full width of its container, with no fill: its small button (.button-sm) and the file name sit inside it.
Groups, rows, help and errors
.form-group- One field: its label, the control, a help or error line, stacked. The fields take the group's width; a checkbox, a radio or a button keeps its own.
.form-row- Groups and a button side by side, their bottoms aligned so the button lines up with the fields. A bare field in the row grows too, so a one-line form, a field and its button, takes the full width:
<form class="form-row"><input …><button>…</button></form>. Stacked on a phone. - The submit button
- A
type="submit"button (or a<button>with no type) in a.form-groupor a.form-rowsits at the right edge: on the fields' line, on a line of its own when the row wraps, and when the row stacks on a phone. To put it elsewhere, add.margin-l-0and.self-start(or-center,-stretch). .form-help,.form-error- Small lines under a control. An error is in the body text colour and marked with the
errorglyph in--field-invalid-color: red text would read at 4:1, short of AA. Tie both to the control witharia-describedby.
<div class="form-group">
<label for="city">City</label>
<input id="city" type="text" aria-invalid="true" aria-describedby="city-error">
<span id="city-error" class="form-error">Enter a city.</span>
</div>
A <fieldset> gets a light frame and may shrink with its column; it stacks its groups and rows with a --space-md gap, since .form-group and .form-row carry no margins of their own; its <legend> is bold.
States
- Hover, focus
- The frame darkens under the pointer and turns to
--field-accenton focus, inside the library's focus ring. disabled- A grey field with grey text and the default pointer. The label of a disabled checkbox or radio dims with it.
- Invalid, valid
- Only after the user has had a go:
:user-invalidand:user-validmatch once a field was edited or its form submitted, so an untouched form shows no errors. The frame turns--field-invalid-color; a field that asked for something (required,pattern) turns--field-valid-coloronce it is right. A script marks a field witharia-invalid="true", which shows at once.
Tokens
| Token | Default | Sets |
|---|---|---|
--field-bg / --field-text | var(--white) / var(--primary-color) | Fill and text of a field. |
--field-border-color | var(--gray-trans) | The frame: 3.5:1 on white, the 3:1 a field's outline needs (WCAG 1.4.11). |
--field-radius | var(--space-xs) | Corner radius; a checkbox takes half. |
--field-padding-x / -y | calc(var(--space-sm) * 1.5) (12px) / var(--space-sm) | Inner spacing; the default button takes -y too, so a field and a button stay equally tall when you change it. |
--field-accent | var(--signal) | Checked boxes and radios, the focused frame. |
--field-invalid-color | var(--fail) | The frame of an invalid field and the error glyph. |
--field-valid-color | var(--success) | The frame of a required field once it is right. |
Inside a chart
A RareCharts card (.rc-chart) owns its controls, so these defaults stop at it. The page's own checkboxes and selects that a chart moves into its controls row keep the chart's compact look.