Basic example

Individual form controls automatically receive some global styling. All textual <input>, <textarea>, and <select> elements with .form-control are set to width: 100%; by default. Wrap labels and controls in .form-group for optimum spacing.

Example block-level help text here.
<form>
  <div class="form-group">
    <label for="exampleInputEmail1">Email address</label>
    <input type="email" class="form-control" id="exampleInputEmail1" placeholder="Email">
  </div>
  <div class="form-group">
    <label for="exampleInputPassword1">Password</label>
    <input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password">
  </div>
  <div class="form-group">
    <label for="exampleInputFile">File input</label>
    <input class="form-control-file" type="file" id="exampleInputFile">
    <small class="form-text text-muted">Example block-level help text here.</small>
  </div>
  <div class="form-check">
    <input class="form-check-input" id="hm-login" type="checkbox">
    <label class="form-check-label" for="hm-login">Check me out</label>
  </div>
  <button type="submit" class="btn btn-light">Submit</button>
</form>

Don't mix form groups with input groups

Do not mix form groups directly with input groups. Instead, nest the input group inside of the form group.

Inline form

Add .form-inline to your form (which doesn’t have to be a <form>) for left-aligned and inline-block controls. This only applies to forms within viewports that are at least 768px wide.

May require custom widths

Inputs and selects have width: 100%; applied by default in Bootstrap. Within inline forms, we reset that to width: auto; so multiple controls can reside on the same line. Depending on your layout, additional custom widths may be required.

Always add labels

Screen readers will have trouble with your forms if you don't include a label for every input. For these inline forms, you can hide the labels using the .sr-only class. There are further alternative methods of providing a label for assistive technologies, such as the aria-label, aria-labelledby or title attribute. If none of these is present, screen readers may resort to using the placeholder attribute, if present, but note that use of placeholder as a replacement for other labelling methods is not advised.

<form class="form-inline">
  <div class="form-group mr-2">
    <label class="mr-1" for="exampleInputName2">Name</label>
    <input type="text" class="form-control" id="exampleInputName2" placeholder="Jane Doe">
  </div>
  <div class="form-group">
    <label class="mr-1" for="exampleInputEmail2">Email</label>
    <input type="email" class="form-control mr-1" id="exampleInputEmail2" placeholder="jane.doe@example.com">
  </div>
  <button type="submit" class="btn btn-light">Send invitation</button>
</form>
<form class="form-inline">
  <div class="form-group mr-2 ">
    <label class="sr-only" for="exampleInputEmail3">Email address</label>
    <input type="email" class="form-control" id="exampleInputEmail3" placeholder="Email">
  </div>
  <div class="form-group mr-2">
    <label class="sr-only" for="exampleInputPassword3">Password</label>
    <input type="password" class="form-control" id="exampleInputPassword3" placeholder="Password">
  </div>
  <div class="hm-checkbox hm-checkbox-inline mr-2">
    <input id="hm-rememberme" type="checkbox">
    <label for="hm-rememberme">Remember me</label>
  </div>
  <button type="submit" class="btn btn-light">Sign in</button>
</form>
$
.00
<form class="form-inline">
  <div class="form-group mr-2">
    <label class="sr-only" for="exampleInputAmount">Amount (in dollars)</label>
    <div class="input-group">
      <div class="input-group-prepend">
        <span class="input-group-text">$</span>
      </div>
      <input type="text" class="form-control" id="exampleInputAmount" placeholder="Amount">
      <div class="input-group-append">
        <span class="input-group-text">.00</span>
      </div>
    </div>
  </div>
  <button type="submit" class="btn btn-primary">Transfer cash</button>
</form>

Horizontal form

Use Bootstrap’s predefined grid classes to align labels and groups of form controls in a horizontal layout by adding .form-horizontal to the form (which doesn’t have to be a <form>). Doing so changes .form-groups to behave as grid rows, so no need for .row.

