Loading...
Skip to main content

Layout

Give your forms some structure—from inline to horizontal to custom grid implementations—with our form layout options.

Forms

Every group of form fields should reside in a Form element. Form preserves native browser form behavior and passes standard form attributes through.

  • New to browser forms? Consider reviewing the MDN form docs for an overview and complete list of available attributes.
  • Button components inside a Form default to type="button", so set type="submit" explicitly on submit buttons.

The form control wrappers fill their available width, so fields stack vertically by default. Use spacing and grid utilities through the layout components' className props to vary this layout.

Utilities

Margin utilities are the easiest way to add structure to forms. Pass them through FormField's className to space labels, controls, optional form text, and validation feedback. Use a single direction throughout the form for consistency.

Use semantic elements such as fieldset where appropriate; the Form wrapper can also render as a different element with its as prop.

<>
<FormField className="mb-3">
<FormLabel htmlFor="formGroupExampleInput">
Example label
</FormLabel>
<FormControl
id="formGroupExampleInput"
placeholder="Example input placeholder"
type="text"
/>
</FormField>
<FormField className="mb-3">
<FormLabel htmlFor="formGroupExampleInput2">
Another label
</FormLabel>
<FormControl
id="formGroupExampleInput2"
placeholder="Another input placeholder"
type="text"
/>
</FormField>
</>

Form grid

Use Row and Col for form layouts that require multiple columns, varied widths, and additional alignment options. Set responsive column spans with the Col breakpoint props.

<Row>
<Col>
<FormControl
aria-label="First name"
placeholder="First name"
type="text"
/>
</Col>
<Col>
<FormControl
aria-label="Last name"
placeholder="Last name"
type="text"
/>
</Col>
</Row>

Gutters

Set gutter utilities through Row's className to control spacing between columns in both directions.

<Row className="g-3">
<Col>
<FormControl
aria-label="First name"
placeholder="First name"
type="text"
/>
</Col>
<Col>
<FormControl
aria-label="Last name"
placeholder="Last name"
type="text"
/>
</Col>
</Row>

More complex layouts can also be created with the grid system.

<Row
as={function ve(){}}
className="g-3"
>
<Col md={6}>
<FormLabel htmlFor="inputEmail4">
Email
</FormLabel>
<FormControl
id="inputEmail4"
type="email"
/>
</Col>
<Col md={6}>
<FormLabel htmlFor="inputPassword4">
Password
</FormLabel>
<FormControl
id="inputPassword4"
type="password"
/>
</Col>
<Col xs={12}>
<FormLabel htmlFor="inputAddress">
Address
</FormLabel>
<FormControl
id="inputAddress"
placeholder="1234 Main St"
type="text"
/>
</Col>
<Col xs={12}>
<FormLabel htmlFor="inputAddress2">
Address 2
</FormLabel>
<FormControl
id="inputAddress2"
placeholder="Apartment, studio, or floor"
type="text"
/>
</Col>
<Col md={6}>
<FormLabel htmlFor="inputCity">
City
</FormLabel>
<FormControl
id="inputCity"
type="text"
/>
</Col>
<Col md={4}>
<FormLabel htmlFor="inputState">
State
</FormLabel>
<FormSelect
defaultValue="Choose..."
id="inputState"
>
<option>
Choose...
</option>
<option>
...
</option>
</FormSelect>
</Col>
<Col md={2}>
<FormLabel htmlFor="inputZip">
Zip
</FormLabel>
<FormControl
id="inputZip"
type="text"
/>
</Col>
<Col xs={12}>
<FormField>
<Checkbox id="gridCheck" />
<FormLabel
htmlFor="gridCheck"
plain
>
Check me out
</FormLabel>
</FormField>
</Col>
<Col xs={12}>
<Button
theme="primary"
type="submit"
variant="solid"
>
Sign in
</Button>
</Col>
</Row>

Horizontal form

Create horizontal forms with the Row and Col layout components. Set the column breakpoint props (such as sm={2}) to size labels and controls, and use the column prop on FormLabel or FormLegend to align the label with its control.

Use margin or padding utilities through className on Row, Col, or FormLabel to adjust alignment. For example, removing top padding from a stacked radio label can better align its text baseline.

