Forms

Examples and usage guidelines for form control styles, layout options, and custom components for creating a wide variety of forms.

Inputs

Default

<div class="mb-3">
    <input type="text" class="form-control" placeholder="Default input">
</div>

Muted

<div class="mb-3">
    <input type="text" class="form-control form-control-muted" placeholder="Muted input">
</div>

Options

States

<div class="mb-3">
    <input type="text" class="form-control is-valid" placeholder="Is valid">
</div>
<div class="mb-3">
    <input type="text" class="form-control is-invalid" placeholder="Is invalid">
</div>
<div class="mb-3">
    <input type="text" class="form-control" placeholder="Disabled" disabled>
</div>

Sizing

<input class="form-control form-control-lg" type="text" placeholder=".form-control-lg" aria-label=".form-control-lg example">
                                                            <input class="form-control" type="text" placeholder="Default input" aria-label="default input example">
                                                            <input class="form-control form-control-sm" type="text" placeholder=".form-control-sm" aria-label=".form-control-sm example">

Textarea

Default

<textarea class="form-control" placeholder="You can manually resize this textarea" rows="3"></textarea>

Floating labels

Wrap a pair of <input class="form-control"> and <label> elements in .form-floating to enable floating labels with Bootstrap’s textual form fields. A placeholder is required on each <input> as our method of CSS-only floating labels uses the :placeholder-shown pseudo-element. Also note that the <input> must come first so we can utilize a sibling selector (e.g., ~).

<div class="form-floating mb-3">
                                                            <input type="email" class="form-control" id="floatingInput" placeholder="name@example.com">
                                                            <label for="floatingInput">Email address</label>
                                                          </div>
                                                          <div class="form-floating">
                                                            <input type="password" class="form-control" id="floatingPassword" placeholder="Password">
                                                            <label for="floatingPassword">Password</label>
                                                          </div>

Textareas

By default, <textarea>s with .form-control will be the same height as <input>s.

<div class="form-floating">
                                                            <textarea class="form-control" placeholder="Leave a comment here" id="floatingTextarea"></textarea>
                                                            <label for="floatingTextarea">Comments</label>
                                                          </div>

Select

Other than .form-control, floating labels are only available on .form-selects. They work in the same way, but unlike <input>s, they’ll always show the <label> in its floated state. Selects with size and multiple are not supported.

<div class="form-floating">
                                                            <select class="form-select" id="floatingSelect" aria-label="Floating label select example">
                                                              <option selected>Open this select menu</option>
                                                              <option value="1">One</option>
                                                              <option value="2">Two</option>
                                                              <option value="3">Three</option>
                                                            </select>
                                                            <label for="floatingSelect">Works with selects</label>
                                                          </div>

Layout

When working with the Bootstrap grid system, be sure to place form elements within column classes.

<div class="row g-2">
                                                            <div class="col-md">
                                                              <div class="form-floating">
                                                                <input type="email" class="form-control" id="floatingInputGrid" placeholder="name@example.com" value="mdo@example.com">
                                                                <label for="floatingInputGrid">Email address</label>
                                                              </div>
                                                            </div>
                                                            <div class="col-md">
                                                              <div class="form-floating">
                                                                <select class="form-select" id="floatingSelectGrid" aria-label="Floating label select example">
                                                                  <option selected>Open this select menu</option>
                                                                  <option value="1">One</option>
                                                                  <option value="2">Two</option>
                                                                  <option value="3">Three</option>
                                                                </select>
                                                                <label for="floatingSelectGrid">Works with selects</label>
                                                              </div>
                                                            </div>
                                                          </div>

Custom Forms

Checkboxes

<div class="form-check custom-checkbox">
    <input type="checkbox" class="form-check-input" id="customCheck1">
    <label class="form-check-label" for="customCheck1">Check this custom checkbox</label>
</div>

Custom checkboxes can also utilize the :indeterminate> pseudo class when manually set via JavaScript (there is no available HTML attribute for specifying it).

<div class="form-check custom-checkbox">
    <input type="checkbox" class="form-check-input" id="customCheck2" data-bs-toggle="indeterminate">
    <label class="form-check-label" for="customCheck2">Check this custom checkbox</label>
</div>

Radios

<div class="form-check custom-radio">
    <input type="radio" id="customRadio1" name="customRadio" class="form-check-input">
    <label class="form-check-label" for="customRadio1">Toggle this custom radio</label>
</div>
<div class="form-check custom-radio">
    <input type="radio" id="customRadio2" name="customRadio" class="form-check-input">
    <label class="form-check-label" for="customRadio2">Or toggle this other custom radio</label>
</div>

<div class="form-check custom-radio form-check-inline">
    <input type="radio" id="customRadioInline1" name="customRadioInline1" class="form-check-input">
    <label class="form-check-label" for="customRadioInline1">Toggle this custom radio</label>
</div>
<div class="form-check custom-radio form-check-inline">
    <input type="radio" id="customRadioInline2" name="customRadioInline1" class="form-check-input">
    <label class="form-check-label" for="customRadioInline2">Or toggle this other custom radio</label>
</div>

Switches

<div class="form-check form-switch">
  <input type="checkbox" class="form-check-input" id="customSwitch1">
  <label class="form-check-label" for="customSwitch1">Toggle this switch element</label>
</div>

Select menu

<select class="form-select">
    <option selected>Open this select menu</option>
    <option value="1">One</option>
    <option value="2">Two</option>
    <option value="3">Three</option>
</select>

You may also choose from small and large custom selects to match our similarly sized text inputs.

<select class="form-select form-select-lg mb-3">
  <option selected>Open this select menu</option>
  <option value="1">One</option>
  <option value="2">Two</option>
  <option value="3">Three</option>
</select>

<select class="form-select form-select-sm">
  <option selected>Open this select menu</option>
  <option value="1">One</option>
  <option value="2">Two</option>
  <option value="3">Three</option>
</select>

Range

Create custom <input type="range"> controls with .form-range. The track (the background) and thumb (the value) are both styled to appear the same across browsers. As only IE and Firefox support “filling” their track from the left or right of the thumb as a means to visually indicate progress, we do not currently support it.

<label for="customRange1">Example range</label>
<input type="range" class="form-range" id="customRange1">

Range inputs have implicit values for min and max0 and 100, respectively. You may specify new values for those using the min and max attributes.

<label for="customRange2">Example range</label>
<input type="range" class="form-range" min="0" max="5" id="customRange2">

By default, range inputs “snap” to integer values. To change this, you can specify a step value. In the example below, we double the number of steps by using step="0.5".

<label for="customRange3">Example range</label>
<input type="range" class="form-range" min="0" max="5" step="0.5" id="customRange3">

File browser

<div class="form-file">
                                                            <input type="file" class="form-file-input" id="customFile">
                                                            <label class="form-file-label" for="customFile">
                                                              <span class="form-file-text">Choose file...</span>
                                                              <span class="form-file-button">Browse</span>
                                                            </label>
                                                          </div>

Validation

Custom styles

For custom Bootstrap form validation messages, you’ll need to add the novalidate boolean attribute to your <form>. This disables the browser default feedback tooltips, but still provides access to the form validation APIs in JavaScript. Try to submit the form below; our JavaScript will intercept the submit button and relay feedback to you. When attempting to submit, you’ll see the :invalid and :valid styles applied to your form controls.

Custom feedback styles apply custom colors, borders, focus styles, and background icons to better communicate feedback. Background icons for <select>s are only available with .form-select, and not .form-control.

Looks good!
Looks good!
@
Please choose a username.
Please provide a valid city.
Please provide a valid state.
Please provide a valid zip.
You must agree before submitting.
<form class="needs-validation" novalidate>
  <div class="row">
    <div class="col-md-4 mb-3">
      <label for="validationCustom01">First name</label>
      <input type="text" class="form-control" id="validationCustom01" placeholder="First name" value="Mark" required>
      <div class="valid-feedback">
        Looks good!
      </div>
    </div>
    <div class="col-md-4 mb-3">
      <label for="validationCustom02">Last name</label>
      <input type="text" class="form-control" id="validationCustom02" placeholder="Last name" value="Otto" required>
      <div class="valid-feedback">
        Looks good!
      </div>
    </div>
    <div class="col-md-4 mb-3">
      <label for="validationCustomUsername">Username</label>
      <div class="input-group input-group-merge">
        <div class="input-group-prepend">
          <span class="input-group-text" id="inputGroupPrepend">@</span>
        </div>
        <input type="text" class="form-control" id="validationCustomUsername" placeholder="Username" aria-describedby="inputGroupPrepend" required>
        <div class="invalid-feedback">
          Please choose a username.
        </div>
      </div>
    </div>
  </div>
  <div class="row">
    <div class="col-md-6 mb-3">
      <label for="validationCustom03">City</label>
      <input type="text" class="form-control" id="validationCustom03" placeholder="City" required>
      <div class="invalid-feedback">
        Please provide a valid city.
      </div>
    </div>
    <div class="col-md-3 mb-3">
      <label for="validationCustom04">State</label>
      <input type="text" class="form-control" id="validationCustom04" placeholder="State" required>
      <div class="invalid-feedback">
        Please provide a valid state.
      </div>
    </div>
    <div class="col-md-3 mb-3">
      <label for="validationCustom05">Zip</label>
      <input type="text" class="form-control" id="validationCustom05" placeholder="Zip" required>
      <div class="invalid-feedback">
        Please provide a valid zip.
      </div>
    </div>
  </div>
  <div class="mb-3">
    <div class="form-check">
      <input class="form-check-input" type="checkbox" value="" id="invalidCheck" required>
      <label class="form-check-label" for="invalidCheck">
        Agree to terms and conditions
      </label>
      <div class="invalid-feedback">
        You must agree before submitting.
      </div>
    </div>
  </div>
  <button class="btn btn-primary" type="submit">Submit form</button>
</form>
// Example starter JavaScript for disabling form submissions if there are invalid fields
                                                    (function() {
                                                        'use strict'

                                                        // Fetch all the forms we want to apply custom Bootstrap validation styles to
                                                        var forms = document.querySelectorAll('.needs-validation')

                                                        // Loop over them and prevent submission
                                                        Array.prototype.slice.call(forms)
                                                            .forEach(function(form) {
                                                                form.addEventListener('submit', function(event) {
                                                                    if (!form.checkValidity()) {
                                                                        event.preventDefault()
                                                                        event.stopPropagation()
                                                                    }

                                                                    form.classList.add('was-validated')
                                                                }, false)
                                                            })
                                                    })()

Browser defaults

Not interested in custom validation feedback messages or writing JavaScript to change form behaviors? All good, you can use the browser defaults. Try submitting the form below. Depending on your browser and OS, you’ll see a slightly different style of feedback.

@
<form>
  <div class="row">
    <div class="col-md-4 mb-3">
      <label for="validationDefault01">First name</label>
      <input type="text" class="form-control" id="validationDefault01" placeholder="First name" value="Mark" required>
    </div>
    <div class="col-md-4 mb-3">
      <label for="validationDefault02">Last name</label>
      <input type="text" class="form-control" id="validationDefault02" placeholder="Last name" value="Otto" required>
    </div>
    <div class="col-md-4 mb-3">
      <label for="validationDefaultUsername">Username</label>
      <div class="input-group">
        <div class="input-group-prepend">
          <span class="input-group-text" id="inputGroupPrepend2">@</span>
        </div>
        <input type="text" class="form-control" id="validationDefaultUsername" placeholder="Username" aria-describedby="inputGroupPrepend2" required>
      </div>
    </div>
  </div>
  <div class="row">
    <div class="col-md-6 mb-3">
      <label for="validationDefault03">City</label>
      <input type="text" class="form-control" id="validationDefault03" placeholder="City" required>
    </div>
    <div class="col-md-3 mb-3">
      <label for="validationDefault04">State</label>
      <input type="text" class="form-control" id="validationDefault04" placeholder="State" required>
    </div>
    <div class="col-md-3 mb-3">
      <label for="validationDefault05">Zip</label>
      <input type="text" class="form-control" id="validationDefault05" placeholder="Zip" required>
    </div>
  </div>
  <div class="mb-3">
    <div class="form-check">
      <input class="form-check-input" type="checkbox" value="" id="invalidCheck2" required>
      <label class="form-check-label" for="invalidCheck2">
        Agree to terms and conditions
      </label>
    </div>
  </div>
  <button class="btn btn-primary" type="submit">Submit form</button>
</form>

Server side

We recommend using client side validation, but in case you require server side, you can indicate invalid and valid form fields with .is-invalid and .is-valid. Note that .invalid-feedback is also supported with these classes.

Looks good!
Looks good!
@
Please choose a username.
Please provide a valid city.
Please provide a valid state.
Please provide a valid zip.
You must agree before submitting.
<form>
  <div class="row">
    <div class="col-md-4 mb-3">
      <label for="validationServer01">First name</label>
      <input type="text" class="form-control is-valid" id="validationServer01" placeholder="First name" value="Mark" required>
      <div class="valid-feedback">
        Looks good!
      </div>
    </div>
    <div class="col-md-4 mb-3">
      <label for="validationServer02">Last name</label>
      <input type="text" class="form-control is-valid" id="validationServer02" placeholder="Last name" value="Otto" required>
      <div class="valid-feedback">
        Looks good!
      </div>
    </div>
    <div class="col-md-4 mb-3">
      <label for="validationServerUsername">Username</label>
      <div class="input-group">
        <div class="input-group-prepend">
          <span class="input-group-text" id="inputGroupPrepend3">@</span>
        </div>
        <input type="text" class="form-control is-invalid" id="validationServerUsername" placeholder="Username" aria-describedby="inputGroupPrepend3" required>
        <div class="invalid-feedback">
          Please choose a username.
        </div>
      </div>
    </div>
  </div>
  <div class="row">
    <div class="col-md-6 mb-3">
      <label for="validationServer03">City</label>
      <input type="text" class="form-control is-invalid" id="validationServer03" placeholder="City" required>
      <div class="invalid-feedback">
        Please provide a valid city.
      </div>
    </div>
    <div class="col-md-3 mb-3">
      <label for="validationServer04">State</label>
      <input type="text" class="form-control is-invalid" id="validationServer04" placeholder="State" required>
      <div class="invalid-feedback">
        Please provide a valid state.
      </div>
    </div>
    <div class="col-md-3 mb-3">
      <label for="validationServer05">Zip</label>
      <input type="text" class="form-control is-invalid" id="validationServer05" placeholder="Zip" required>
      <div class="invalid-feedback">
        Please provide a valid zip.
      </div>
    </div>
  </div>
  <div class="mb-3">
    <div class="form-check">
      <input class="form-check-input is-invalid" type="checkbox" value="" id="invalidCheck3" required>
      <label class="form-check-label" for="invalidCheck3">
        Agree to terms and conditions
      </label>
      <div class="invalid-feedback">
        You must agree before submitting.
      </div>
    </div>
  </div>
  <button class="btn btn-primary" type="submit">Submit form</button>
</form>