<form>
  <div class="form-group row">
    <label for="inputEmail3" class="col-sm-2 col-form-label">Email</label>
    <div class="col-sm-10">
      <input type="email" class="form-control" id="inputEmail3" placeholder="Email">
    </div>
  </div>
  <div class="form-group row">
    <label for="inputPassword3" class="col-sm-2 col-form-label">Password</label>
    <div class="col-sm-10">
      <input type="password" class="form-control" id="inputPassword3" placeholder="Password">
    </div>
  </div>
  <div class="form-group row">
    <div class="offset-sm-2 col-sm-10">
      <div class="form-check hm-checkbox">
        <input class="form-check-input" id="hm-horizontal" type="checkbox">
        <label class="form-check-label" for="hm-horizontal">Check me out</label>
      </div>
    </div>
  </div>
  <div class="form-group row">
    <div class="offset-sm-2 col-sm-10">
      <button type="submit" class="btn btn-light">Sign in</button>
    </div>
  </div>
</form>

Supported controls

Examples of standard form controls supported in an example form layout.

Inputs

Most common form control, text-based input fields. Includes support for all HTML5 types: text, password, datetime, datetime-local, date, month, time, week, number, email, url, search, tel, and color.

Type declaration required

Inputs will only be fully styled if their type is properly declared.

<input class="form-control" placeholder="No type input">
<input type="text" class="form-control" placeholder="Text input">
<input type="password" class="form-control" placeholder="Password input">
<input type="date" class="form-control" placeholder="2017-11-27">

Input groups

To add integrated text or buttons before and/or after any text-based <input>, check out the input group component.

Textarea

Form control which supports multiple lines of text. Change rows attribute as necessary.

<form>
  <textarea class="form-control" rows="3" placeholder="Textarea"></textarea>
</form>

Checkboxes and radios

Checkboxes are for selecting one or several options in a list, while radios are for selecting one option from many.

Disabled checkboxes and radios are supported, but to provide a “not-allowed” cursor on hover of the parent <label>, you’ll need to add the .disabled class to the parent .hm-radio, .hm-radio-inline, .hm-checkbox, or .hm-checkbox-inline.

Hitman checkboxes and radio buttons

Hitman checkboxes and radio buttons use their own html markup.

<form>
  <div class="hm-checkbox">
    <input id="hm-1" type="checkbox" checked>
    <label for="hm-1">Option one is this and that&mdash;be sure to include why it's great</label>
  </div>
  <div class="hm-checkbox disabled">
    <input id="hm-2" type="checkbox" disabled>
    <label for="hm-2">Option two is disabled</label>
  </div>

  <div class="hm-radio">
    <input id="hm-3" type="radio" name="hm-g" checked>
    <label for="hm-3">Option one is this and that&mdash;be sure to include why it's great</label>
  </div>
  <div class="hm-radio">
    <input id="hm-4" type="radio" name="hm-g">
    <label for="hm-4">Option two is also quite good</label>
  </div>
  <div class="hm-radio disabled">
    <input id="hm-5" type="radio" name="hm-g" disabled>
    <label for="hm-5">Option three is disabled</label>
  </div>
</form>

Inline checkboxes and radios

Use the .hm-checkbox-inline or .hm-radio-inline classes on a series of checkboxes or radios for controls that appear on the same line.

<form>
  <div class="hm-checkbox hm-checkbox-inline">
    <input id="hmi-1" type="checkbox" checked>
    <label for="hmi-1">1</label>
  </div>
  <div class="hm-checkbox hm-checkbox-inline">
    <input id="hmi-2" type="checkbox">
    <label for="hmi-2">2</label>
  </div>
    <div class="hm-checkbox hm-checkbox-inline">
    <input id="hmi-3" type="checkbox">
    <label for="hmi-3">3</label>
  </div>
</form>

<form>
  <div class="hm-radio hm-radio-inline">
    <input id="hmi-4" type="radio" name="hmi-g2" checked>
    <label for="hmi-4">1</label>
  </div>
  <div class="hm-radio hm-radio-inline">
    <input id="hmi-5" type="radio" name="hmi-g2">
    <label for="hmi-5">2</label>
  </div>
  <div class="hm-radio hm-radio-inline">
    <input id="hmi-6" type="radio" name="hmi-g2">
    <label for="hmi-6">3</label>
  </div>
</form>

Checkboxes and radios without label text

Should you have no text within the <label>, the input is positioned as you’d expect. Currently only works on non-inline checkboxes and radios. Remember to still provide some form of label for assistive technologies (for instance, using aria-label).

<form>
  <div class="hm-checkbox">
    <input id="hmb-1" type="checkbox">
    <label for="hmb-1"></label>
  </div>
  <div class="hm-radio">
    <input id="hmb-2" type="radio">
    <label for="hmb-2"></label>
  </div>
</form>

Selects

Please note that Hitman selects use the .hm-select as wrapper.

<form>
  <div class="hm-select">
    <select class="form-control">
      <option>1</option>
      <option>2</option>
      <option>3</option>
      <option>4</option>
      <option>5</option>
    </select>
  </div>
</form>

For <select> controls with the multiple attribute, multiple options are shown by default.

<form>
  <select class="custom-select" multiple>
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    <option>5</option>
  </select>
</form>

Static control

When you need to place plain text next to a form label within a form, use the .form-control-static class on a <p>.

<form>
  <div class="form-group row">
    <label for="staticEmail" class="col-sm-2 col-form-label">Email</label>
    <div class="col-sm-10">
      <input type="text" readonly class="form-control-plaintext" id="staticEmail" value="email@example.com">
    </div>
  </div>
  <div class="form-group row">
    <label for="inputPassword" class="col-sm-2 col-form-label">Password</label>
    <div class="col-sm-10">
      <input type="password" class="form-control" id="inputPassword" placeholder="Password">
    </div>
  </div>
</form>
<form class="form-inline">
  <div class="form-group">
    <label for="staticEmail2" class="sr-only">Email</label>
    <input type="text" readonly class="form-control-plaintext" id="staticEmail2" value="email@example.com">
  </div>
  <div class="form-group mx-sm-3">
    <label for="inputPassword2" class="sr-only">Password</label>
    <input type="password" class="form-control" id="inputPassword2" placeholder="Password">
  </div>
  <button type="submit" class="btn btn-light">Confirm identity</button>
</form>

Focus state

We remove the default outline styles on some form controls and apply a box-shadow in its place for :focus.

<input class="form-control" id="focusedInput" type="text" value="Demonstrative focus state">

Disabled state

Add the disabled boolean attribute on an input to prevent user interactions. Disabled inputs appear lighter and add a not-allowed cursor.

<input class="form-control" id="disabledInput" type="text" placeholder="Disabled input here…" disabled>

Disabled fieldsets

Add the disabled attribute to a <fieldset> to disable all the controls within the <fieldset> at once.

Caveat about link functionality of <a>

By default, browsers will treat all native form controls (<input>, <select> and <button> elements) inside a <fieldset disabled> as disabled, preventing both keyboard and mouse interactions on them. However, if your form also includes <a ... class="btn btn-*"> elements, these will only be given a style of pointer-events: none. As noted in the section about disabled state for buttons (and specifically in the sub-section for anchor elements), this CSS property is not yet standardized and isn't fully supported in Opera 18 and below, or in Internet Explorer 11, and won't prevent keyboard users from being able to focus or activate these links. So to be safe, use custom JavaScript to disable such links.

Cross-browser compatibility

While Bootstrap will apply these styles in all browsers, Internet Explorer 11 and below don't fully support the disabled attribute on a <fieldset>. Use custom JavaScript to disable the fieldset in these browsers.

<fieldset disabled>
  <div class="form-group">
    <label for="disabledTextInput">Disabled input</label>
    <input type="text" id="disabledTextInput" class="form-control" placeholder="Disabled input">
  </div>
  <div class="form-group">
    <label for="disabledSelect">Disabled select menu</label>
      <select class="form-control">
        <option value="">Disabled select</option>
      </select>
  </div>
  <div class="form-check hm-checkbox">
    <input class="form-check-input" id="hm-cantcheck" type="checkbox">
    <label class="form-check-label" for="hm-cantcheck">Cant't check this</label>
  </div>
  <button type="submit" class="btn btn-primary">Submit</button>