Radios

<Form>
<Row className="mb-3">
<Col
as={function ve(){}}
column
htmlFor="inputEmail3"
sm={2}
>
<p>
Email
</p>
</Col>
<Col sm={10}>
<FormControl
id="inputEmail3"
type="email"
/>
</Col>
</Row>
<Row className="mb-3">
<Col
as={function ve(){}}
column
htmlFor="inputPassword3"
sm={2}
>
<p>
Password
</p>
</Col>
<Col sm={10}>
<FormControl
id="inputPassword3"
type="password"
/>
</Col>
</Row>
<Row
as="fieldset"
className="mb-3"
>
<Col
as={function ve(){}}
className="pt-0"
column
sm={2}
>
<p>
Radios
</p>
</Col>
<Col sm={10}>
<FormGroup>
<FormField className="mb-1">
<Radio
defaultChecked
defaultValue="option1"
id="gridRadios1"
name="gridRadios"
/>
<FormLabel
htmlFor="gridRadios1"
plain
>
First radio
</FormLabel>
</FormField>
<FormField className="mb-1">
<Radio
defaultValue="option2"
id="gridRadios2"
name="gridRadios"
/>
<FormLabel
htmlFor="gridRadios2"
plain
>
Second radio
</FormLabel>
</FormField>
<FormField>
<Radio
defaultValue="option3"
disabled
id="gridRadios3"
name="gridRadios"
/>
<FormLabel
htmlFor="gridRadios3"
plain
>
Third disabled radio
</FormLabel>
</FormField>
</FormGroup>
</Col>
</Row>
<Row className="mb-3">
<Col
sm={{
offset: 2,
span: 10
}}
>
<FormField>
<Checkbox id="gridCheck1" />
<FormLabel
htmlFor="gridCheck1"
plain
>
Example checkbox
</FormLabel>
</FormField>
</Col>
</Row>
<Button
theme="primary"
type="submit"
variant="solid"
>
Sign in
</Button>
</Form>

Horizontal form label sizing

Set controlSize on FormLabel or FormLegend to match the controlSize of the associated form control.

<>
<Row className="mb-3">
<Col
as={function ve(){}}
column
controlSize="sm"
htmlFor="colFormLabelSm"
sm={2}
>
<p>
Email
</p>
</Col>
<Col sm={10}>
<FormControl
controlSize="sm"
id="colFormLabelSm"
placeholder="col-form-label-sm"
type="email"
/>
</Col>
</Row>
<Row className="mb-3">
<Col
as={function ve(){}}
column
htmlFor="colFormLabel"
sm={2}
>
<p>
Email
</p>
</Col>
<Col sm={10}>
<FormControl
id="colFormLabel"
placeholder="col-form-label"
type="email"
/>
</Col>
</Row>
<Row>
<Col
as={function ve(){}}
column
controlSize="lg"
htmlFor="colFormLabelLg"
sm={2}
>
<p>
Email
</p>
</Col>
<Col sm={10}>
<FormControl
controlSize="lg"
id="colFormLabelLg"
placeholder="col-form-label-lg"
type="email"
/>
</Col>
</Row>
</>

Column sizing

Place any number of Col components in a Row to split the available width equally. Set a breakpoint prop such as sm={7} to size one column while the remaining columns share the rest.

<Row className="g-3">
<Col sm={7}>
<FormControl
aria-label="City"
placeholder="City"
type="text"
/>
</Col>
<Col sm>
<FormControl
aria-label="State"
placeholder="State"
type="text"
/>
</Col>
<Col sm>
<FormControl
aria-label="Zip"
placeholder="Zip"
type="text"
/>
</Col>
</Row>

Auto-sizing

The example below passes a flexbox alignment utility through Row's className and sets the Col component's xs prop to "auto", so each column takes only as much space as its contents need.

