4 description: Examples and usage guidelines for form controls, form layouts, and custom forms.
8 Bootstrap provides several form control styles, layout options, and custom components for creating a wide variety of forms.
12 * Will be replaced with the ToC, excluding the "Contents" header
17 Bootstrap's form controls expand on [our Rebooted form styles]({{ site.baseurl }}/content/reboot/#forms) with classes. Use these classes to opt into their customized displays for a more consistent rendering across browsers and devices. The example form below demonstrates common HTML form elements that receive updated styles from Bootstrap with additional classes.
19 Remember, since Bootstrap utilizes the HTML5 doctype, **all inputs must have a `type` attribute**.
23 <div class="form-group">
24 <label for="exampleInputEmail1">Email address</label>
25 <input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
26 <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
28 <div class="form-group">
29 <label for="exampleInputPassword1">Password</label>
30 <input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password">
32 <div class="form-group">
33 <label for="exampleSelect1">Example select</label>
34 <select class="form-control" id="exampleSelect1">
42 <div class="form-group">
43 <label for="exampleSelect2">Example multiple select</label>
44 <select multiple class="form-control" id="exampleSelect2">
52 <div class="form-group">
53 <label for="exampleTextarea">Example textarea</label>
54 <textarea class="form-control" id="exampleTextarea" rows="3"></textarea>
56 <div class="form-group">
57 <label for="exampleInputFile">File input</label>
58 <input type="file" class="form-control-file" id="exampleInputFile" aria-describedby="fileHelp">
59 <small id="fileHelp" class="form-text text-muted">This is some placeholder block-level help text for the above input. It's a bit lighter and easily wraps to a new line.</small>
61 <fieldset class="form-group">
62 <legend>Radio buttons</legend>
63 <div class="form-check">
64 <label class="form-check-label">
65 <input type="radio" class="form-check-input" name="optionsRadios" id="optionsRadios1" value="option1" checked>
66 Option one is this and that—be sure to include why it's great
69 <div class="form-check">
70 <label class="form-check-label">
71 <input type="radio" class="form-check-input" name="optionsRadios" id="optionsRadios2" value="option2">
72 Option two can be something else and selecting it will deselect option one
75 <div class="form-check disabled">
76 <label class="form-check-label">
77 <input type="radio" class="form-check-input" name="optionsRadios" id="optionsRadios3" value="option3" disabled>
78 Option three is disabled
82 <div class="form-check">
83 <label class="form-check-label">
84 <input type="checkbox" class="form-check-input">
88 <button type="submit" class="btn btn-primary">Submit</button>
92 Below is a complete list of the specific form controls supported by Bootstrap and the classes that customize them. Additional documentation is available for each group.
99 <th>Supported variations</th>
105 {% markdown %}`.form-group`{% endmarkdown %}
107 <td class="text-nowrap">
108 Any group of form controls
111 {% markdown %}Use with any block-level element like `<fieldset>` or `<div>`{% endmarkdown %}
116 {% markdown %}`.form-control`{% endmarkdown %}
122 {% markdown %}`text`, `password`, `datetime-local`, `date`, `month`, `time`, `week`, `number`, `email`, `url`, `search`, `tel`, `color`{% endmarkdown %}
130 {% markdown %}`multiple`, `size`{% endmarkdown %}
138 <span class="text-muted">N/A</span>
142 <td class="text-nowrap">
143 {% markdown %}`.form-control-file`{% endmarkdown %}
149 {% markdown %}`file`{% endmarkdown %}
153 <td class="text-nowrap">
158 <td class="text-nowrap">
159 Checkboxes and radios
162 <span class="text-muted">N/A</span>
170 Here are examples of `.form-control` applied to each textual HTML5 `<input>` `type`.
173 <div class="form-group row">
174 <label for="example-text-input" class="col-2 col-form-label">Text</label>
176 <input class="form-control" type="text" value="Artisanal kale" id="example-text-input">
179 <div class="form-group row">
180 <label for="example-search-input" class="col-2 col-form-label">Search</label>
182 <input class="form-control" type="search" value="How do I shoot web" id="example-search-input">
185 <div class="form-group row">
186 <label for="example-email-input" class="col-2 col-form-label">Email</label>
188 <input class="form-control" type="email" value="bootstrap@example.com" id="example-email-input">
191 <div class="form-group row">
192 <label for="example-url-input" class="col-2 col-form-label">URL</label>
194 <input class="form-control" type="url" value="https://getbootstrap.com" id="example-url-input">
197 <div class="form-group row">
198 <label for="example-tel-input" class="col-2 col-form-label">Telephone</label>
200 <input class="form-control" type="tel" value="1-(555)-555-5555" id="example-tel-input">
203 <div class="form-group row">
204 <label for="example-password-input" class="col-2 col-form-label">Password</label>
206 <input class="form-control" type="password" value="hunter2" id="example-password-input">
209 <div class="form-group row">
210 <label for="example-number-input" class="col-2 col-form-label">Number</label>
212 <input class="form-control" type="number" value="42" id="example-number-input">
215 <div class="form-group row">
216 <label for="example-datetime-local-input" class="col-2 col-form-label">Date and time</label>
218 <input class="form-control" type="datetime-local" value="2011-08-19T13:45:00" id="example-datetime-local-input">
221 <div class="form-group row">
222 <label for="example-date-input" class="col-2 col-form-label">Date</label>
224 <input class="form-control" type="date" value="2011-08-19" id="example-date-input">
227 <div class="form-group row">
228 <label for="example-month-input" class="col-2 col-form-label">Month</label>
230 <input class="form-control" type="month" value="2011-08" id="example-month-input">
233 <div class="form-group row">
234 <label for="example-week-input" class="col-2 col-form-label">Week</label>
236 <input class="form-control" type="week" value="2011-W33" id="example-week-input">
239 <div class="form-group row">
240 <label for="example-time-input" class="col-2 col-form-label">Time</label>
242 <input class="form-control" type="time" value="13:45:00" id="example-time-input">
245 <div class="form-group row">
246 <label for="example-color-input" class="col-2 col-form-label">Color</label>
248 <input class="form-control" type="color" value="#563d7c" id="example-color-input">
255 Since Bootstrap applies `display: block` and `width: 100%` to almost all our form controls, forms will by default stack vertically. Additional classes can be used to vary this layout on a per-form basis.
259 The `.form-group` class is the easiest way to add some structure to forms. Its only purpose is to provide `margin-bottom` around a label and control pairing. As a bonus, since it's a class you can use it with `<fieldset>`s, `<div>`s, or nearly any other element.
263 <div class="form-group">
264 <label for="formGroupExampleInput">Example label</label>
265 <input type="text" class="form-control" id="formGroupExampleInput" placeholder="Example input">
267 <div class="form-group">
268 <label for="formGroupExampleInput2">Another label</label>
269 <input type="text" class="form-control" id="formGroupExampleInput2" placeholder="Another input">
276 Use the `.form-inline` class to display a series of labels, form controls, and buttons on a single horizontal row. Form controls within inline forms vary slightly from their default states.
278 - Controls are `display: flex`, collapsing any HTML white space and allowing you to provide alignment control with [spacing]({{ site.baseurl }}/utilities/spacing/) and [flexbox]({{ site.baseurl }}/utilities/flexbox/) utilities.
279 - Controls and input groups receive `width: auto` to override the Bootstrap default `width: 100%`.
280 - Controls **only appear inline in viewports that are at least 576px wide** to account for narrow viewports on mobile devices.
282 You may need to manually address the width and alignment of individual form controls with [spacing utilities]({{ site.baseurl }}/utilities/spacing/) (as shown below). Lastly, be sure to always include a `<label>` with each form control, even if you need to hide it from non-screenreader visitors with `.sr-only`.
285 <form class="form-inline">
286 <label class="sr-only" for="inlineFormInput">Name</label>
287 <input type="text" class="form-control mb-2 mr-sm-2 mb-sm-0" id="inlineFormInput" placeholder="Jane Doe">
289 <label class="sr-only" for="inlineFormInputGroup">Username</label>
290 <div class="input-group mb-2 mr-sm-2 mb-sm-0">
291 <div class="input-group-addon">@</div>
292 <input type="text" class="form-control" id="inlineFormInputGroup" placeholder="Username">
295 <div class="form-check mb-2 mr-sm-2 mb-sm-0">
296 <label class="form-check-label">
297 <input class="form-check-input" type="checkbox"> Remember me
301 <button type="submit" class="btn btn-primary">Submit</button>
305 Custom form controls and selects are also supported.
308 <form class="form-inline">
309 <label class="mr-sm-2" for="inlineFormCustomSelect">Preference</label>
310 <select class="custom-select mb-2 mr-sm-2 mb-sm-0" id="inlineFormCustomSelect">
311 <option selected>Choose...</option>
312 <option value="1">One</option>
313 <option value="2">Two</option>
314 <option value="3">Three</option>
317 <label class="custom-control custom-checkbox mb-2 mr-sm-2 mb-sm-0">
318 <input type="checkbox" class="custom-control-input">
319 <span class="custom-control-indicator"></span>
320 <span class="custom-control-description">Remember my preference</span>
323 <button type="submit" class="btn btn-primary">Submit</button>
327 {% callout warning %}
328 #### Alternatives to hidden labels
329 Assistive technologies such as 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 are present, assistive technologies 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.
334 For more structured form layouts that are also responsive, you can utilize Bootstrap's [predefined grid classes]({{ site.baseurl }}/layout/grid/) or [mixins]({{ site.baseurl }}/layout/grid/#sass-mixins) to create horizontal forms. Add the `.row` class to form groups and use the `.col-*-*` classes to specify the width of your labels and controls.
336 Be sure to add `.col-form-label` to your `<label>`s as well so they're vertically centered with their associated form controls. For `<legend>` elements, you can use `.col-form-legend` to make them appear similar to regular `<label>` elements.
339 <div class="container">
341 <div class="form-group row">
342 <label for="inputEmail3" class="col-sm-2 col-form-label">Email</label>
343 <div class="col-sm-10">
344 <input type="email" class="form-control" id="inputEmail3" placeholder="Email">
347 <div class="form-group row">
348 <label for="inputPassword3" class="col-sm-2 col-form-label">Password</label>
349 <div class="col-sm-10">
350 <input type="password" class="form-control" id="inputPassword3" placeholder="Password">
353 <fieldset class="form-group row">
354 <legend class="col-form-legend col-sm-2">Radios</legend>
355 <div class="col-sm-10">
356 <div class="form-check">
357 <label class="form-check-label">
358 <input class="form-check-input" type="radio" name="gridRadios" id="gridRadios1" value="option1" checked>
359 Option one is this and that—be sure to include why it's great
362 <div class="form-check">
363 <label class="form-check-label">
364 <input class="form-check-input" type="radio" name="gridRadios" id="gridRadios2" value="option2">
365 Option two can be something else and selecting it will deselect option one
368 <div class="form-check disabled">
369 <label class="form-check-label">
370 <input class="form-check-input" type="radio" name="gridRadios" id="gridRadios3" value="option3" disabled>
371 Option three is disabled
376 <div class="form-group row">
377 <label class="col-sm-2">Checkbox</label>
378 <div class="col-sm-10">
379 <div class="form-check">
380 <label class="form-check-label">
381 <input class="form-check-input" type="checkbox"> Check me out
386 <div class="form-group row">
387 <div class="offset-sm-2 col-sm-10">
388 <button type="submit" class="btn btn-primary">Sign in</button>
395 Grid-based form layouts also support large and small inputs.
398 <div class="container">
400 <div class="form-group row">
401 <label for="lgFormGroupInput" class="col-sm-2 col-form-label col-form-label-lg">Email</label>
402 <div class="col-sm-10">
403 <input type="email" class="form-control form-control-lg" id="lgFormGroupInput" placeholder="you@example.com">
406 <div class="form-group row">
407 <label for="smFormGroupInput" class="col-sm-2 col-form-label col-form-label-sm">Email</label>
408 <div class="col-sm-10">
409 <input type="email" class="form-control form-control-sm" id="smFormGroupInput" placeholder="you@example.com">
417 ## Checkboxes and radios
419 Default checkboxes and radios are improved upon with the help of `.form-check`, **a single class for both input types that improves the layout and behavior of their HTML elements**. Checkboxes are for selecting one or several options in a list, while radios are for selecting one option from many.
421 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 `.form-check`. The disabled class will also lighten the text color to help indicate the input's state.
423 ### Default (stacked)
425 By default, any number of checkboxes and radios that are immediate sibling will be vertically stacked and appropriately spaced with `.form-check`.
428 <div class="form-check">
429 <label class="form-check-label">
430 <input class="form-check-input" type="checkbox" value="">
431 Option one is this and that—be sure to include why it's great
434 <div class="form-check disabled">
435 <label class="form-check-label">
436 <input class="form-check-input" type="checkbox" value="" disabled>
437 Option two is disabled
443 <div class="form-check">
444 <label class="form-check-label">
445 <input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios1" value="option1" checked>
446 Option one is this and that—be sure to include why it's great
449 <div class="form-check">
450 <label class="form-check-label">
451 <input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios2" value="option2">
452 Option two can be something else and selecting it will deselect option one
455 <div class="form-check disabled">
456 <label class="form-check-label">
457 <input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios3" value="option3" disabled>
458 Option three is disabled
465 Group checkboxes or radios on the same horizontal row by adding `.form-check-inline` to any `.form-check`.
468 <div class="form-check form-check-inline">
469 <label class="form-check-label">
470 <input class="form-check-input" type="checkbox" id="inlineCheckbox1" value="option1"> 1
473 <div class="form-check form-check-inline">
474 <label class="form-check-label">
475 <input class="form-check-input" type="checkbox" id="inlineCheckbox2" value="option2"> 2
478 <div class="form-check form-check-inline disabled">
479 <label class="form-check-label">
480 <input class="form-check-input" type="checkbox" id="inlineCheckbox3" value="option3" disabled> 3
486 <div class="form-check form-check-inline">
487 <label class="form-check-label">
488 <input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineRadio1" value="option1"> 1
491 <div class="form-check form-check-inline">
492 <label class="form-check-label">
493 <input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineRadio2" value="option2"> 2
496 <div class="form-check form-check-inline disabled">
497 <label class="form-check-label">
498 <input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineRadio3" value="option3" disabled> 3
505 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`).
508 <div class="form-check">
509 <label class="form-check-label">
510 <input class="form-check-input" type="checkbox" id="blankCheckbox" value="option1" aria-label="...">
513 <div class="form-check">
514 <label class="form-check-label">
515 <input class="form-check-input" type="radio" name="blankRadio" id="blankRadio1" value="option1" aria-label="...">
522 When you need to place plain text next to a form label within a form, use the `.form-control-static` class on an element of your choice.
526 <div class="form-group row">
527 <label class="col-sm-2 col-form-label">Email</label>
528 <div class="col-sm-10">
529 <p class="form-control-static">email@example.com</p>
532 <div class="form-group row">
533 <label for="inputPassword" class="col-sm-2 col-form-label">Password</label>
534 <div class="col-sm-10">
535 <input type="password" class="form-control" id="inputPassword" placeholder="Password">
542 <form class="form-inline">
543 <div class="form-group">
544 <label class="sr-only">Email</label>
545 <p class="form-control-static">email@example.com</p>
547 <div class="form-group mx-sm-3">
548 <label for="inputPassword2" class="sr-only">Password</label>
549 <input type="password" class="form-control" id="inputPassword2" placeholder="Password">
551 <button type="submit" class="btn btn-primary">Confirm identity</button>
557 Add the `disabled` boolean attribute on an input to prevent user interactions. Disabled inputs appear lighter and add a `not-allowed` cursor.
560 <input class="form-control" id="disabledInput" type="text" placeholder="Disabled input here..." disabled>
563 Add the `disabled` attribute to a `<fieldset>` to disable all the controls within.
568 <div class="form-group">
569 <label for="disabledTextInput">Disabled input</label>
570 <input type="text" id="disabledTextInput" class="form-control" placeholder="Disabled input">
572 <div class="form-group">
573 <label for="disabledSelect">Disabled select menu</label>
574 <select id="disabledSelect" class="form-control">
575 <option>Disabled select</option>
578 <div class="checkbox">
580 <input type="checkbox"> Can't check this
583 <button type="submit" class="btn btn-primary">Submit</button>
588 {% callout warning %}
589 #### Caveat about link functionality of `<a>`
591 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]({{ site.baseurl }}/components/buttons/#disabled-state) (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.
595 #### Cross-browser compatibility
597 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.
602 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.
605 <input class="form-control" type="text" placeholder="Readonly input here…" readonly>
610 Set heights using classes like `.form-control-lg`, and set widths using grid column classes like `.col-lg-*`.
613 <input class="form-control form-control-lg" type="text" placeholder=".form-control-lg">
614 <input class="form-control" type="text" placeholder="Default input">
615 <input class="form-control form-control-sm" type="text" placeholder=".form-control-sm">
619 <select class="form-control form-control-lg">
620 <option>Large select</option>
622 <select class="form-control">
623 <option>Default select</option>
625 <select class="form-control form-control-sm">
626 <option>Small select</option>
632 Wrap inputs in grid columns, or any custom parent element, to easily enforce desired widths.
637 <input type="text" class="form-control" placeholder=".col-2">
640 <input type="text" class="form-control" placeholder=".col-3">
643 <input type="text" class="form-control" placeholder=".col-4">
650 Block-level help text in forms can be created using `.form-text` (previously known as `.help-block` in v3). Inline help text can be flexibly implemented using any inline HTML element and utility classes like `.text-muted`.
652 {% callout warning %}
653 #### Associating help text with form controls
655 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.
660 Block help text—for below inputs or for longer lines of help text—can be easily achieved with `.form-text`. This class includes `display: block` and adds some top margin for easy spacing from the inputs above.
663 <label for="inputPassword5">Password</label>
664 <input type="password" id="inputPassword5" class="form-control" aria-describedby="passwordHelpBlock">
665 <p id="passwordHelpBlock" class="form-text text-muted">
666 Your password must be 8-20 characters long, contain letters and numbers, and must not contain spaces, special characters, or emoji.
672 Inline text can use any typical inline HTML element (be it a `<small>`, `<span>`, or something else).
675 <form class="form-inline">
676 <div class="form-group">
677 <label for="inputPassword4">Password</label>
678 <input type="password" id="inputPassword4" class="form-control mx-sm-3" aria-describedby="passwordHelpInline">
679 <small id="passwordHelpInline" class="text-muted">
680 Must be 8-20 characters long.
688 Bootstrap includes validation styles for danger, warning, and success states on most form controls.
692 Here's a rundown of how they work:
694 - To use, add `.has-warning`, `.has-danger`, or `.has-success` to the parent element. Any `.col-form-label`, `.form-control`, or custom form element will receive the validation styles.
695 - Contextual validation text, in addition to your usual form field help text, can be added with the use of `.form-control-feedback`. This text will adapt to the parent `.has-*` class. By default it only includes a bit of `margin` for spacing and a modified `color` for each state.
696 - Validation icons are `url()`s configured via Sass variables that are applied to `background-image` declarations for each state.
697 - You may use your own base64 PNGs or SVGs by updating the Sass variables and recompiling.
698 - Icons can also be disabled entirely by setting the variables to `none` or commenting out the source Sass.
702 Generally speaking, you'll want to use a particular state for specific types of feedback:
704 - **Danger** is great for when there's a blocking or required field. A user *must* fill in this field properly to submit the form.
705 - **Warning** works well for input values that are in progress, like password strength, or soft validation before a user attempts to submit a form.
706 - And lastly, **success** is ideal for situations when you have per-field validation throughout a form and want to encourage a user through the rest of the fields.
709 {% callout warning %}
710 #### Conveying validation state to assistive technologies and colorblind users
712 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.
714 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), include a [Glyphicon]({{ site.baseurl }}/components/#glyphicons) (with appropriate alternative text using the `.sr-only` class - see the [Glyphicon examples]({{ site.baseurl }}/components/#glyphicons-examples)), or by providing an additional [help text](#forms-help-text) block. Specifically for assistive technologies, invalid form controls can also be assigned an `aria-invalid="true"` attribute.
720 Here are some examples of the aforementioned classes in action. First up is your standard left-aligned fields with labels, help text, and validation messaging.
723 <div class="form-group has-success">
724 <label class="form-control-label" for="inputSuccess1">Input with success</label>
725 <input type="text" class="form-control form-control-success" id="inputSuccess1">
726 <div class="form-control-feedback">Success! You've done it.</div>
727 <small class="form-text text-muted">Example help text that remains unchanged.</small>
729 <div class="form-group has-warning">
730 <label class="form-control-label" for="inputWarning1">Input with warning</label>
731 <input type="text" class="form-control form-control-warning" id="inputWarning1">
732 <div class="form-control-feedback">Shucks, check the formatting of that and try again.</div>
733 <small class="form-text text-muted">Example help text that remains unchanged.</small>
735 <div class="form-group has-danger">
736 <label class="form-control-label" for="inputDanger1">Input with danger</label>
737 <input type="text" class="form-control form-control-danger" id="inputDanger1">
738 <div class="form-control-feedback">Sorry, that username's taken. Try another?</div>
739 <small class="form-text text-muted">Example help text that remains unchanged.</small>
743 Those same states can also be used with horizontal forms.
746 <div class="container">
748 <div class="form-group row has-success">
749 <label for="inputHorizontalSuccess" class="col-sm-2 col-form-label">Email</label>
750 <div class="col-sm-10">
751 <input type="email" class="form-control form-control-success" id="inputHorizontalSuccess" placeholder="name@example.com">
752 <div class="form-control-feedback">Success! You've done it.</div>
753 <small class="form-text text-muted">Example help text that remains unchanged.</small>
756 <div class="form-group row has-warning">
757 <label for="inputHorizontalWarning" class="col-sm-2 col-form-label">Email</label>
758 <div class="col-sm-10">
759 <input type="email" class="form-control form-control-warning" id="inputHorizontalWarning" placeholder="name@example.com">
760 <div class="form-control-feedback">Shucks, check the formatting of that and try again.</div>
761 <small class="form-text text-muted">Example help text that remains unchanged.</small>
764 <div class="form-group row has-danger">
765 <label for="inputHorizontalDnger" class="col-sm-2 col-form-label">Email</label>
766 <div class="col-sm-10">
767 <input type="email" class="form-control form-control-danger" id="inputHorizontalDnger" placeholder="name@example.com">
768 <div class="form-control-feedback">Sorry, that username's taken. Try another?</div>
769 <small class="form-text text-muted">Example help text that remains unchanged.</small>
776 Checkboxes and radios are also supported.
779 <div class="form-check has-success">
780 <label class="form-check-label">
781 <input type="checkbox" class="form-check-input" id="checkboxSuccess" value="option1">
782 Checkbox with success
785 <div class="form-check has-warning">
786 <label class="form-check-label">
787 <input type="checkbox" class="form-check-input" id="checkboxWarning" value="option1">
788 Checkbox with warning
791 <div class="form-check has-danger">
792 <label class="form-check-label">
793 <input type="checkbox" class="form-check-input" id="checkboxDanger" value="option1">
801 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.
803 ### Checkboxes and radios
805 Each checkbox and radio is wrapped in a `<label>` for three reasons:
807 - It provides a larger hit areas for checking the control.
808 - It provides a helpful and semantic wrapper to help us replace the default `<input>`s.
809 - It triggers the state of the `<input>` automatically, meaning no JavaScript is required.
811 We hide the default `<input>` with `opacity` and use the `.custom-control-indicator` to build a new custom form indicator in its place. Unfortunately we can't build a custom one from just the `<input>` because CSS's `content` doesn't work on that element.
813 We use the sibling selector (`~`) for all our `<input>` states—like `:checked`—to properly style our custom form indicator. When combined with the `.custom-control-description` class, we can also style the text for each item based on the `<input>`'s state.
815 In the checked states, we use **base64 embedded SVG icons** from [Open Iconic](https://useiconic.com/open). This provides us the best control for styling and positioning across browsers and devices.
820 <label class="custom-control custom-checkbox">
821 <input type="checkbox" class="custom-control-input">
822 <span class="custom-control-indicator"></span>
823 <span class="custom-control-description">Check this custom checkbox</span>
827 Custom checkboxes can also utilize the `:indeterminate` pseudo class when manually set via JavaScript (there is no available HTML attribute for specifying it).
829 <div class="bd-example bd-example-indeterminate">
830 <label class="custom-control custom-checkbox">
831 <input type="checkbox" class="custom-control-input">
832 <span class="custom-control-indicator"></span>
833 <span class="custom-control-description">Check this custom checkbox</span>
837 If you're using jQuery, something like this should suffice:
840 $('.your-checkbox').prop('indeterminate', true)
846 <label class="custom-control custom-radio">
847 <input id="radio1" name="radio" type="radio" class="custom-control-input">
848 <span class="custom-control-indicator"></span>
849 <span class="custom-control-description">Toggle this custom radio</span>
851 <label class="custom-control custom-radio">
852 <input id="radio2" name="radio" type="radio" class="custom-control-input">
853 <span class="custom-control-indicator"></span>
854 <span class="custom-control-description">Or toggle this other custom radio</span>
860 Custom checkboxes and radios can also be disabled. Add the `disabled` boolean attribute to the `<input>` and the custom indicator and label description will be automatically styled.
863 <label class="custom-control custom-checkbox">
864 <input type="checkbox" class="custom-control-input" disabled>
865 <span class="custom-control-indicator"></span>
866 <span class="custom-control-description">Check this custom checkbox</span>
869 <label class="custom-control custom-radio">
870 <input id="radio3" name="radioDisabled" type="radio" class="custom-control-input" disabled>
871 <span class="custom-control-indicator"></span>
872 <span class="custom-control-description">Toggle this custom radio</span>
876 #### Validation states
878 Add other states to your custom forms with our validation classes.
881 <div class="form-group has-success">
882 <label class="custom-control custom-checkbox">
883 <input type="checkbox" class="custom-control-input">
884 <span class="custom-control-indicator"></span>
885 <span class="custom-control-description">Check this custom checkbox</span>
888 <div class="form-group has-warning">
889 <label class="custom-control custom-checkbox">
890 <input type="checkbox" class="custom-control-input">
891 <span class="custom-control-indicator"></span>
892 <span class="custom-control-description">Check this custom checkbox</span>
895 <div class="form-group has-danger mb-0">
896 <label class="custom-control custom-checkbox">
897 <input type="checkbox" class="custom-control-input">
898 <span class="custom-control-indicator"></span>
899 <span class="custom-control-description">Check this custom checkbox</span>
906 Custom checkboxes and radios are inline to start. Add a parent with class `.custom-controls-stacked` to ensure each form control is on separate lines.
909 <div class="custom-controls-stacked">
910 <label class="custom-control custom-radio">
911 <input id="radioStacked1" name="radio-stacked" type="radio" class="custom-control-input">
912 <span class="custom-control-indicator"></span>
913 <span class="custom-control-description">Toggle this custom radio</span>
915 <label class="custom-control custom-radio">
916 <input id="radioStacked2" name="radio-stacked" type="radio" class="custom-control-input">
917 <span class="custom-control-indicator"></span>
918 <span class="custom-control-description">Or toggle this other custom radio</span>
925 Custom `<select>` menus need only a custom class, `.custom-select` to trigger the custom styles.
928 <select class="custom-select">
929 <option selected>Open this select menu</option>
930 <option value="1">One</option>
931 <option value="2">Two</option>
932 <option value="3">Three</option>
938 The file input is the most gnarly of the bunch and require additional JavaScript if you'd like to hook them up with functional *Choose file...* and selected file name text.
941 <label class="custom-file">
942 <input type="file" id="file" class="custom-file-input">
943 <span class="custom-file-control"></span>
949 - We wrap the `<input>` in a `<label>` so the custom control properly triggers the file browser.
950 - We hide the default file `<input>` via `opacity`.
951 - We use `:after` to generate a custom background and directive (*Choose file...*).
952 - We use `:before` to generate and position the *Browse* button.
953 - We declare a `height` on the `<input>` for proper spacing for surrounding content.
955 In other words, it's an entirely custom element, all generated via CSS.
957 #### Translating or customizing the strings
959 The [`:lang()` pseudo-class](https://developer.mozilla.org/en-US/docs/Web/CSS/:lang) is used to allow for easy translation of the "Browse" and "Choose file..." text into other languages. Simply override or add entries to the `$custom-file-text` SCSS variable with the relevant [language tag](https://en.wikipedia.org/wiki/IETF_language_tag) and localized strings. The English strings can be customized the same way. For example, here's how one might add a Spanish translation (Spanish's language code is `es`):
964 en: "Choose file...",
965 es: "Seleccionar archivo..."
974 You'll need to set the language of your document (or subtree thereof) correctly in order for the correct text to be shown. This can be done using [the `lang` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/lang) or the [`Content-Language` HTTP header](https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.12), among other methods.