</fieldset>

Readonly state

Add the readonly boolean attribute on an input to prevent modification of the input’s value. Read-only inputs appear lighter (just like disabled inputs), but retain the standard cursor.

<input class="form-control" type="text" placeholder="Readonly input here…" readonly>

Help text

Block level help text for form controls.

Associating help text with form controls

Help text should be explicitly associated with the form control it relates to using the aria-describedby attribute. This will ensure that assistive technologies – such as screen readers – will announce this help text when the user focuses or enters the control.

A block of help text that breaks onto a new line and may extend beyond one line.
<form>
  <div class="form-group">
    <label for="inputHelpBlock">Input with help text</label>
    <input type="text" id="inputHelpBlock" class="form-control" aria-describedby="helpBlock">
    <small id="helpBlock" class="form-text text-muted">A block of help text that breaks onto a new line and may extend beyond one line.</small>
  </div>
</form>

Validation states

Bootstrap includes validation styles for error, warning, and success states on form controls. To use, add .has-warning, .has-error, or .has-success to the parent element. Any .control-label, .form-control, and .help-block within that element will receive the validation styles.

Conveying validation state to assistive technologies and colorblind users

Using these validation styles to denote the state of a form control only provides a visual, color-based indication, which will not be conveyed to users of assistive technologies - such as screen readers - or to colorblind users.

Ensure that an alternative indication of state is also provided. For instance, you can include a hint about state in the form control's <label> text itself (as is the case in the following code example) or (with appropriate alternative text using the .sr-onlyor by providing an additional help text block. Specifically for assistive technologies, invalid form controls can also be assigned an aria-invalid="true" attribute.

A block of help text that breaks onto a new line and may extend beyond one line.
<form>
  <div class="form-group">
    <label for="inputSuccess1">Input with success</label>
    <input type="text" class="form-control is-valid" id="inputSuccess1" aria-describedby="helpBlock2">
    <small id="helpBlock2" class="help-block">A block of help text that breaks onto a new line and may extend beyond one line.</small>
  </div>
  <div class="form-group">
    <label for="inputSuccess2">Input with success</label>
    <input type="text" class="form-control is-valid" id="inputSuccess2">
  </div>
  <div class="form-group">
    <label for="inputError1">Input with error</label>
    <input type="text" class="form-control is-invalid" id="inputError1">
  </div>
  <div class="form-group">
    <div class="form-check hm-checkbox">
      <input class="form-check-input is-valid" id="hm-success" type="checkbox">
      <label class="form-check-label" for="hm-success">Checkbox with success</label>
    </div>
  </div>
    <div class="form-group">
    <div class="form-check hm-checkbox">
      <input class="form-check-input is-invalid" id="hm-error" type="checkbox">
      <label class="form-check-label" for="hm-error">Checkbox with error</label>
    </div>
  </div>
</form>

With optional icons

You can also add optional feedback icons with the addition of .has-feedback and the right icon.

Feedback icons only work with textual <input class="form-control"> elements.

Icons, labels, and input groups

Manual positioning of feedback icons is required for inputs without a label and for input groups with an add-on on the right. You are strongly encouraged to provide labels for all inputs for accessibility reasons. If you wish to prevent labels from being displayed, hide them with the .sr-only class. If you must do without labels, adjust the top value of the feedback icon. For input groups, adjust the right value to an appropriate pixel value depending on the width of your addon.

Conveying the icon's meaning to assistive technologies

To ensure that assistive technologies – such as screen readers – correctly convey the meaning of an icon, additional hidden text should be included with the .sr-only class and explicitly associated with the form control it relates to using aria-describedby. Alternatively, ensure that the meaning (for instance, the fact that there is a warning for a particular text entry field) is conveyed in some other form, such as changing the text of the actual <label> associated with the form control.

Although the following examples already mention the validation state of their respective form controls in the <label> text itself, the above technique (using .sr-only text and aria-describedby) has been included for illustrative purposes.

