The <FormControl> component renders a form control with Bootstrap styling. The <FormGroup> component wraps a form control with proper spacing, along with support for a label, help text, and validation state. To ensure accessibility, set controlId on <FormGroup>, and use <FormLabel> for the label.
The <FormControl> component directly renders the <input> or other specified component. If you need to access the value of an uncontrolled <FormControl>, attach a ref to it as you would with an uncontrolled input, then call ReactDOM.findDOMNode(ref) to get the DOM node. You can then interact with that node as you would with any other uncontrolled input.
If your application contains a large number of form groups, we recommend building a higher-level component encapsulating a complete field group that renders the label, the control, and any other necessary components. We don't provide this out-of-the-box, because the composition of those field groups is too specific to an individual application to admit a good one-size-fits-all solution.
For textual form controls—like inputs, selects, and textareas—use the FormControl component. FormControl adds some additional styles for general appearance, focus state, sizing, and more.
If you want to have elements in your form styled as plain text, use the plaintext prop on FormControls to remove the default form field styling and preserve the correct margin and padding.
For the non-textual checkbox and radio controls, FormCheck provides a single component for both types that adds some additional styling and improved layout.
When you render a FormCheck without a label (no children) some additional styling is applied to keep the inputs from collapsing. Remember to add an aria-label when omitting labels!
When you need tighter control, or want to customize how the FormCheck component renders, it may better to use it's constituent parts directly.
By provided children to the FormCheck you can forgo the default rendering and handle it yourself. (You can still provide an id to the FormCheck or FormGroup and have it propagate to the label and input).
<Form>
{['checkbox','radio'].map(type=>(
<divkey={type}className="mb-3">
<Form.Checktype={type}id={`check-api-${type}`}>
<Form.Check.Inputtype={type}isValid/>
<Form.Check.Label>{`Custom api ${type}`}</Form.Check.Label>
<Form.Control.Feedbacktype="valid">You did it!</Form.Control.Feedback>
FormControl and FormCheck both apply display: block with width: 100% to controls, which means they stack vertically by default. Additional components and props can be used to vary this layout on a per-form basis.
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. By default it only applies margin-bottom, but it picks up additional styles in <Form inline > as needed. Use it with fieldsets, divs, or nearly any other element.
You also add the controlId prop to accessibly wire the nested label and input together via the id.
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.
You may also swap <Row> for <Form.Row>, a variation of the standard grid row that overrides the default column gutters for tighter and more compact layouts.
<Form>
<Form.Row>
<Col>
<Form.Controlplaceholder="First name"/>
</Col>
<Col>
<Form.Controlplaceholder="Last name"/>
</Col>
</Form.Row>
</Form>
More complex layouts can also be created with the grid system.
You may also swap <Row> for <Form.Row>, a variation of the standard grid row that overrides the default column gutters for tighter and more compact layouts.
For native HTML form validation–available in all our supported browsers, the :valid and :invalid pseudo selectors are used to apply validation styles as well as display feedback messages.
Bootstrap scopes the :valid and :invalid styles to parent .was-validated class, usually applied to the Form (you can use the validated prop as a shortcut). Otherwise, any required field without a value shows up as invalid on page load. This way, you may choose when to activate them (typically after form submission is attempted).
It's often beneficial (especially in React) to handle form validation via a library like Formik, or react-formal. In those cases, isValid and isInvalid props can be added to form controls to manually apply validation styles. Below is a quick example integrating with Formik.
For even more customization and cross browser consistency, use our completely custom form elements to replace the browser defaults. They’re built on top of semantic and accessible markup, so they’re solid replacements for any default form control.
Custom checkbox and radio styles are achieved with a resourceful use of the :checked selector and :after pseudo elements, but are Structurally similar to the default FormCheck. By default the checked and indeterminate icons use embedded svg icons from Open Iconic.
Apply Bootstrap's custom elements by adding the custom prop.
A switch has the markup of a custom checkbox but uses type="switch" to render a toggle switch. Switches also support the same customizable children as <FormCheck>.
import Form from 'react-bootstrap/Form'Copy import code for the Form component
Name
Type
Default
Description
ref
ReactRef
The Form ref will be forwarded to the underlying element,
which means, unless it's rendered as a composite component,
it will be a DOM node, when resolved.
as
elementType
You can use a custom element type for this component.
inline
boolean
false
Display the series of labels, form controls,
and buttons on a single horizontal row
validated
boolean
Mark a form as having been validated. Setting it to true will
toggle any validation styles on the forms elements.
bsPrefix
string
{'form'}
Change the underlying component CSS base class name and modifier class names prefix. This is an escape hatch for working with heavily customized bootstrap css.
import Form from 'react-bootstrap/Form'Copy import code for the Form component
Name
Type
Default
Description
as
elementType
<div>
You can use a custom element type for this component.
bsPrefix required
string
'form-row'
Change the underlying component CSS base class name and modifier class names prefix. This is an escape hatch for working with heavily customized bootstrap css.
import Form from 'react-bootstrap/Form'Copy import code for the Form component
Name
Type
Default
Description
ref
ReactRef
The FormGroup ref will be forwarded to the underlying element.
Unless the FormGroup is rendered as a composite component,
it will be a DOM node, when resolved.
as
elementType
You can use a custom element type for this component.
controlId
string
Sets id on <FormControl> and htmlFor on <FormGroup.Label>.
bsPrefix
string
'form-group'
Change the underlying component CSS base class name and modifier class names prefix. This is an escape hatch for working with heavily customized bootstrap css.
import Form from 'react-bootstrap/Form'Copy import code for the Form component
Name
Type
Default
Description
ref
ReactRef
The FormLabel ref will be forwarded to the underlying element.
Unless the FormLabel is rendered as a composite component,
it will be a DOM node, when resolved.
column
boolean
false
Renders the FormLabel as a <Col> component (accepting all the same props),
as well as adding additional styling for horizontal forms.
htmlFor
string
Uses controlId from <FormGroup> if not explicitly specified.
srOnly
boolean
false
Hides the label visually while still allowing it to be
read by assistive technologies.
bsPrefix
string
'form-label'
Change the underlying component CSS base class name and modifier class names prefix. This is an escape hatch for working with heavily customized bootstrap css.
import Form from 'react-bootstrap/Form'Copy import code for the Form component
Name
Type
Default
Description
ref
ReactRef
The FormControl ref will be forwarded to the underlying input element,
which means unless as is a composite component,
it will be a DOM node, when resolved.
as
'input' | 'textarea' | 'select' | elementType
The underlying HTML element to use when rendering the FormControl.
disabled
boolean
Make the control disabled
id
string
Uses controlId from <FormGroup> if not explicitly specified.
isInvalid
boolean
Add "invalid" validation styles to the control and accompanying label
isValid
boolean
Add "valid" validation styles to the control
onChange
function
A callback fired when the value prop changes
plaintext
boolean
Render the input as plain text. Generally used along side readOnly.
readOnly
boolean
Make the control readonly
size
'sm' | 'lg'
Input size variants
type
string
The HTML input type, which is only relevant if as is 'input' (the default).
Change the underlying component CSS base class name and modifier class names prefix. This is an escape hatch for working with heavily customized bootstrap css.
import Form from 'react-bootstrap/Form'Copy import code for the Form component
Name
Type
Default
Description
ref
ReactRef
The FormCheck ref will be forwarded to the underlying input element,
which means it will be a DOM node, when resolved.
as
'input' | elementType
The underlying HTML element to use when rendering the FormCheck.
children
node
Provide a function child to manually handle the layout of the FormCheck's inner components.
<FormCheck><FormCheck.InputisInvalidtype={radio}/><FormCheck.Label>Allow us to contact you?</FormCheck.Label><Feedbacktype="invalid">Yo this is required</Feedback></FormCheck>
custom
boolean
Use Bootstrap's custom form elements to replace the browser defaults
disabled
boolean
false
feedback
node
A message to display when the input is in a validation state
id
string
A HTML id attribute, necessary for proper form accessibility.
inline
boolean
false
isInvalid
boolean
false
Manually style the input as invalid
isValid
boolean
false
Manually style the input as valid
label
node
title
string
''
type
'radio' | 'checkbox' | 'switch'
'checkbox'
The type of checkable.
bsPrefix
string
'form-check'
Change the underlying component CSS base class name and modifier class names prefix. This is an escape hatch for working with heavily customized bootstrap css.
import FormCheck from 'react-bootstrap/FormCheck'Copy import code for the FormCheck component
Name
Type
Default
Description
as
'input' | elementType
The underlying HTML element to use when rendering the FormCheckInput.
id
string
A HTML id attribute, necessary for proper form accessibility.
isInvalid required
boolean
Manually style the input as invalid
isStatic
boolean
A convenience prop shortcut for adding position-static to the input, for
correct styling when used without an FormCheckLabel
isValid required
boolean
Manually style the input as valid
type
'radio' | 'checkbox'
'checkbox'
The type of checkable.
bsPrefix
string
'form-check-input'
Change the underlying component CSS base class name and modifier class names prefix. This is an escape hatch for working with heavily customized bootstrap css.
import FormCheck from 'react-bootstrap/FormCheck'Copy import code for the FormCheck component
Name
Type
Default
Description
htmlFor
string
The HTML for attribute for associating the label with an input
bsPrefix
string
'form-check-input'
Change the underlying component CSS base class name and modifier class names prefix. This is an escape hatch for working with heavily customized bootstrap css.