Form group
Form group adds structure to forms.
Examples
Structure
Guidelines
Use a form group to associate a label or legend, description, help text, and validation feedback with form controls. See the forms pattern for guidance on composing a form.
Appearance
Form groups stack their label above the controls. Use label-description for text directly below the label and description for help text below the controls. Both have named slots for content that includes markup.
Behavior
Labels and grouping
Set label to name the field, or use the label slot for custom content. For a single input, set label-for to the input's unique id, without a leading #. This renders a <div> containing a <label> associated with the input.
For multiple related controls, or checkbox and radio groups with their own input labels, omit label-for. The form group renders a <fieldset> with a <legend> naming the group. Each control still needs its own label. You can nest form groups to label individual fields within a related group:
Set optional to append (optional) to the label, or customize it with optional-text. When using the label slot, include any optional suffix in the slot content yourself.
Disabled groups
The disabled prop disables native form controls inside the rendered <fieldset>. It has no effect when label-for is set, because the group renders a <div>. In that case, set disabled on the input itself.
Validation
Form groups in GitLab pair a label with an input and often description text below the label, and help text below the field, and a validation message that appears once the field is in an invalid state. Bind the same state to both the form group and the input so the message and the input styling stay in sync.
false: Invalid. Provideinvalid-feedbacktext explaining how to correct the input.true: Valid. Usevalid-feedbackonly when a success message is useful.null: No validation state.
The invalid-feedback and valid-feedback slots support custom markup. Explicitly setting the group's state makes the corresponding feedback visible even when the input is nested in another component. Feedback appears below the controls and above help text, with aria-live="assertive".
Accessibility
Prefer a visible label. If the surrounding context already identifies the field visually, label-sr-only hides the label or legend while keeping its content available to screen readers, including the optional suffix and label description.
With label-for, the form group adds help text and the active validation feedback to the target control's aria-describedby, preserving existing references. The target must be inside the form group.
Without label-for, associate the help text and feedback with each control using ariaDescribedby from the scoped default slot:
Code reference
GlFormGroup
The default slot exposes ariaDescribedby, descriptionId, id, and labelId. These IDs reference the group's rendered elements and can be used to associate custom controls with them.
label-class accepts a string, array, or object of additional label classes. label-size accepts sm or lg to apply the corresponding Bootstrap label-size class; the default Pajamas label styling is recommended.
import { GlFormGroup } from '@gitlab/ui';Props
Name | Description | Default |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Slots
Name | Description |
|---|---|
label | Content of the label or legend. Replaces the `label` prop and the optional text. |
label-description | Content shown below the label. Replaces the `label-description` prop. |
default | The form controls of the group. |
invalid-feedback | Content of the invalid feedback. Replaces the `invalid-feedback` prop. |
valid-feedback | Content of the valid feedback. Replaces the `valid-feedback` prop. |
description | Help text shown below the form controls. Replaces the `description` prop. |
Last updated at: