Basic Form
Accessible form pattern using the form-field custom element. Native HTML5 validation with CSS-only feedback states.
Overview
This snippet provides a complete contact form with all common input types. It uses form.stacked for vertical layout, <form-field> for validated inputs, and semantic elements like <fieldset> and <footer> instead of wrapper divs.
Key features:
- Zero wrapper
<div>tags — every element is semantic or custom - Native HTML5 validation (no JavaScript required)
- Accessible labels and helper text
- Consistent field styling via
<form-field> - Proper autocomplete attributes
- Checkbox and radio group patterns
- Form actions via
footer.actions.end
Live Example
A contact form with text inputs, select, textarea, checkbox, and radio buttons.
Source Code
The form.stacked class provides vertical layout. Each validated field uses <form-field>; optional controls use bare semantic elements.
Field Types
Text Input
Standard text input with label, placeholder, and helper text.
Select Dropdown
Native select with placeholder option.
Checkbox
Optional checkbox — bare <label> is sufficient when no validation or helper text is needed.
Radio Group
Radio buttons grouped in a fieldset.minimal.group — removes border/padding and stacks children with flex column. No inner <div> needed.
Usage Notes
- Labels: Every input must have an associated label with matching
for/idattributes - Autocomplete: Use appropriate
autocompletevalues to help browsers autofill - Validation: Use native attributes like
required,minlength,pattern, andtype - Helper text: Use
<output>witharia-describedbyandaria-live="polite"for accessible hints - Grouping: Use
<fieldset>and<legend>for radio/checkbox groups - Actions: Use
footer.actions.endfor right-aligned submit/reset buttons
Related
Form Field
Form field element documentation
Input Element
Native input element patterns
Form Element
Native form element documentation