Form
Native controls with consistent labels, spacing, validation and actions.
When to use
Use the form styles to compose labelled native controls for a task such as registration, account editing or checkout. Choose the individual input component that matches each value, then group related choices and actions.
Overview
Forms style native inputs, selects, choices, range sliders and switches. See their pages for details.
Checkboxes, radios and switches keep their native input behavior. In forced-colors mode, their borders and state indicators use system colors, including disabled states.
Range slider
Use .range-slider-input for native range inputs with a custom track and thumb.
Basic structure
Use .form-label with the matching control class.
<div class="mb-3">
<label class="form-label" for="email">Email</label>
<input
class="form-control"
id="email"
name="email"
type="email"
placeholder="alex@example.com" />
</div>Required fields
Use native required and mark its label with .is-required.
<div class="mb-3">
<label class="form-label is-required" for="fullname">Full name</label>
<input class="form-control" id="fullname" name="fullname" required />
</div>Validation
Combine .is-invalid and aria-invalid="true". Link .invalid-feedback with aria-describedby and its id.
<div class="mb-3">
<label class="form-label" for="invalidEmail">Email</label>
<input
class="form-control is-invalid"
id="invalidEmail"
name="invalidEmail"
type="email"
aria-invalid="true"
aria-describedby="invalidEmailFeedback" />
<div class="invalid-feedback" id="invalidEmailFeedback">
Please enter a valid email address.
</div>
</div>Extended form example
<form>
<div class="mb-3">
<label for="salutation" class="form-label">Salutation</label>
<select class="form-select" id="salutation" name="salutation">
<option value="not-specified">Not specified</option>
<option value="male">Male</option>
<option value="female">Female</option>
</select>
</div>
<div class="mb-3">
<label for="fullname" class="form-label is-required">Full name</label>
<input
class="form-control"
id="fullname"
name="fullname"
required
placeholder="Alex Morgan" />
</div>
<div class="mb-3">
<label for="birthdate" class="form-label">Date of birth</label>
<input class="form-control" id="birthdate" name="birthdate" type="date" />
</div>
<div class="mb-3">
<label for="email" class="form-label is-required">Email</label>
<input
class="form-control"
id="email"
name="email"
type="email"
pattern="[a-z0-9._%+\-]+@[a-z0-9.\-]+\.[a-z]{2,}$"
required
placeholder="alex@example.com" />
</div>
<div class="mb-3">
<label for="message" class="form-label">Message</label>
<textarea
class="form-control"
id="message"
name="message"
placeholder="Describe the changes you need."></textarea>
</div>
<fieldset class="border border-0 min-w-0 mb-3">
<legend class="mb-2">Notification type</legend>
<div class="d-flex flex-column gap-2">
<div class="form-check">
<input
class="form-check-input"
id="notificationEmail"
name="notificationType"
type="radio"
value="email"
checked />
<label class="form-label" for="notificationEmail">Email</label>
</div>
<div class="form-check">
<input
class="form-check-input"
id="notificationSms"
name="notificationType"
type="radio"
value="sms" />
<label class="form-label" for="notificationSms">SMS</label>
</div>
</div>
</fieldset>
<div class="form-switch mb-3">
<input
class="form-switch-input"
id="notifications"
name="notifications"
type="checkbox"
checked />
<label class="form-label" for="notifications">Enable notifications</label>
</div>
<div class="range-slider mb-3">
<div class="range-slider-header">
<label class="form-label" for="digestLimit">Daily digest limit</label>
<output class="range-slider-output" for="digestLimit">8 items</output>
</div>
<input
class="range-slider-input"
id="digestLimit"
name="digestLimit"
type="range"
min="1"
max="20"
value="8"
style="--range-slider-progress: 36.84%" />
<div class="range-slider-marks" aria-hidden="true">
<span>1</span>
<span>20</span>
</div>
</div>
<div class="form-check mb-3">
<input class="form-check-input" name="privacy" id="privacy" type="checkbox" required />
<label class="form-label is-required" for="privacy">I have read the data policy</label>
</div>
<div class="d-flex gap-1">
<button id="btnCancel" type="button" class="btn btn-secondary btn-text">cancel</button>
<button id="btnSubmit" class="btn btn-primary btn-solid" type="submit">submit</button>
</div>
</form>Accessibility and behavior
- Use a native
form, visible labels and a unique controlidfor everyforreference. Addnameand appropriateautocompleteattributes to submitted fields. - Group related choices with
fieldsetandlegend. Keep DOM order aligned with the intended reading and keyboard order. - Native
requiredapplies constraints;.is-requiredmarks the label visually. Pair application errors witharia-invalidand linked feedback, preserve valid values and identify the next recovery action. - Use a submit button for the primary form action and
type="button"for secondary actions. Application code and the server own submission and validation; styles alone do not submit or validate data.
CSS variables
Override these base defaults on the listed selector after the library styles. Variants and states may replace them; global tokens follow the active theme.
| Token | Default | Purpose | Scope / state |
|---|---|---|---|
--form-control-bg-color | var(--bg-surface) | Background color. | .form-control |
--form-control-border-width | var(--border-width) | Border thickness. | .form-control |
--form-control-border-color | var(--control-border-color) | Border color. | .form-control |
--form-control-border-radius | var(--border-radius) | Corner radius. | .form-control |
--form-control-padding-y | var(--spacer-1) | Top and bottom padding. | .form-control |
--form-control-padding-x | var(--spacer-3) | Left and right padding. | .form-control |
--form-control-font-size | var(--font-size) | Text size. | .form-control |
--form-control-font-weight | 400 | Input text weight. | .form-control |
--form-control-placeholder-color | var(--text-subtle) | Placeholder text color. | .form-control |
--form-control-disabled-text-color | var(--disabled-text-color) | Text color while disabled. | .form-control (disabled) |
--form-control-disabled-bg-color | var(--disabled-bg-color) | Background color while disabled. | .form-control (disabled) |
--form-control-disabled-border-color | var(--disabled-border-color) | Border color while disabled. | .form-control (disabled) |
--form-control-focus-border-color | var(--primary-hover) | Border color while focused. | .form-control (focus) |
--form-control-focus-outline-width | var(--focus-outline-width) | Focus ring thickness. | .form-control (focus) |
--form-control-focus-outline-style | var(--focus-outline-style) | Focus ring line style. | .form-control (focus) |
--form-control-focus-outline-color | var(--focus-outline-color) | Focus ring color. | .form-control (focus) |
--form-control-focus-outline-offset | var(--focus-offset) | Distance between the focus ring and control. | .form-control (focus) |
--form-control-transition-duration | var(--transition-duration) | Duration of visual state transitions. | .form-control |
--form-control-transition-easing | var(--transition-easing) | Timing curve for visual state transitions. | .form-control |
--form-select-bg-color | var(--bg-surface) | Background color. | .form-select |
--form-select-border-width | var(--border-width) | Border thickness. | .form-select |
--form-select-border-color | var(--control-border-color) | Border color. | .form-select |
--form-select-border-radius | var(--border-radius) | Corner radius. | .form-select |
--form-select-padding-y | var(--spacer-1) | Top and bottom padding. | .form-select |
--form-select-padding-x | var(--spacer-3) | Left and right padding. | .form-select |
--form-select-indicator-padding | var(--spacer-5) | Space reserved for the select arrow at the inline end. | .form-select |
--form-select-font-size | var(--font-size) | Text size. | .form-select |
--form-select-font-weight | 400 | Text weight. | .form-select |
--form-select-disabled-text-color | var(--disabled-text-color) | Text color while disabled. | .form-select (disabled) |
--form-select-disabled-bg-color | var(--disabled-bg-color) | Background color while disabled. | .form-select (disabled) |
--form-select-disabled-border-color | var(--disabled-border-color) | Border color while disabled. | .form-select (disabled) |
--form-select-focus-border-color | var(--primary-hover) | Border color while focused. | .form-select (focus) |
--form-select-focus-outline-width | var(--focus-outline-width) | Focus ring thickness. | .form-select (focus) |
--form-select-focus-outline-style | var(--focus-outline-style) | Focus ring line style. | .form-select (focus) |
--form-select-focus-outline-color | var(--focus-outline-color) | Focus ring color. | .form-select (focus) |
--form-select-focus-outline-offset | var(--focus-offset) | Distance between the focus ring and control. | .form-select (focus) |
--form-select-transition-duration | var(--transition-duration) | Duration of visual state transitions. | .form-select |
--form-select-transition-easing | var(--transition-easing) | Timing curve for visual state transitions. | .form-select |
--form-check-gap | var(--spacer-2) | Space between the input and label. | .form-check |
--form-check-input-size | 1rem | Checkbox or radio width and height. | .form-check-input |
--form-check-input-border-radius | var(--border-radius-sm, 0.25rem) | Checkbox corner radius; radios remain circular. | .form-check-input |
--form-check-input-bg-color | var(--bg-surface) | Unchecked control background. | .form-check-input |
--form-check-input-border-width | var(--border-width) | Control border thickness. | .form-check-input |
--form-check-input-border-color | var(--control-border-color) | Unchecked control border. | .form-check-input |
--form-check-input-checked-bg-color | var(--primary) | Checked or indeterminate background. | .form-check-input (checked / indeterminate) |
--form-check-input-checked-border-color | var(--primary) | Checked or indeterminate border. | .form-check-input (checked / indeterminate) |
--form-check-input-checked-color | var(--on-primary) | Checkmark, indeterminate bar or radio dot color. | .form-check-input (checked / indeterminate) |
--form-check-disabled-bg-color | var(--disabled-bg-color) | Background color while disabled. | .form-check-input (disabled) |
--form-check-disabled-border-color | var(--disabled-border-color) | Border color while disabled. | .form-check-input (disabled) |
--form-check-transition-duration | var(--transition-duration) | Duration of visual state transitions. | .form-check |
--form-check-transition-easing | var(--transition-easing) | Timing curve for visual state transitions. | .form-check |
--form-switch-gap | var(--spacer-2) | Space between the switch and label. | .form-switch |
--form-switch-input-width | 2.5rem | Switch track width. | .form-switch-input |
--form-switch-input-height | 1.25rem | Switch track height. | .form-switch-input |
--form-switch-input-padding | 0.125rem | Space between the thumb and the track border. | .form-switch-input |
--form-switch-input-bg-color | var(--bg-highlight) | Unchecked track background. | .form-switch-input |
--form-switch-input-border-width | var(--border-width) | Track border thickness. | .form-switch-input |
--form-switch-input-border-color | var(--control-border-color) | Unchecked track border. | .form-switch-input |
--form-switch-input-border-radius | 9999px | Track corner radius. | .form-switch-input |
--form-switch-input-checked-bg-color | var(--primary) | Checked track background. | .form-switch-input (checked) |
--form-switch-input-checked-border-color | var(--primary) | Checked track border. | .form-switch-input (checked) |
--form-switch-thumb-size | 1rem | Thumb diameter. | .form-switch-input |
--form-switch-thumb-bg-color | var(--bg-surface) | Thumb background. | .form-switch-input |
--form-switch-thumb-box-shadow | var(--shadow-sm) | Thumb shadow. | .form-switch-input |
--form-switch-thumb-checked-translate-x | calc(var(--form-switch-input-width) - var(--form-switch-thumb-size) - (var(--form-switch-input-padding) * 2) - (var(--form-switch-input-border-width) * 2)) | Thumb travel when checked; RTL reverses the direction. | .form-switch-input (checked) |
--form-switch-disabled-bg-color | var(--disabled-bg-color) | Background color while disabled. | .form-switch-input (disabled) |
--form-switch-disabled-border-color | var(--disabled-border-color) | Border color while disabled. | .form-switch-input (disabled) |
--form-switch-disabled-thumb-bg-color | var(--disabled-text-color) | Thumb background while disabled. | .form-switch-input (disabled) |
--form-switch-focus-outline-width | var(--focus-outline-width) | Focus ring thickness. | .form-switch-input (focus) |
--form-switch-focus-outline-style | var(--focus-outline-style) | Focus ring line style. | .form-switch-input (focus) |
--form-switch-focus-outline-color | var(--focus-outline-color) | Focus ring color. | .form-switch-input (focus) |
--form-switch-focus-outline-offset | var(--focus-offset) | Distance between the focus ring and control. | .form-switch-input (focus) |
--form-switch-transition-duration | var(--transition-duration) | Duration of visual state transitions. | .form-switch |
--form-switch-transition-easing | var(--transition-easing) | Timing curve for visual state transitions. | .form-switch |