Overview
.form is a centered panel (max 328px) that stacks a heading, field rows, an optional checkbox row, and a full-width primary action. Default spacing: 24px padding, 48px between title and body, 16px between fields.
| Part | Class | Role |
|---|---|---|
| Panel | .form | Surface, padding, vertical rhythm |
| Title | .form__title | Heading styled as h4 token |
| Fields stack | .form__body | Inputs + optional checkbox |
| Row | .form__field | Label + one .field or .textarea |
| Actions | .form__actions | Full-width .btn |
Prerequisites
- PimentCSS installed, Installation.
- Input fields,
.label,.field, icons from Input fields. - Checkbox, opt-in row via Checkboxes & switches.
- Buttons, primary submit from Buttons.
Structure
Wrap fields in .form__field so label-to-control gap (4px) and field width (280px) stay consistent. Checkbox uses .form__checkbox on the label for full-width alignment inside the body.
<form class="form" action="/contact" method="post">
<h2 class="form__title">Contact us</h2>
<div class="form__body">
<div class="form__field">
<label class="label" for="email">…</label>
<div class="field">…</div>
</div>
<label class="checkbox form__checkbox">…</label>
</div>
<div class="form__actions"><button type="submit" class="btn btn--primary">Send</button></div>
</form>
Contact form example
Interactive demo combining text inputs, native select, radio group, textarea, validation error, checkbox, and submit. All controls use PimentCSS form patterns.
Field row
Each .form__field is a column: .label then .field (or .textarea). Icons and validation states come from the field component; the form only sets width and vertical gap.
<div class="form__field">
<label class="label" for="topic"><span class="label__text">Topic</span></label>
<div class="field">
<input class="field__input focus-visible" id="topic" name="topic" type="text">
</div>
</div>
Checkbox in the form
Add .form__checkbox on the checkbox label so it spans the body width and aligns with touch targets. Keep the native input first, then .checkbox__control, then text.
Actions
.form__actions stretches child buttons to 100% width. Pair with .btn--primary for the main submit.
Class reference
| Class | Description |
|---|---|
.form | Root panel; flex column, centered, surface background |
.form__title | Title using heading h4 tokens |
.form__body | Stack of fields and optional checkbox |
.form__field | Single label + control row (280px max) |
.form__checkbox | Full-width checkbox label variant |
.form__fieldset | Radio group with legend inside the body |
.form__radio | Full-width radio label variant |
.form__actions | Footer actions; buttons fill width |
Customize (Sass)
-
Form spacing
Override panel width and gaps before importing components.@use "pimentcss-design-system" with ( $form-max-width: 22rem, $form-gap: 2.5rem, $form-body-gap: 1rem ); -
Rebuild CSS
Run after editing _form.scss or tokens.npm run build:css
Accessibility (RGAA / WCAG)
Forms
- Labels, every input has a visible
<label for="…">matchingid. - Required fields, use
requiredandaria-required="true"when applicable; show errors witharia-invalidon the control. - Submit, use
type="submit"on the primary button; do not rely on Enter in a single-field page without a form element. - Autocomplete, set meaningful
autocompletevalues (e.g.name,email,tel). - Checkbox copy, label text describes the consent; checked state must be perceivable (not color alone).
- Focus,
focus-visibleon inputs, checkbox, and submit for keyboard users.