Skip to content

CSS: form-field ​

.instui-form-field — A form-field wrapper: a label, its controls, and inline, required, or readonly layouts.

Native validation is opt-in: add data-native-validation and load @pantoken/interactions/form-field.iife.js, or call initFormField(host, control, error). Supply exactly one native control and one error message with a stable, unique ID. The behavior associates the error after blur or a native validation attempt and removes it when corrected; CSS alone doesn't synchronize ARIA.

Source: form-field.css

TIP

JS Enhancement — This component's CSS renders and works on its own; pair it with @pantoken/interactions to add the interactive behavior. See the modifier table below.

Usage ​

css
@import "@pantoken/components/components.css";
@import "@pantoken/components/form-field.css";
html
<label class="instui-form-field">
  <span class="label">Display name</span>
  <span class="controls"><input class="instui-text-input" type="text" autocomplete="nickname"></span>
</label>

Structure ​

text
.instui-form-field
  .label
  .controls
    text-input (component)
  form-field-messages (component)
flowchart TD n0[".instui-form-field"]:::cssdoc-root n1(".label"):::cssdoc-part n2(".controls"):::cssdoc-part n3(["text-input"]):::cssdoc-component n4(["form-field-messages"]):::cssdoc-component n0 --> n1 n2 --> n3 n0 --> n2 n0 --> n4 click n3 "/api/css/text-input.md" click n4 "/api/css/form-field-messages.md" classDef cssdoc-root stroke-width:1px; classDef cssdoc-part stroke-width:1px; classDef cssdoc-slot stroke-width:1px; classDef cssdoc-component stroke-width:1px;

Modifiers ​

ModifierDescription
.-inlineInline layout (shorthand for -layout-inline).
.-invalidInvalid (error) state.
.-label-align-endEnd-align the label text.
.-label-align-startStart-align the label text.
.-layout-inlineInline layout: label beside the controls.
.-layout-stackedStacked layout: label above the controls.
.-readonlyRead-only state.
.-v-align-bottomBottom-align the label with the controls.
.-v-align-topTop-align the label with the controls.

Parts ​

PartDescription
.controlsThe control area beside or below the label.
.labelThe field label.

Pseudo-elements ​

Pseudo-elementDescription
::afterRenders the decorative required-field asterisk after the label text when the field is required.

States ​

StateDescription
:required—

Accessibility ​

A wrapping <label> names the control. When it also contains messages, use aria-labelledby to identify just the visible label text and aria-describedby for hints. Associate visible validation errors and synchronize aria-invalid in application code or with the opt-in native validation behavior; the decorative required asterisk isn't an accessible-name substitute.

Rules (axe-core)Rebrand (light)Rebrand (dark)CanvasCanvas High Contrast
color-contrastWCAG 2.2 1.4.3PassPassReview neededReview needed

Canvas, Canvas High Contrast: Elements must meet minimum color contrast ratio thresholds

  • #audit-email-label
ConditionsRebrand (light)Rebrand (dark)CanvasCanvas High Contrast
forced-colors-focus-visibleWCAG 2.2 1.4.11, 2.4.7PassPassPassPass
more-contrast-respectedWCAG 2.2 1.4.3, 1.4.6PassPassPassPass
reduced-motion-respectedWCAG 2.2 2.3.3, 2.2.2PassPassPassPass
reflow-at-320pxWCAG 2.2 1.4.10PassPassPassPass
text-spacing-no-clippingWCAG 2.2 1.4.12PassPassPassPass
InteractionsRebrand (light)Rebrand (dark)CanvasCanvas High Contrast
error-associated-on-invalidWCAG 2.2 3.3.1, 4.1.3PassPassPassPass
focus-indicator-visibleWCAG 2.2 2.4.7PassPassPassPass
label-associatedWCAG 2.2 1.3.1, 3.3.2, 4.1.2PassPassPassPass
no-focus-trapWCAG 2.2 2.1.2PassPassPassPass
trigger-reachable-by-tabWCAG 2.2 2.1.1PassPassPassPass
Computed stylesRebrand (light)Rebrand (dark)CanvasCanvas High Contrast
boundary-contrastWCAG 2.2 1.4.11PassPassPassPass
focus-indicator-contrastWCAG 2.2 1.4.11, 2.4.13PassPassPassPass
text-contrast-by-stateWCAG 2.2 1.4.3PassPassPassPass
Screen reader (simulated)Rebrand (light)Rebrand (dark)CanvasCanvas High Contrast
AnnouncementsPassPassPassPass

These automated results do not establish that the page meets WCAG; manual review is still needed.

Tokens consumed ​

TokenTypeValue
--instui-component-form-field-layout-asterisk-color<color>LightDarklight-dark(#C51F22, #FA917F)
--instui-component-form-field-layout-font-family[ <font-family-name> | <generic-font-family> ]#Atkinson Hyperlegible Next, "Helvetica Neue", Helvetica, Arial, sans-serif
--instui-component-form-field-layout-font-size<length>1rem
--instui-component-form-field-layout-font-weight<integer>400
--instui-component-form-field-layout-gap-inputs<length>0.75rem
--instui-component-form-field-layout-gap-primitives<length>0.5rem
--instui-component-form-field-layout-line-height<length>1.125rem
--instui-component-form-field-layout-readonly-text-color<color>LightDarklight-dark(#576773, #AAB0B5)
--instui-component-form-field-layout-text-color<color>LightDarklight-dark(#273540, #ffffff)

Browser support ​

  • Contains its element styles with the CSS @scope at-rule; needs a recent Chromium, Firefox, or Safari.

Subcomponents ​