@
<Row
as={function ve(){}}
className="gy-2 gx-3 align-items-center"
>
<Col xs="auto">
<FormLabel
className="visually-hidden"
htmlFor="autoSizingInput"
plain
>
Name
</FormLabel>
<FormControl
id="autoSizingInput"
placeholder="Jane Doe"
type="text"
/>
</Col>
<Col xs="auto">
<FormLabel
className="visually-hidden"
htmlFor="autoSizingInputGroup"
plain
>
Username
</FormLabel>
<InputGroup>
<InputGroupText>
@
</InputGroupText>
<FormControl
id="autoSizingInputGroup"
placeholder="Username"
type="text"
/>
</InputGroup>
</Col>
<Col xs="auto">
<FormLabel
className="visually-hidden"
htmlFor="autoSizingSelect"
plain
>
Preference
</FormLabel>
<FormSelect
defaultValue="Choose..."
id="autoSizingSelect"
>
<option>
Choose...
</option>
<option value="1">
One
</option>
<option value="2">
Two
</option>
<option value="3">
Three
</option>
</FormSelect>
</Col>
<Col xs="auto">
<FormField>
<Checkbox id="autoSizingCheck" />
<FormLabel
htmlFor="autoSizingCheck"
plain
>
Remember me
</FormLabel>
</FormField>
</Col>
<Col xs="auto">
<Button
theme="primary"
type="submit"
variant="solid"
>
Submit
</Button>
</Col>
</Row>

You can then combine responsive Col props to adjust the layout at multiple breakpoints.

@
<Row
as={function ve(){}}
className="gx-3 gy-2 align-items-center"
>
<Col sm={3}>
<FormLabel
className="visually-hidden"
htmlFor="specificSizeInputName"
plain
>
Name
</FormLabel>
<FormControl
id="specificSizeInputName"
placeholder="Jane Doe"
type="text"
/>
</Col>
<Col sm={3}>
<FormLabel
className="visually-hidden"
htmlFor="specificSizeInputGroupUsername"
plain
>
Username
</FormLabel>
<InputGroup>
<InputGroupText>
@
</InputGroupText>
<FormControl
id="specificSizeInputGroupUsername"
placeholder="Username"
type="text"
/>
</InputGroup>
</Col>
<Col sm={3}>
<FormLabel
className="visually-hidden"
htmlFor="specificSizeSelect"
plain
>
Preference
</FormLabel>
<FormSelect
defaultValue="Choose..."
id="specificSizeSelect"
>
<option>
Choose...
</option>
<option value="1">
One
</option>
<option value="2">
Two
</option>
<option value="3">
Three
</option>
</FormSelect>
</Col>
<Col xs="auto">
<FormField>
<Checkbox id="autoSizingCheck2" />
<FormLabel
htmlFor="autoSizingCheck2"
plain
>
Remember me
</FormLabel>
</FormField>
</Col>
<Col xs="auto">
<Button
theme="primary"
type="submit"
variant="solid"
>
Submit
</Button>
</Col>
</Row>

Inline forms

Use responsive Col props to create horizontal layouts. Add gutter and alignment utilities through Row's className; on narrow viewports, set xs={12} on each Col to stack the controls.

@
<Row
as={function ve(){}}
className="g-3 align-items-center"
lg="auto"
>
<Col xs={12}>
<FormLabel
className="visually-hidden"
htmlFor="inlineFormInputGroupUsername"
plain
>
Username
</FormLabel>
<InputGroup>
<InputGroupText>
@
</InputGroupText>
<FormControl
id="inlineFormInputGroupUsername"
placeholder="Username"
type="text"
/>
</InputGroup>
</Col>
<Col xs={12}>
<FormLabel
className="visually-hidden"
htmlFor="inlineFormSelectPref"
plain
>
Preference
</FormLabel>
<FormSelect
defaultValue="Choose..."
id="inlineFormSelectPref"
>
<option>
Choose...
</option>
<option value="1">
One
</option>
<option value="2">
Two
</option>
<option value="3">
Three
</option>
</FormSelect>
</Col>
<Col xs={12}>
<FormField>
<Checkbox id="inlineFormCheck" />
<FormLabel
htmlFor="inlineFormCheck"
plain
>
Remember me
</FormLabel>
</FormField>
</Col>
<Col xs={12}>
<Button
theme="primary"
type="submit"
variant="solid"
>
Submit
</Button>
</Col>
</Row>
Documentation navigation
On this page
On this page