Looks good!
Please choose a username.
@
Looks good!
<form>
  <div class="form-group">
    <label for="inputSuccess3">Input with success</label>
    <input type="text" class="form-control is-valid" id="inputSuccess3">
    <div class="valid-feedback">
        Looks good!
    </div>
  </div>
  <div class="form-group">
    <label for="inputError2">Input with error</label>
    <input type="text" class="form-control is-invalid" id="inputError2">
    <div class="invalid-feedback">
          Please choose a username.
    </div>
  </div>
  <div class="form-group">
    <label for="inputGroupSuccess1">Input group with success</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-valid" id="inputGroupSuccess1" aria-describedby="inputGroupPrepend3">
      <div class="valid-feedback">
        Looks good!
      </div>
    </div>
  </div>
</form>

Optional icons in horizontal and inline forms

Looks good!
@
Looks good!
<form>
  <div class="form-group row">
    <label class="col-form-label col-sm-3" for="inputSuccess3">Input with success</label>
    <div class="col-sm-9">
      <input type="text" class="form-control is-valid" id="inputSuccess3">
      <div class="valid-feedback">
        Looks good!
      </div>
    </div>
  </div>
  <div class="form-group row">
    <label class="col-form-label col-sm-3" for="inputGroupSuccess2">Input group with success</label>
    <div class="col-sm-9">
      <div class="input-group">
        <div class="input-group-prepend">
          <span class="input-group-text" id="inputGroupPrepend4">@</span>
        </div>
        <input type="text" class="form-control is-valid" id="inputGroupSuccess2" aria-describedby="inputGroupPrepend4">
        <div class="valid-feedback">
          Looks good!
        </div>
      </div>
    </div>
  </div>
</form>
@
<form class="form-inline">
  <div class="form-group mr-2">
    <label class="mr-1" for="inputSuccess4">Input with success</label>
    <input type="text" class="form-control is-valid" id="inputSuccess4">
  </div>
  <div class="form-group">
    <label class="mr-1" for="inputGroupSuccess3">Input group with success</label>
    <div class="input-group">
      <div class="input-group-prepend">
        <span class="input-group-text" id="inputGroupPrepend5">@</span>
      </div>
      <input type="text" class="form-control is-valid" id="inputGroupSuccess3" aria-describedby="inputGroupPrepend5">
    </div>
  </div>
</form>

Optional icons with hidden .sr-only labels

If you use the .sr-only class to hide a form control’s <label> (rather than using other labelling options, such as the aria-label attribute), Bootstrap will automatically adjust the position of the icon once it’s been added.

Looks good!
@
Looks good!
<div class="form-group">
  <label class="sr-only" for="inputSuccess5">Hidden label</label>
  <input type="text" class="form-control is-valid" id="inputSuccess5">
  <div class="valid-feedback">
    Looks good!
  </div>
</div>
<div class="form-group">
  <label class= "sr-only" for="inputGroupSuccess4">Input group with success</label>
  <div class="input-group">
    <div class="input-group-prepend">
      <span class="input-group-text" id="inputGroupPrepend6">@</span>
    </div>
    <input type="text" class="form-control is-valid" id="inputGroupSuccess4" aria-describedby="inputGroupPrepend6">
    <div class="valid-feedback">
      Looks good!
    </div>
  </div>
</div>

Control sizing

Set heights using classes like .input-lg, and set widths using grid column classes like .col-lg-*.

Height sizing

Create taller or shorter form controls that match button sizes.

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

<div class="hm-select">
  <select class="form-control form-control-lg">
    <option value="">.input-lg</option>
  </select>
</div>
<div class="hm-select">
  <select class="form-control">
    <option value="">Default input</option>
  </select>
</div>
<div class="hm-select">
  <select class="form-control form-control-sm">
    <option value="">.input-sm</option>
  </select>
</div>

Column sizing

Wrap inputs in grid columns, or any custom parent element, to easily enforce desired widths.

<div class="form-row">
  <div class="col-2">
    <input type="text" class="form-control" placeholder=".col-2">
  </div>
  <div class="col-3">
    <input type="text" class="form-control" placeholder=".col-3">
  </div>
  <div class="col-4">
    <input type="text" class="form-control" placeholder=".col-4">
  </div>
</div>