Layout

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

Form groups

The FormGroup component is the easiest way to add some structure to forms. It provides a flexible container for grouping of labels, controls, optional help text, and form validation messaging. Use it with fieldsets, dids, or nearly any other element.

You also add the controlId prop to accessibly wire the nested label and input together via the id.

<Form>
<Form.Group className="mb-3" controlId="formGroupEmail">
<Form.Label>Email address</Form.Label>
<Form.Control type="email" placeholder="Enter email" />
</Form.Group>
<Form.Group className="mb-3" controlId="formGroupPassword">
<Form.Label>Password</Form.Label>
<Form.Control type="password" placeholder="Password" />
</Form.Group>
</Form>

Form grid

More complex forms can be built using the grid components. Use these for form layouts that require multiple columns, varied widths, and additional alignment options.

<Form>
<Row>
<Col>
<Form.Control placeholder="First name" />
</Col>
<Col>
<Form.Control placeholder="Last name" />
</Col>
</Row>
</Form>

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

<Form>
<Row className="mb-3">
<Form.Group as={Col} controlId="formGridEmail">
<Form.Label>Email</Form.Label>
<Form.Control type="email" placeholder="Enter email" />
</Form.Group>
<Form.Group as={Col} controlId="formGridPassword">
<Form.Label>Password</Form.Label>
<Form.Control type="password" placeholder="Password" />
</Form.Group>
</Row>
<Form.Group className="mb-3" controlId="formGridAddress1">
<Form.Label>Address</Form.Label>
<Form.Control placeholder="1234 Main St" />
</Form.Group>
<Form.Group className="mb-3" controlId="formGridAddress2">
<Form.Label>Address 2</Form.Label>
<Form.Control placeholder="Apartment, studio, or floor" />
</Form.Group>
<Row className="mb-3">
<Form.Group as={Col} controlId="formGridCity">
<Form.Label>City</Form.Label>
<Form.Control />
</Form.Group>
<Form.Group as={Col} controlId="formGridState">
<Form.Label>State</Form.Label>
<Form.Select defaultValue="Choose...">
<option>Choose...</option>
<option>...</option>
</Form.Select>
</Form.Group>
<Form.Group as={Col} controlId="formGridZip">
<Form.Label>Zip</Form.Label>
<Form.Control />
</Form.Group>
</Row>
<Form.Group className="mb-3" id="formGridCheckbox">
<Form.Check type="checkbox" label="Check me out" />
</Form.Group>
<Button variant="primary" type="submit">
Submit
</Button>
</Form>

Horizontal form

Create horizontal forms with the grid by adding as=❴Row❵ to form groups and using Col to specify the width of your labels and controls. Be sure to add the column prop to your FormLabels as well so they're vertically centered with their associated form controls.

At times, you maybe need to use margin or padding utilities to create that perfect alignment you need. For example, we've removed the padding-top on our stacked radio inputs label to better align the text baseline.

<Form>
<Form.Group as={Row} className="mb-3" controlId="formHorizontalEmail">
<Form.Label column sm={2}>
Email
</Form.Label>
<Col sm={10}>
<Form.Control type="email" placeholder="Email" />
</Col>
</Form.Group>
<Form.Group as={Row} className="mb-3" controlId="formHorizontalPassword">
<Form.Label column sm={2}>
Password
</Form.Label>
<Col sm={10}>
<Form.Control type="password" placeholder="Password" />
</Col>
</Form.Group>
<fieldset>
<Form.Group as={Row} className="mb-3">
<Form.Label as="legend" column sm={2}>
Radios
</Form.Label>
<Col sm={10}>
<Form.Check
type="radio"
label="first radio"
name="formHorizontalRadios"
id="formHorizontalRadios1"
/>
<Form.Check
type="radio"
label="second radio"
name="formHorizontalRadios"
id="formHorizontalRadios2"
/>
<Form.Check
type="radio"
label="third radio"
name="formHorizontalRadios"
id="formHorizontalRadios3"
/>
</Col>
</Form.Group>
</fieldset>
<Form.Group as={Row} className="mb-3" controlId="formHorizontalCheck">
<Col sm={{ span: 10, offset: 2 }}>
<Form.Check label="Remember me" />
</Col>
</Form.Group>
<Form.Group as={Row} className="mb-3">
<Col sm={{ span: 10, offset: 2 }}>
<Button type="submit">Sign in</Button>
</Col>
</Form.Group>
</Form>

Horizontal form label sizing

You can size the <FormLabel> using the column prop as shown.



<Form>
<Row>
<Form.Label column="lg" lg={2}>
Large Text
</Form.Label>
<Col>
<Form.Control size="lg" type="text" placeholder="Large text" />
</Col>
</Row>
<br />
<Row>
<Form.Label column lg={2}>
Normal Text
</Form.Label>
<Col>
<Form.Control type="text" placeholder="Normal text" />
</Col>
</Row>
<br />
<Row>
<Form.Label column="sm" lg={2}>
Small Text
</Form.Label>
<Col>
<Form.Control size="sm" type="text" placeholder="Small text" />
</Col>
</Row>
</Form>

Column sizing

As shown in the previous examples, our grid system allows you to place any number of <Col>s within a <Row>. They'll split the available width equally between them. You may also pick a subset of your columns to take up more or less space, while the remaining <Col>s equally split the rest, with specific column classes like <Col xs=❴7❵>.

<Form>
<Row>
<Col xs={7}>
<Form.Control placeholder="City" />
</Col>
<Col>
<Form.Control placeholder="State" />
</Col>
<Col>
<Form.Control placeholder="Zip" />
</Col>
</Row>
</Form>

Auto-sizing

The example below uses a flexbox utility to vertically center the contents and changes <Col> to <Col xs="auto"> so that your columns only take up as much space as needed. Put another way, the column sizes itself based on on the contents.

@
<Form>
<Row className="align-items-center">
<Col xs="auto">
<Form.Label htmlFor="inlineFormInput" visuallyHidden>
Name
</Form.Label>
<Form.Control
className="mb-2"
id="inlineFormInput"
placeholder="Jane Doe"
/>
</Col>
<Col xs="auto">
<Form.Label htmlFor="inlineFormInputGroup" visuallyHidden>
Username
</Form.Label>
<InputGroup className="mb-2">
<InputGroup.Text>@</InputGroup.Text>
<FormControl id="inlineFormInputGroup" placeholder="Username" />
</InputGroup>
</Col>
<Col xs="auto">
<Form.Check
type="checkbox"
id="autoSizingCheck"
className="mb-2"
label="Remember me"
/>
</Col>
<Col xs="auto">
<Button type="submit" className="mb-2">
Submit
</Button>
</Col>
</Row>
</Form>

You can then remix that once again with size-specific column classes.

@
<Form>
<Row className="align-items-center">
<Col sm={3} className="my-1">
<Form.Label htmlFor="inlineFormInputName" visuallyHidden>
Name
</Form.Label>
<Form.Control id="inlineFormInputName" placeholder="Jane Doe" />
</Col>
<Col sm={3} className="my-1">
<Form.Label htmlFor="inlineFormInputGroupUsername" visuallyHidden>
Username
</Form.Label>
<InputGroup>
<InputGroup.Text>@</InputGroup.Text>
<FormControl id="inlineFormInputGroupUsername" placeholder="Username" />
</InputGroup>
</Col>
<Col xs="auto" className="my-1">
<Form.Check type="checkbox" id="autoSizingCheck2" label="Remember me" />
</Col>
<Col xs="auto" className="my-1">
<Button type="submit">Submit</Button>
</Col>
</Row>
</Form>