Category: 4. Forms

https://cdn3d.iconscout.com/3d/premium/thumb/form-3d-icon-png-download-3927997.png

  • Validation

    This chapter will discuss about Bootstrap validation. Bootstrap 5 Validation enhances HTML5 form validation by offering useful feedback to users, supporting default browser behavior, custom styles, and JavaScript.

    The client-side custom validation styles and tooltips are inaccessible because they are not visible to assistive technology. It is recommended to use either the server-side option or the default browser validation technique, while we work on the solution.

    How form validation works in Bootstrap

    • The two pseudo-classes :invalid and :valid in CSS are used to provide HTML form validation. It applies to the <textarea><select>, and <input> elements.
    • Bootstrap applies the :invalid and :valid styles to the parent .was-validated class. Fields without a value show as invalid when the page loads. You choose when to activate them (usually after a form submission).
    • To restore the original appearance of the form after dynamic submissions using Ajax, the class .was-validated should be removed from the <form> to reset its appearance.
    • The pseudo-classes can be replaced with the .is-invalid and .is-valid classes for server-side validation as a fallback, without the need for a .was-validated parent class.
    • Currently, CSS limitations prevent us from directly applying styles to a <label> element that precedes a form control in the DOM without the help of custom JavaScript.
    • The constraint validation API, which consists of various JavaScript methods for validating form controls, is supported by all contemporary web browsers.
    • Use browser default styles or create custom feedback styles using HTML/CSS.
    • Use setCustomValidity method in JavaScript for unique validity messages.

    Let’s look at some examples of custom form validation styles, optional server-side classes and browser defaults.

    Custom styles

    • Add novalidate boolean attribute to the <form> to receive custom validation messages from Bootstrap.
    • Browser default feedback tooltips are disabled with above boolean attribute but JavaScript validation APIs still work. Submitting this form will trigger JavaScript to provide feedback, displaying :invalid and :valid styles on form controls.
    • Custom feedback styles improve feedback communication by adding colors, borders, focus styles, and backdrop icons. Backdrop icons for <select> are only available for .form-select, and not .form-control.

    This example demonstrates a Bootstrap form with validation features, to ensure that the required fields are filled out correctly before the form can be submitted.https://www.tutorialspoint.com/bootstrap/examples/custom_style.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Validation</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><form class="row g-3 needs-validation" novalidate><div class="col-md-4"><label for="validationCustomName" class="form-label">Full Name</label><input type="text" class="form-control" id="validationCustomName" value="Jhon Miller" required><div class="invalid-feedback">
    
           Correct input!
       &lt;/div&gt;&lt;/div&gt;&lt;div class="col-md-4"&gt;&lt;label for="validationCustomEmail" class="form-label"&gt;Email Id&lt;/label&gt;&lt;div class="input-group has-validation"&gt;&lt;input type="text" class="form-control" id="validationCustomEmail" aria-describedby="inputGroupPrepend" required&gt;&lt;span class="input-group-text" id="inputGroupPrepend"&gt;@tutorialspoint.com&lt;/span&gt;&lt;div class="invalid-feedback"&gt;
            Please enter correct mail id.
         &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="col-md-4"&gt;&lt;label for="validationCustomPhone" class="form-label"&gt;Mobile no&lt;/label&gt;&lt;input type="text" class="form-control" id="validationCustomPhone" required&gt;&lt;div class="invalid-feedback"&gt;
          please enter correct mobile no.
       &lt;/div&gt;&lt;/div&gt;&lt;div class="col-md-6"&gt;&lt;label for="validationAddress" class="form-label"&gt;Address&lt;/label&gt;&lt;input type="text" class="form-control" id="validationAddress" value="XYZ - 123" required&gt;&lt;div class="valid-feedback"&gt;
          Correct input!
         &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="col-md-3"&gt;&lt;label for="validationCustom" class="form-label"&gt;Gender&lt;/label&gt;&lt;select class="form-select" id="validationCustom" required&gt;&lt;option selected disabled value=""&gt;Choose...&lt;/option&gt;&lt;option&gt;Male&lt;/option&gt;&lt;option&gt;Female&lt;/option&gt;&lt;option&gt;Others&lt;/option&gt;&lt;/select&gt;&lt;div class="invalid-feedback"&gt;
          Please select gender.
       &lt;/div&gt;&lt;/div&gt;&lt;div class="col-12"&gt;&lt;div class="form-check"&gt;&lt;input class="form-check-input" type="checkbox" value="" id="invalidCheck" required&gt;&lt;label class="form-check-label" for="invalidCheck"&gt;
            I have reviewed and agree to Terms of Services and Privacy Policy.
         &lt;/label&gt;&lt;div class="invalid-feedback"&gt;
            You must agree before submitting.
         &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="col-12"&gt;&lt;button class="btn btn-primary" type="submit"&gt;Submit&lt;/button&gt;&lt;/div&gt;&lt;/form&gt;&lt;script&gt;
    (() =&gt; {
    'use strict'
    // Fetch all the forms we want to apply custom Bootstrap validation styles to
    const forms = document.querySelectorAll('.needs-validation')
    // Loop over them and prevent submission
    Array.from(forms).forEach(form =&gt; {
      form.addEventListener('submit', event =&gt; {
        if (!form.checkValidity()) {
          event.preventDefault()
          event.stopPropagation()
        }
        form.classList.add('was-validated')
      }, false)
    })
    })() </script></body></html>

    The following JavaScript code snippet disables form submissions if there are invalid fields. It achieves this by adding event listeners to the forms and preventing the default form submission behavior if the form is not valid.

        // Example JavaScript starter for disabling form submissions if there are invalid fields
    
    (() =&gt; {
      'use strict'
      // Fetch all the forms we want to apply custom Bootstrap validation styles to
      const forms = document.querySelectorAll('.needs-validation')
      // Loop over them and prevent submission
      Array.from(forms).forEach(form =&gt; {
        form.addEventListener('submit', event =&gt; {
          if (!form.checkValidity()) {
            event.preventDefault()
            event.stopPropagation()
          }
          form.classList.add('was-validated')
        }, false)
      })
    })()

    Browser defaults

    • We can also use browser default messages instead of custom validation message. Depending on your browser and OS, feedback style varies slightly.
    • Although CSS cannot be used to style these feedback styles, JavaScript can still be used to alter the feedback text.

    Try submitting the form in the following example to how default browser validation messages show up.https://www.tutorialspoint.com/bootstrap/examples/validation_browser_default.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap Form - Validation</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><form class="row g-3"><div class="col-md-4"><label for="validationDefaultName" class="form-label">Full Name</label><input type="text" class="form-control" id="validationDefaultName" value="name" required></div><div class="col-md-4"><label for="validationDefaultEmail" class="form-label">Email Id</label><div class="input-group"><input type="text" class="form-control" id="validationDefaultEmail" aria-describedby="inputGroupPrepend" required><span class="input-group-text" id="inputGroupPrepend">@tutorialspoint.com</span></div></div><div class="col-md-4"><label for="validationDefaultMob" class="form-label">Mobile No</label><input type="text" class="form-control" id="validationDefaultMob" value="" required></div><div class="col-md-6"><label for="validationDefaultAddress" class="form-label">Address</label><input type="text" class="form-control" id="validationDefaultAddress" required></div><div class="col-md-3"><label for="validationDefaultGender" class="form-label">Gender</label><select class="form-select" id="validationDefaultGender" required><option selected disabled value="">Choose...</option><option>Male</option><option>Female</option><option>Others</option></select></div><div class="form-check"><input class="form-check-input" type="checkbox" value="" id="invalidCheck2" required><label class="form-check-label" for="invalidCheck2">
    
              I have reviewed and agree to Terms of Services and Privacy Policy.
            &lt;/label&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="col-12"&gt;&lt;button class="btn btn-primary" type="submit"&gt;Submit&lt;/button&gt;&lt;/div&gt;&lt;/form&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Server-side

    • Client-side validation is recommended, but in case of server-side validation, use .is-invalid and .is-valid directives to indicate form field status. Also consider using .invalid-feedback with these classes.
    • Use aria-describedby attribute to link invalid feedback/error message to the form field in the case of invalid fields. (Allows more than one id to be referenced if field connects to other form text.)
    • Input groups need an additional .has-validation class for dealing with issues with border radius.
    https://www.tutorialspoint.com/bootstrap/examples/validation_server_side.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Validation</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><form class="row g-3"><div class="col-md-4"><label for="validationServerName" class="form-label">Full name</label><input type="text" class="form-control is-valid" id="validationServerName" value="Mark" required><div class="valid-feedback">
    
          enter your name
        &lt;/div&gt;&lt;/div&gt;&lt;div class="col-md-4"&gt;&lt;label for="validationServerEmail" class="form-label"&gt;Email Id&lt;/label&gt;&lt;div class="input-group has-validation"&gt;&lt;input type="text" class="form-control is-invalid" id="validationServerEmail"
            aria-describedby="inputGroupPrepend3 validationServerEmailFeedback" required&gt;&lt;span class="input-group-text" id="inputGroupPrepend3"&gt;@tutorialspoint.com&lt;/span&gt;&lt;div id="validationServerEmailFeedback" class="invalid-feedback"&gt;
            Please enter mail id.
          &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="col-md-4"&gt;&lt;label for="validationServerMob" class="form-label"&gt;Mobile no&lt;/label&gt;&lt;input type="text" class="form-control is-valid" id="validationServerMob" value="" required&gt;&lt;div class="valid-feedback"&gt;
          Please enter mobile no
        &lt;/div&gt;&lt;/div&gt;&lt;div class="col-md-6"&gt;&lt;label for="validationServerAddress" class="form-label"&gt;Address&lt;/label&gt;&lt;input type="text" class="form-control is-invalid" id="validationServerAddress"
          aria-describedby="validationServerAddressFeedback" required&gt;&lt;div id="validationServerAddressFeedback" class="invalid-feedback"&gt;
          Please enter a valid Address.
        &lt;/div&gt;&lt;/div&gt;&lt;div class="col-md-3"&gt;&lt;label for="validationServer04" class="form-label"&gt;Gender&lt;/label&gt;&lt;select class="form-select is-invalid" id="validationServer04" aria-describedby="validationServer04Feedback"
          required&gt;&lt;option selected disabled value=""&gt;Choose...&lt;/option&gt;&lt;option&gt;Male&lt;/option&gt;&lt;option&gt;Female&lt;/option&gt;&lt;option&gt;Others&lt;/option&gt;&lt;/select&gt;&lt;div id="validationServer04Feedback" class="invalid-feedback"&gt;
          Please select a valid gender.
        &lt;/div&gt;&lt;/div&gt;&lt;div class="col-12"&gt;&lt;div class="form-check"&gt;&lt;input class="form-check-input is-invalid" type="checkbox" value="" id="invalidCheckPolicy"
            aria-describedby="invalidCheckFeedback" required&gt;&lt;label class="form-check-label" for="invalidCheckPolicy"&gt;
            I have reviewed and agree to Terms of Services and Privacy Policy.
          &lt;/label&gt;&lt;div id="invalidCheckFeedback" class="invalid-feedback"&gt;
            You must agree before submitting.
          &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="col-12"&gt;&lt;button class="btn btn-primary" type="submit"&gt;Submit&lt;/button&gt;&lt;/div&gt;&lt;/form&gt;&lt;/body&gt;&lt;/html&gt;;

    Supported elements

    The following form controls and components support validation styles:

    • <textarea> and <input> using the .form-control (allowing input groups to contain up to one .form-control).
    • <select> using .form-select
    • .form-check
    https://www.tutorialspoint.com/bootstrap/examples/validation_supported_elements.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap Form - Validation</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><form class="was-validated"><div class="mb-3"><label for="validationTextarea" class="form-label">Add comment</label><textarea class="form-control" id="validationTextarea" placeholder="Comment Here" required></textarea><div class="invalid-feedback">
    
            Add comment
          &lt;/div&gt;&lt;/div&gt;&lt;div class="form-check mb-3"&gt;&lt;input type="checkbox" class="form-check-input" id="validationFormCheck" required&gt;&lt;label class="form-check-label" for="validationFormCheck"&gt;Item One&lt;/label&gt;&lt;div class="invalid-feedback"&gt;Invalid Answer&lt;/div&gt;&lt;/div&gt;&lt;div class="form-check"&gt;&lt;input type="radio" class="form-check-input" id="validationFormRadio1" name="radio-stacked" required&gt;&lt;label class="form-check-label" for="validationFormRadio1"&gt;Item Two&lt;/label&gt;&lt;/div&gt;&lt;div class="form-check mb-3"&gt;&lt;input type="radio" class="form-check-input" id="validationFormRadio2" name="radio-stacked" required&gt;&lt;label class="form-check-label" for="validationFormRadio2"&gt;Item Three&lt;/label&gt;&lt;div class="invalid-feedback"&gt;Invalid Answer&lt;/div&gt;&lt;/div&gt;&lt;div class="mb-3"&gt;&lt;select class="form-select" required aria-label="select example"&gt;&lt;option value=""&gt;Gender&lt;/option&gt;&lt;option value="1"&gt;Male&lt;/option&gt;&lt;option value="2"&gt;Female&lt;/option&gt;&lt;option value="3"&gt;Others&lt;/option&gt;&lt;/select&gt;&lt;div class="invalid-feedback"&gt;Invalid selection&lt;/div&gt;&lt;/div&gt;&lt;div class="mb-3"&gt;&lt;input type="file" class="form-control" aria-label="file example" required&gt;&lt;div class="invalid-feedback"&gt;File size more than 256kb&lt;/div&gt;&lt;/div&gt;&lt;div class="mb-3"&gt;&lt;button class="btn btn-primary" type="submit" disabled&gt;Submit&lt;/button&gt;&lt;/div&gt;&lt;/form&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Tooltips

    • To display validation feedback in a styled tooltip, swap the classes .{valid|invalid}-feedback for .{valid|invalid}-tooltip if the layout permits it.
    • To position the tooltip, make sure the parent has the property position: relative.
    https://www.tutorialspoint.com/bootstrap/examples/validation_Tooltips.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Validation</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><form class="row g-3 needs-validation" novalidate><div class="col-md-4 position-relative"><label for="validationTooltipName" class="form-label">Full Name</label><input type="text" class="form-control" id="validationTooltipName" value="Jhon Miller" required><div class="valid-tooltip">
    
          Correct Input!
        &lt;/div&gt;&lt;/div&gt;&lt;div class="col-md-4 position-relative"&gt;&lt;label for="validationTooltipEmail" class="form-label"&gt;Email Id&lt;/label&gt;&lt;div class="input-group has-validation"&gt;&lt;input type="text" class="form-control" id="validationTooltipEmail" aria-describedby="validationTooltipEmailPrepend" required&gt;&lt;span class="input-group-text" id="validationTooltipEmailPrepend"&gt;@tutorialspoint.com&lt;/span&gt;&lt;div class="invalid-tooltip"&gt;
           Please enter mail id.
          &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="col-md-4 position-relative"&gt;&lt;label for="validationTooltipMob" class="form-label"&gt;Mobile no&lt;/label&gt;&lt;input type="text" class="form-control" id="validationTooltipMob" required&gt;&lt;div class="invalid-tooltip"&gt;
          Please enter mobile no.
        &lt;/div&gt;&lt;/div&gt;&lt;div class="col-md-6 position-relative"&gt;&lt;label for="validationTooltipAddress" class="form-label"&gt;Address&lt;/label&gt;&lt;input type="text" class="form-control" id="validationTooltipAddress" value="XYZ - 123" required&gt;&lt;div class="valid-tooltip"&gt;
         Correct Input!
        &lt;/div&gt;&lt;/div&gt;&lt;div class="col-md-3 position-relative"&gt;&lt;label for="validationTooltip04" class="form-label"&gt;Gender&lt;/label&gt;&lt;select class="form-select" id="validationTooltip04" required&gt;&lt;option selected disabled value=""&gt;Choose...&lt;/option&gt;&lt;option&gt;Male&lt;/option&gt;&lt;option&gt;Female&lt;/option&gt;&lt;option&gt;Others&lt;/option&gt;&lt;/select&gt;&lt;div class="invalid-tooltip"&gt;
          Please select a valid gender.
        &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="col-12"&gt;&lt;button class="btn btn-primary" type="submit"&gt;Submit&lt;/button&gt;&lt;/div&gt;&lt;/form&gt;&lt;script&gt;
      (() =&gt; {
    'use strict'
    // Fetch all the forms we want to apply custom Bootstrap validation styles to
    const forms = document.querySelectorAll('.needs-validation')
    // Loop over them and prevent submission
    Array.from(forms).forEach(form =&gt; {
      form.addEventListener('submit', event =&gt; {
        if (!form.checkValidity()) {
          event.preventDefault()
          event.stopPropagation()
        }
        form.classList.add('was-validated')
      }, false)
    })
    })()
    &lt;/script&gt;&lt;/body&gt;&lt;/html&gt;</pre>

  • Form Layout

    This chapter will discuss about Bootstrap form layout. Add structure to your forms with form layout options, from inline to horizontal to implementing custom grids.

    Form layout

    • Bootstrap gives no default styling for the <form> element, but there are a few capable browser highlights that are given by default. Each group of form fields must be inside a <form> element.
    • Ensure to be specify and include a type attribute for <button>s within a <form> as they default to type=”submit”.
    • Forms are stacked vertically by default. Bootstrap uses display: block and width: 100% to nearly all form controls. To change layout of each form, use additional classes.

    Utilities

    • To add some structure to forms should be use margin utilities. Use basic grouping of labels, controls, optional form text, and form validation messages.
    • For consistency, sticking to margin-bottom utilities and employing a single direction all through the form is recommended.
    https://www.tutorialspoint.com/bootstrap/examples/layout_utilities.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Layout </title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="mb-3"><label for="formGroupExampleInput" class="form-label">Username</label><input type="text" class="form-control" id="formGroupExampleInput" placeholder="Username"></div><div class="mb-3"><label for="formGroupExampleInput2" class="form-label">Password</label><input type="text" class="form-control" id="formGroupExampleInput2" placeholder="password"></div></body></html>

    Form grid

    Use grid classes for building the more complex forms. Form a grid for form layouts that require multiple columns, varied widths, and additional alignment options. You need to enable Sass variable using $enable-grid-classes.https://www.tutorialspoint.com/bootstrap/examples/layout_form_grid.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Layout</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="row mt-2"><div class="col"><input type="text" class="form-control" placeholder="Username" aria-label="Username"></div><div class="col"><input type="text" class="form-control" placeholder="Password" aria-label="Password"></div></div></body></html>

    Gutters

    To control over the gutter width in the inline as block direction use the gutter modifier classes. By using $enable-grid-classes you can enable Sass variable.https://www.tutorialspoint.com/bootstrap/examples/layout_gutters.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Layout</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="row g-3 mt-2"><div class="col"><input type="text" class="form-control" placeholder="Username" aria-label="Username"></div><div class="col"><input type="text" class="form-control" placeholder="Password" aria-label="Password"></div></div></body></html>

    Create more complex layouts using the grid system.

    https://www.tutorialspoint.com/bootstrap/examples/layout_complex_layout_using_grid_system.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Layout</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><form class="row g-3"><div class="col-md-6"><label for="inputFirst" class="form-label">First name</label><input type="text" class="form-control" id="inputFirst"></div><div class="col-md-6"><label for="inputLast" class="form-label">Last name</label><input type="text" class="form-control" id="inputLast"></div><div class="col-md-6"><label for="inputEmail" class="form-label">Email</label><input type="email" class="form-control" id="inputEmail"></div><div class="col-6"><label for="inputPassword" class="form-label">Password</label><input type="Password" class="form-control" id="inputPassword" placeholder="password"></div><div class="col-12"><label for="inputAddress" class="form-label">Address</label><input type="text" class="form-control" id="inputAddress" placeholder="Address"></div><div class="col-md-6"><label for="inputAdharno" class="form-label">Adharcard no</label><input type="text" class="form-control" id="inputAdharno"></div><div class="col-md-6"><label for="inputMobno" class="form-label">Mobile no</label><input type="text" class="form-control" id="inputMobno"></div><div class="col-12"><div class="form-check"><input class="form-check-input" type="checkbox" id="gridCheck"><label class="form-check-label" for="gridCheck">
    
              I agree to terms and conditions
            &lt;/label&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="col-12"&gt;&lt;button type="submit" class="btn btn-primary"&gt;Submit&lt;/button&gt;&lt;/div&gt;&lt;/form&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Horizontal form

    • Use the class .row to form groups to create horizontal forms with the grid. Use the class .col-*-* to define the width of the labels and controls.
    • To make a form vertically centered with their associated form controls, use the class .col-form-label to <label>.
    https://www.tutorialspoint.com/bootstrap/examples/layout_horizontal_form.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Layout</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><form><div class="row mb-3"><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"></div></div><div class="row mb-3"><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"></div></div><fieldset class="row mb-3"><legend class="col-form-label col-sm-2 pt-0">Language Known</legend><div class="col-sm-10"><div class="form-check"><input class="form-check-input" type="checkbox" name="gridCheck" id="gridCheck1" value="option1" checked><label class="form-check-label" for="gridCheck1">
    
                English
              &lt;/label&gt;&lt;/div&gt;&lt;div class="form-check"&gt;&lt;input class="form-check-input" type="checkbox"  name="gridCheck" id="gridCheck2" value="option2"&gt;&lt;label class="form-check-label" for="gridCheck2"&gt;
                Hindi
              &lt;/label&gt;&lt;/div&gt;&lt;div class="form-check"&gt;&lt;input class="form-check-input" type="checkbox"  name="gridCheck" id="gridCheck2" value="option2"&gt;&lt;label class="form-check-label" for="gridCheck2"&gt;
                  marathi
                &lt;/label&gt;&lt;/div&gt;&lt;div class="form-check disabled"&gt;&lt;input class="form-check-input"type="checkbox"  name="gridCheck" id="gridCheck3" value="option3" disabled&gt;&lt;label class="form-check-label" for="gridCheck3"&gt;
                Others
              &lt;/label&gt;&lt;/div&gt;&lt;/div&gt;&lt;/fieldset&gt;&lt;div class="row mb-3"&gt;&lt;div class="col-sm-10 offset-sm-2"&gt;&lt;div class="form-check"&gt;&lt;input class="form-check-input" type="radio" id="gridRadio1"&gt;&lt;label class="form-check-label" for="gridRadio1"&gt;
                Radio Button
              &lt;/label&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;button type="submit" class="btn btn-primary"&gt;Submit&lt;/button&gt;&lt;/form&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Horizontal form label sizing

    Use the classes .col-form-label-sm or .col-form-label-lg to your <label> or <legend> to follow the size of .form-control-sm and .form-control-lg respectively.https://www.tutorialspoint.com/bootstrap/examples/layout_horizontal_form_label_sizing.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Layout</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="row mb-3"><label for="colFormSm" class="col-sm-2 col-form-label col-form-label-sm">Username</label><div class="col-sm-10"><input type="email" class="form-control form-control-sm" id="colFormSm" placeholder="Username"></div></div><div class="row mb-3"><label for="colFormLabel" class="col-sm-2 col-form-label">Password</label><div class="col-sm-10"><input type="text" class="form-control" id="colFormLabel" placeholder="Password"></div></div><div class="row"><label for="colFormLg" class="col-sm-2 col-form-label col-form-label-lg">Email</label><div class="col-sm-10"><input type="email" class="form-control form-control-lg" id="colFormLg" placeholder="email"></div></div></body></html>

    Column sizing

    As mentioned in the previous example, the grid system allows any number of .cols within a .row. Divide the available width evenly between them. You can also use a specific column class like .col-sm-7 to select a subset of columns to occupy more or less space while the remaining .col divides the rest evenly.https://www.tutorialspoint.com/bootstrap/examples/layout_column_sizing.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Layout</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="row g-3"><div class="col-sm-6"><input type="text" class="form-control" placeholder="Email" aria-label="Email"></div><div class="col-sm-3"><input type="text" class="form-control" placeholder="Mobile no" aria-label="Mobile no"></div><div class="col-sm-2"><input type="text" class="form-control" placeholder="Age" aria-label="Age"></div></div></body></html>

    Auto-sizing

    In the below example, use flexbox utility to center the content vertically and change .col to .col-auto. So that the column only takes up as much space as it needs. In other words, the column size depends on the content.https://www.tutorialspoint.com/bootstrap/examples/layout_auto_sizing.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Layout</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><form class="row gy-2 gx-3 align-items-center"><div class="col-auto"><label class="visually-hidden" for="inputName">Name</label><input type="text" class="form-control" id="inputName" placeholder="Name"></div><div class="col-auto"><label class="visually-hidden" for="inputGroup"></label><div class="input-group"><input type="text" class="form-control" id="inputGroup" placeholder="Username"><div class="input-group-text">@gmail.com</div></div></div><div class="col-auto"><label class="visually-hidden" for="selectLanguage">Language</label><select class="form-select" id="selectLanguage"><option selected>Choose...</option><option value="1">English</option><option value="2">Hindi</option><option value="3">Marathi</option></select></div><div class="col-auto"><div class="form-check"><input class="form-check-input" type="checkbox" id="autoSizingCheck"><label class="form-check-label" for="autoSizingCheck">
    
            Remember me
          &lt;/label&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="col-auto"&gt;&lt;button type="submit" class="btn btn-primary"&gt;Submit&lt;/button&gt;&lt;/div&gt;&lt;/form&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Then you can remix again with size-specific column classes.https://www.tutorialspoint.com/bootstrap/examples/layout_autosizing_size_specific.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Layout</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><form class="row gx-3 gy-2 align-items-center mt-2"><div class="col-sm-3"><label class="visually-hidden" for="inputName">Name</label><input type="text" class="form-control" id="inputName" placeholder="Name"></div><div class="col-sm-3"><label class="visually-hidden" for="specificSizeInputGroupUsername">Username</label><div class="input-group"><input type="text" class="form-control" id="specificSizeInputGroupUsername" placeholder="Email"><div class="input-group-text">@gmail.com</div></div></div><div class="col-sm-3"><label class="visually-hidden" for="selectLanguage">Language</label><select class="form-select" id="selectLanguage"><option selected>Choose...</option><option value="1">English</option><option value="2">Hindi</option><option value="3">Marathi</option></select></div><div class="col-auto"><div class="form-check"><input class="form-check-input" type="checkbox" id="autoSizingCheck2"><label class="form-check-label" for="autoSizingCheck2">
    
            Remember me
          &lt;/label&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="col-auto"&gt;&lt;button type="submit" class="btn btn-primary"&gt;Submit&lt;/button&gt;&lt;/div&gt;&lt;/form&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Inline forms

    • To build responsive horizontal layouts use the classes .row-cols-*.
    • Use gutter modifier classes to have gutters in horizontal and vertical directions.
    • In narrow mobile viewports, .col-12 is useful for stacking form controls, etc.
    • To align the form elements at the middle and make the .form-check align properly use the class .align-items-center.
    https://www.tutorialspoint.com/bootstrap/examples/layout_inline_form.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Layout</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><form class="row row-cols-lg-auto g-3 align-items-center"><div class="col-12"><label class="visually-hidden" for="inlineFormInputGroupUsername">Username</label><div class="input-group"><input type="text" class="form-control" id="inlineFormInputGroupUsername" placeholder="Username"><div class="input-group-text">@gmail.com</div></div></div><div class="col-12"><label class="visually-hidden" for="selectLanguage">Language</label><select class="form-select" id="selectLanguage"><option selected>Choose...</option><option value="1">English</option><option value="2">Hindi</option><option value="3">Marathi</option></select></div><div class="col-12"><div class="form-check"><input class="form-check-input" type="checkbox" id="inlineFormCheck"><label class="form-check-label" for="inlineFormCheck">
    
            Remember me
          &lt;/label&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="col-12"&gt;&lt;button type="submit" class="btn btn-primary"&gt;Submit&lt;/button&gt;&lt;/div&gt;&lt;/form&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Print Page

  • Floating Labels

    This chapter will discuss about Bootstrap floating labels. Floating labels refer to form labels that float over the input fields.

    Basic example

    • To allow floating labels with Bootstrap’s textual form fields, include a pair of <input class=”form-control”> and <label> elements in .form-floating.
    • Each <input> must have a placeholder since the technique for CSS-only floating labels employs the :placeholder-shown pseudo-element. The <input> needs to be placed first to make use of a sibling selector like (~).
    https://www.tutorialspoint.com/bootstrap/examples/floating_labels_basic_example.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Floating Labels</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="form-floating mb-3 mt-2"><input type="text" class="form-control" id="floatingUsername" placeholder="[email protected]"><label for="floatingUsername">Username</label></div><div class="form-floating"><input type="password" class="form-control" id="floatingPassword" placeholder="Password"><label for="floatingPassword">Password</label></div></body></html>

    When a value is already assigned, <label> elements will automatically align their position to float over the input field.https://www.tutorialspoint.com/bootstrap/examples/floating_labels_floated_location.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Floating Labels</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><form class="form-floating mt-2"><input type="email" class="form-control" id="floatingInputValue" placeholder="[email protected]" value="[email protected]"><label for="floatingInputValue">Username</label></form></body></html>

    By using form validation styles like is-invalid, you can provide visual feedback to users when they submit incorrect data.https://www.tutorialspoint.com/bootstrap/examples/floating_labels_floated_location.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Floating Labels</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><form class="form-floating"><input type="text" class="form-control is-invalid" id="floatingInvalidInput" placeholder="Password" value="Password"><label for="floatingInvalidInput">Invalid Password</label></form></body></html>

    Textareas

    The height of <textarea> with the class .form-control is automatically set to have the same height as <input>.https://www.tutorialspoint.com/bootstrap/examples/floating_labels_textareas.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Floating Labels</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="form-floating"><textarea class="form-control" placeholder="Text Here" id="floatingTextarea"></textarea><label for="floatingTextarea">Text Here</label></div></body></html>

    Don’t use the rows attribute if you want to customize the height of your <textarea>. Instead, specify a height explicitly (either inline or using customized CSS). In the below example we have used inline styling.https://www.tutorialspoint.com/bootstrap/examples/floating_labels_customize_textareas.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Floating Labels</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="form-floating"><textarea class="form-control" placeholder="Add a comment" id="floatingTextarea" style="height: 100px"></textarea><label for="floatingTextarea">Add a comment</label></div></body></html>

    Selects

    • Floating labels are only accessible on .form-selects, in addition to .form-control.
    • The same concepts apply to them, except unlike <input>s, they always display the <label> in its floated state. Size-based and multiple selects are not supported.
    https://www.tutorialspoint.com/bootstrap/examples/floating_labels_selects.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Floating Labels</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="form-floating"><select class="form-select" id="floatingSelect" aria-label="Floating label select menu"><option selected>Language</option><option value="1">English</option><option value="2">Hindi</option><option value="3">Marathi</option></select><label for="floatingSelect">Others</label></div></body></html>

    Disabled

    Add the disabled boolean attribute on an input. This gives grayed-out appearance to an input, textarea, or select. It also removes pointer events, and prevents focusing.https://www.tutorialspoint.com/bootstrap/examples/floating_labels_disabled.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Floating Labels</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="form-floating mb-3"><input type="email" class="form-control" id="floatingInputDisabled" placeholder="name" disabled><label for="floatingInputDisabled">Name</label></div><div class="form-floating mb-3"><textarea class="form-control" placeholder="[email protected]" id="floatingEmailDisabled" disabled></textarea><label for="floatingEmailDisabled">Email Id</label></div><div class="form-floating mb-3"><textarea class="form-control" placeholder="Add a comment" id="floatingTextareaDisabled" style="height: 120px" disabled></textarea><label for="floatingTextareaDisabled">Add a comment</label></div><div class="form-floating"><select class="form-select" id="floatingSelectDisabled" aria-label="Floating label disabled select example" disabled><option selected>Select Language</option><option value="1">English</option><option value="2">Hindi</option><option value="3">Marathi</option></select><label for="floatingSelectDisabled">Others</label></div></body></html>

    Readonly plaintext

    When switching from an editable <input> to a plaintext value without changing the page layout, .form-control-plaintext can be useful.https://www.tutorialspoint.com/bootstrap/examples/floating_labels_readonly_plaintext.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Floating Labels</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="form-floating mb-3 mt-2"><input type="text" readonly class="form-control" id="floatingEmptyPlaintextInput" style="height: 80px" placeholder="Block the comment" value="Block the comment"><label for="floatingEmptyPlaintextInput">Block the comment</label></div><div class="form-floating mb-3"><input type="text" readonly class="form-control" id="floatingPlaintextInput" style="height: 80px" placeholder="Add a comment" value="Add a comment"><label for="floatingPlaintextInput">Add a comment</label></div></body></html>

    Input groups

    Similarly, floating labels support .input-group.https://www.tutorialspoint.com/bootstrap/examples/floating_labels_input_groups.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Floating Labels</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="input-group mb-3"><div class="form-floating"><input type="email" class="form-control" id="floatingInputGroup" placeholder="email"><label for="floatingInputGroup">Email Id</label></div><span class="input-group-text">[email protected]</span></div></body></html>

    The -feedback (it is a validation class to provide valuable feedback to users before submitting the form.) should be positioned outside of the .form-floating but inside of the .input-group when using .input-group and .form-floating along with form validation.https://www.tutorialspoint.com/bootstrap/examples/floating_labels_has_validation.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Floating Labels</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="input-group has-validation"><div class="form-floating is-invalid"><input type="text" class="form-control is-invalid" id="floatingInputGroup" placeholder="Password" required><label for="floatingInputGroup">Password</label></div><div class="invalid-feedback">
    
                Wrong Password
            &lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Layout

    • When using a grid system, the implementation of floating labels layout becomes beneficial as it enables the placement of form elements within column classes.
    • There is no pre-defined classes in bootstrap, so we must utilize form classes and position them according to our requirement.
    https://www.tutorialspoint.com/bootstrap/examples/floating_labels_layout.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Floating Labels</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="row g-2"><div class="col-md"><div class="form-floating"><input type="email" class="form-control" id="floatingGrid" placeholder="[email protected]" value="[email protected]"><label for="floatingGrid">Email Id</label></div></div><div class="col-md"><div class="form-floating"><select class="form-select" id="floatingSelectGrid"><option selected>Language</option><option value="1">English</option><option value="2">Hindi</option><option value="3">Marathi</option></select><label for="floatingSelectGrid">Others</label></div></div></div></html>

  • Input Groups

    This chapter will discuss about bootstrap input groups component. A bootstrap input group component is a an extremely versatile and effective form controls for building appealing and visually appealing form controls, however it is only compatible with text input, select, and textarea.

    Users may quickly add text, buttons, or button groups to the sides of text inputs, custom selections, and custom file inputs to extend form controls.

    Input groups

    • The sections that follow will show users how to add text, icons, and buttons before, after, or on either side of form controls to make the form appear more professional.
    • An icon, sampletext, or a button can be added in front of or behind the input field using the .input-group class, which is a container to enhance inputs.
    https://www.tutorialspoint.com/bootstrap/examples/input_groups_basic_example.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Input Groups </title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container mt-3"><form action="/contact.php"><div class="input-group mb-3"><span class="input-group-text">@ </span><input type="text" class="form-control" placeholder="Username" name="usrname"></div><div class="input-group mb-3"><input type="text" class="form-control" placeholder="Your Email" name="email"><span class="input-group-text">@tutorialspoint.com </span></div><button type="submit" class="btn btn-success">Submit </button></form></div></body></html>

    Wrapping

    By default, input groups wrap uses the flex-wrap: wrap class to allow for custom form field validation inside the input group. Users can disable this using .flex-nowrap class.https://www.tutorialspoint.com/bootstrap/examples/input_groups_with_wrapping.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Input Groups </title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container mt-3"><div class="input-group flex-nowrap"><span class="input-group-text" id="addon-wrapping">Email address</span><input type="email" class="form-control" placeholder="[email protected]" aria-label="email id" aria-describedby="addon-wrapping"></div></div></body></html>

    Sizing

    For small and large input groups, respectively, use the .input-group-sm and .input-group-lg classes.https://www.tutorialspoint.com/bootstrap/examples/input_groups_sizing.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Input Groups</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container mt-3"><div class="input-group input-group-sm mb-3"><span class="input-group-text">@small</span><input type="text" class="form-control" aria-label="Input for sizing" aria-describedby="inputGroup-sizing-sm"></div><div class="input-group mb-3"><span class="input-group-text">@default</span><input type="text" class="form-control" aria-label="Input for sizing" aria-describedby="inputGroup-sizing-default"></div><div class="input-group input-group-lg mb-3"><span class="input-group-text">@large</span><input type="text" class="form-control" aria-label="Input for sizing" aria-describedby="inputGroup-sizing-lg"></div></div></body></html>

    Checkboxes and radios

    Insert the text inside the input group’s addon using any checkbox or radio button. If there is no text next to the input, we suggest to add .mt-0 to the .form-check-input.https://www.tutorialspoint.com/bootstrap/examples/input_groups_checkboxes_radios.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Input Groups </title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container mt-3"><div class="input-group mb-3"><div class="input-group-text"><input class="form-check-input mt-0" type="checkbox" value="" aria-label="Checkbox"></div><input type="text" class="form-control" placeholder="Item 1"></div><div class="input-group"><div class="input-group-text"><input class="form-check-input mt-0" type="radio" value="" aria-label="Radio button"></div><input type="text" class="form-control" placeholder="Item 2"></div></div></body></html>

    Multiple inputs

    Although more than one <input> tags can be displayed visually, validation styles are only offered for input groups with a single <input> tag.https://www.tutorialspoint.com/bootstrap/examples/input_groups_with_multiple_inputs.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Input Groups </title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container mt-3"><div class="input-group"><span class="input-group-text">Student email id and  password </span><input type="text" aria-label=" email id " class="form-control"><input type="text" aria-label="password" class="form-control"></div></div></body></html>

    Multiple addons

    Users have the option to combine multiple addons into a single input group. Additionally, you can mix both the checkbox and radio inputs, as demonstrated in the example below.https://www.tutorialspoint.com/bootstrap/examples/input_groups_with_multiple_addons.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Input Groups </title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container mt-3"><div class="input-group mb-3"><span class="input-group-text"><input type="checkbox" class="form-check-input mt-0"></span><span class="input-group-text">$</span><span class="input-group-text">0.00</span><input type="text" class="form-control"></div><div class="input-group mb-3"><input type="text" class="form-control"><span class="input-group-text">$</span><span class="input-group-text">0.00</span></div></div></body></html>

    Button addons

    Users can add or remove buttons from form controls like text. Easily add any number of buttons that you want to the .input-group, as shown in the example below.https://www.tutorialspoint.com/bootstrap/examples/input_groups_with_button_addons.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Input Groups </title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container mt-4"><div class="row"><div class="input-group mb-3"><input type="text" class="form-control" placeholder="Search"><button type="button" class="btn btn-primary"><i class="bi-search"></i></button></div><div class="input-group"><input type="text" class="form-control" placeholder="Type text"><button type="submit" class="btn btn-success">Submit</button><button type="clear" class="btn btn-danger">Clear</button></div></div></div></body></html>

    Buttons with dropdowns

    Users have the option to combine multiple addons into a single input group. Additionally, you can mix both the checkbox and radio inputs, as demonstrated in the example below.https://www.tutorialspoint.com/bootstrap/examples/input_groups_buttons_with_dropdowns.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Input Groups </title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container mt-4"><div class="input-group mb-3"><button class="btn btn-outline-dark dropdown-toggle" type="button" data-bs-toggle="dropdown"
    
          aria-expanded="false"&gt;Dropdown&lt;/button&gt;&lt;ul class="dropdown-menu"&gt;&lt;li&gt;&lt;a class="dropdown-item" href="#"&gt;Home&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a class="dropdown-item" href="#"&gt;About Us&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a class="dropdown-item" href="#"&gt;Services&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;hr class="dropdown-divider"&gt;&lt;/li&gt;&lt;li&gt;&lt;a class="dropdown-item" href="#"&gt;Others&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;input type="text" class="form-control" aria-label="Dropdown button"&gt;&lt;/div&gt;&lt;div class="input-group mb-3"&gt;&lt;input type="text" class="form-control" aria-label="Dropdown button"&gt;&lt;button class="btn btn-outline-dark dropdown-toggle" type="button" data-bs-toggle="dropdown"
          aria-expanded="false"&gt;Dropdown&lt;/button&gt;&lt;ul class="dropdown-menu dropdown-menu-end"&gt;&lt;li&gt;&lt;a class="dropdown-item" href="#"&gt;Home&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a class="dropdown-item" href="#"&gt;About Us&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a class="dropdown-item" href="#"&gt;Services&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;hr class="dropdown-divider"&gt;&lt;/li&gt;&lt;li&gt;&lt;a class="dropdown-item" href="#"&gt;Others&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&gt;
      &lt;/div&gt;&lt;div class="input-group  mb-3"&gt;&lt;button class="btn btn-outline-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown"
          aria-expanded="false"&gt;Dropdown&lt;/button&gt;&lt;ul class="dropdown-menu"&gt;&lt;li&gt;&lt;a class="dropdown-item" href="#"&gt;Home&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a class="dropdown-item" href="#"&gt;About Us&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a class="dropdown-item" href="#"&gt;Services&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;hr class="dropdown-divider"&gt;&lt;/li&gt;&lt;li&gt;&lt;a class="dropdown-item" href="#"&gt;Others&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;input type="text" class="form-control" aria-label="Text input with 2 dropdown buttons"&gt;&lt;button class="btn btn-outline-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown"
          aria-expanded="false"&gt;Dropdown&lt;/button&gt;&lt;ul class="dropdown-menu dropdown-menu-end"&gt;&lt;li&gt;&lt;a class="dropdown-item" href="#"&gt;Home&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a class="dropdown-item" href="#"&gt;About Us&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a class="dropdown-item" href="#"&gt;Services&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;hr class="dropdown-divider"&gt;&lt;/li&gt;&lt;li&gt;&lt;a class="dropdown-item" href="#"&gt;Others&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Segmented buttons

    The same common style that defines a dropdown button is used by segmented buttons to segment dropdowns in input groups. The .btn class is used to create buttons, and the .dropdown-menu class is used to create dropdown menus.https://www.tutorialspoint.com/bootstrap/examples/input_groups_segmented_buttons_with_dropdowns.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Input Groups </title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container mt-4"><div class="input-group mb-3"><button type="button" class="btn btn-outline-dark">Home</button><button type="button" class="btn btn-outline-dark dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false"><span class="visually-hidden">Toggle Dropdown</span></button><ul class="dropdown-menu"><li><a class="dropdown-item" href="#">Home</a></li><li><a class="dropdown-item" href="#">About Us</a></li><li><a class="dropdown-item" href="#">Services</a></li><li><hr class="dropdown-divider"></li><li><a class="dropdown-item" href="#">Separated link</a></li></ul><input type="text" class="form-control" aria-label="Segmented dropdown button"></div><div class="input-group"><input type="text" class="form-control" aria-label="Segmented dropdown button"><button type="button" class="btn btn-outline-dark">Home</button><button type="button" class="btn btn-outline-dark dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false"><span class="visually-hidden">Toggle Dropdown</span></button><ul class="dropdown-menu dropdown-menu-end"><li><a class="dropdown-item" href="#">Home</a></li><li><a class="dropdown-item" href="#">About Us</a></li><li><a class="dropdown-item" href="#">Services</a></li><li><hr class="dropdown-divider"></li><li><a class="dropdown-item" href="#">Separated link</a></li></ul></div></div></body></html>

    Custom forms

    Custom forms are expanded form controls used to gather certain data from website visitors. There are restrictions on the number of different forms you can create using custom forms. There are two types of custom forms:

    • Custom select
    • Custom file input

    Users can select or pick from a predefined option using the custom select menu, which is a dropdown menu.https://www.tutorialspoint.com/bootstrap/examples/input_groups_with_custom_select_form.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Input Groups </title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container mt-4"><div class="input-group mb-3"><label class="input-group-text" for="customSelect1">Options</label><select class="form-select" id="customSelect1"><option selected>Select the Subject</option><option value="1">English</option><option value="2">Mathematics</option><option value="3">Science</option></select></div><div class="input-group mb-3"><select class="form-select" id="customSelect2"><option selected>Select the Subject</option><option value="1">English</option><option value="2">Mathematics</option><option value="3">Science</option></select><label class="input-group-text" for="customSelect2">Options</label></div><div class="input-group mb-3"><button class="btn btn-outline-dark" type="button">Button</button><select class="form-select" id="customSelect3" aria-label="Button addon"><option selected>Select the Subject</option><option value="1">English</option><option value="2">Mathematics</option><option value="3">Science</option></select></div><div class="input-group"><select class="form-select" id="customSelect4" aria-label="Button addon"><option selected>Select the Subject</option><option value="1">English</option><option value="2">Mathematics</option><option value="3">Science</option></select><button class="btn btn-outline-dark" type="button">Button</button></div></div></body></html>

    Custom file input

    In custom file input users can choose a file by clicking a button that opens a file to select from your personal computer or server.

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html ><html lang="en" ><head ><title >Bootstrap - Input Groups  </title ><meta charset="UTF-8" ><meta http-equiv="X-UA-Compatible" content="IE=edge" ><meta name="viewport" content="width=device-width, initial-scale=1.0" ><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" ><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" ></script ></head ><body ><div class="container mt-4" ><div class="input-group mb-3" ><label class="input-group-text" for="customFileInput1" >Upload </label ><input type="file" class="form-control" id="customFileInput1" ></div ><div class="input-group mb-3" ><input type="file" class="form-control" id="customFileInput2" ><label class="input-group-text" for="customFileInput2" >Upload </label ></div ><div class="input-group mb-3" ><button class="btn btn-outline-primary" type="button" id="customFileInput3" >Option Button </button ><input type="file" class="form-control" id="inputGroupFile03" aria-describedby="customFileInput3" aria-label="Upload" ></div ><div class="input-group" ><input type="file" class="form-control" id="inputGroupFile04" aria-describedby="customFileInput4" aria-label="Upload" ><button class="btn btn-outline-primary" type="button" id="customFileInput4" >Option Button </button ></div ></div ></body ></html >

  • Range

    This chapter will discuss about Bootstrap form range. Range is an interactive component. The user can quickly scroll and slide through possible values spread across the required range.

    Basic example

    • Use class .form-range to create unique controls for <input type=”range”>. Both track and thumb have the same appearance across all browsers.
    • Bootstrap doesn’t support “filling” their range’s track from left to right of the thumb as a means to visually indicate progress. This is only supported on firefox.
    <!DOCTYPE html><html lang="en"><head><title>Bootstrap Form - Range</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><label for="basicRange" class="form-label">Range</label><input type="range" class="form-range" id="basicRange"></body></html>

    Disabled

    • The disabled attribute is used to disable the Range.
    • Disabled range cannot be focused, appears greyed out, and has no pointer events.

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap Form - Range</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><label for="disabledRange" class="form-label">Range</label><input type="range" class="form-range" id="disabledRange" disabled></body></html>

    Min and max

    Default range input for min is 0 and max is 100. If you are using min and max attributes, new values can be specified.https://www.tutorialspoint.com/bootstrap/examples/range_min_and_max.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap Form - Range</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><label for="minmaxrange" class="form-label">Range</label><input type="range" class="form-range" min="0" max="9" id="minmaxrange"></body></html>

    Steps

    Range step determines how much the range input value will increase or decrease in one step. Number of steps is doubled when step=”0.5″ is used.https://www.tutorialspoint.com/bootstrap/examples/range_steps.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap Form - Range</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><label for="stepRange" class="form-label">Range</label><input type="range" class="form-range" min="0" max="7" step="0.5" id="stepRange"></html>

    Print Page

  • Checkbox and Radios

    This chapter will discuss about checkbox and radios utilities provided by Bootstrap. Checkboxes allow you to select one or more alternatives from a list, whereas radio buttons allow you to choose only one.

    Approach

    • Bootstrap provides wrapper class .form-check for improved layout and behavior of browser default checkboxes and radios elements. It also allows greater customization and cross browser consistency.
    • .form-check-label class is used to show checkbox labels.
    • .form-check-input class is used for input type checkbox.
    • Structurally, the input and label act as siblings.

    Bootstrap’s custom icons are used to display checked or indeterminate states.

    Checkbox

    Checkboxes select one or several options from a list.https://www.tutorialspoint.com/bootstrap/examples/checkbox.php

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Checkbox</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="form-check"><input class="form-check-input" type="checkbox" value="" id="defaultCheck"><label class="form-check-label" for="defaultCheck">
    
       item 1
      &lt;/label&gt;&lt;/div&gt;&lt;div class="form-check"&gt;&lt;input class="form-check-input" type="checkbox" value="" id="flexCheckChecked" checked&gt;&lt;label class="form-check-label" for="flexCheckChecked"&gt;
        item 2
      &lt;/label&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Indeterminate

    • The :indeterminate pseudo class is used to create intermediate state checkboxes.
    • The indeterminate state is set via JavaScript as there is no equivalent HTML attribute available to specify it.

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Checkbox</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="form-check"><input class="form-check-input" type="checkbox" value="" id="indeterminateCheckbox" ><label class="form-check-label" for="indeterminateCheckbox">
    
         item 1
      &lt;/label&gt;&lt;/div&gt;&lt;script&gt;
      var x = document.getElementById("indeterminateCheckbox").indeterminate = true;;
    </script></body></html>

    Disabled checkbox

    To indicate disabled state use disabled attribute. This makes the associated <label> lighter color indicating disabled state.https://www.tutorialspoint.com/bootstrap/examples/checkbox_disabled.php

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Checkbox</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="form-check"><input class="form-check-input" type="checkbox" value="" id="disabledIndeterminateCheckbox" disabled><label class="form-check-label" for="disabledIndeterminateCheckbox">
    
         item 1
      &lt;/label&gt;&lt;/div&gt;&lt;div class="form-check"&gt;&lt;input class="form-check-input" type="checkbox" value="" id="disabledCheckedCheckbox" checked disabled&gt;&lt;label class="form-check-label" for="disabledCheckedCheckbox"&gt;
         item 2
      &lt;/label&gt;&lt;/div&gt;&lt;div class="form-check"&gt;&lt;input class="form-check-input" type="checkbox" value="" id="disabledCheckbox" disabled&gt;&lt;label class="form-check-label" for="disabledCheckbox"&gt;
       item 3
      &lt;/label&gt;&lt;/div&gt;&lt;/body&gt;&lt;script&gt;
    var x = document.getElementById("disabledIndeterminateCheckbox").indeterminate = true;
    </script></html>

    Radios

    Radio button limits the number of choices to only one in a list.https://www.tutorialspoint.com/bootstrap/examples/radio.php

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Radio</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="form-check"><input class="form-check-input" type="radio" name="flexRadioDefault" id="defaultRadio"><label class="form-check-label" for="defaultRadio">
    
        Item 1
      &lt;/label&gt;&lt;/div&gt;&lt;div class="form-check"&gt;&lt;input class="form-check-input" type="radio" name="flexRadioDefault" id="defaultCheckRadio" checked&gt;&lt;label class="form-check-label" for="defaultCheckRadio"&gt;
        Item 2
      &lt;/label&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Disabled Radio Button

    To indicate disabled state use disabled attribute and the associated <label>'s are styled with a lighter color.https://www.tutorialspoint.com/bootstrap/examples/radio_disabled.php

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap Form - Radio</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="form-check"><input class="form-check-input" type="radio" name="flexRadioDisabled" id="disabledRadio" disabled><label class="form-check-label" for="disabledRadio">
    
         Item 1
      &lt;/label&gt;&lt;/div&gt;&lt;div class="form-check"&gt;&lt;input class="form-check-input" type="radio" name="flexRadioDisabled" id="disabledCheckedRadio" checked disabled&gt;&lt;label class="form-check-label" for="disabledCheckedRadio"&gt;
        Item 2
      &lt;/label&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Switches

    • The switch has the custom checkbox markup, to render the toggle use .form-switch class. Use role="switch" to convey the type of control to assistive technologies.
    • The switches supports the disabled attribute. The older assistive technologies just announced it as a normal checkbox as a fallback.
    https://www.tutorialspoint.com/bootstrap/examples/radio_switches.php

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap Form - Radio</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="form-check form-switch"><input class="form-check-input" type="checkbox" role="switch" id="defaultSwitchCheckbox"><label class="form-check-label" for="defaultSwitchCheckbox">Wi-fi</label></div><div class="form-check form-switch"><input class="form-check-input" type="checkbox" role="switch" id="defaultSwitchCheckedCheckbox" checked><label class="form-check-label" for="defaultSwitchCheckedCheckbox">Bluetooth</label></div><div class="form-check form-switch"><input class="form-check-input" type="checkbox" role="switch" id="disabledSwitchCheckbox" disabled><label class="form-check-label" for="disabledSwitchCheckbox">Whatsapp Notification</label></div><div class="form-check form-switch"><input class="form-check-input" type="checkbox" role="switch" id="disabledSwitchCheckedCheckbox" checked disabled><label class="form-check-label" for="disabledSwitchCheckedCheckbox">Facebook Notification</label></div></body></html>

    Default checkbox and radios (stacked)

    The radios and checkboxes can be stacked vertically using the .form-check class.https://www.tutorialspoint.com/bootstrap/examples/radio_checkbox_default_stacked.php

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Checkbox and Radios</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="form-check"><input class="form-check-input" type="radio" name="Radios" id="defaultStackedRadio" value="option2"><label class="form-check-label" for="defaultStackedRadio">
    
       English
      &lt;/label&gt;&lt;/div&gt;&lt;div class="form-check"&gt;&lt;input class="form-check-input" type="radio" name="Radios" id="disabledStackedRadio" value="option3" disabled&gt;&lt;label class="form-check-label" for="disabledStackedRadio"&gt;
        Hindi
      &lt;/label&gt;&lt;/div&gt;&lt;div class="form-check"&gt;&lt;input class="form-check-input" type="checkbox" value="" id="defaultCheckbox"&gt;&lt;label class="form-check-label" for="defaultCheckbox"&gt;
      Marathi
    &lt;/div&gt;&lt;div class="form-check"&gt;&lt;input class="form-check-input" type="checkbox" value="" id="disabledCheckbox" disabled&gt;&lt;label class="form-check-label" for="disabledCheckbox"&gt;
       Japanes
      &lt;/label&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Inline

    To put checkboxes and radios next to each other, use the class .form-check-inline with any .form-check.https://www.tutorialspoint.com/bootstrap/examples/checkbox_radios_inline.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Checkbox and Radios</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="form-check form-check-inline"><input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineDeafultRadio" value="option1"><label class="form-check-label" for="inlineDeafultRadio">English</label></div><div class="form-check form-check-inline"><input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineDisabledRadio" value="option3" disabled><label class="form-check-label" for="inlineDisabledRadio">Hindi</label></div><div class="form-check form-check-inline"><input class="form-check-input" type="checkbox" id="inlineDeafultCheckbox" value="option1"><label class="form-check-label" for="inlineDeafultCheckbox">Marathi</label></div><div class="form-check form-check-inline"><input class="form-check-input" type="checkbox" id="inlineDisabledCheckbox" value="option3" disabled><label class="form-check-label" for="inlineDisabledCheckbox">Japanes</label></div></body></html>

    Reverse

    Place checkboxes, radios and switches on opposite sides using .form-check-reverse modifier class.https://www.tutorialspoint.com/bootstrap/examples/checkbox_radios_reverse.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Checkbox and Radios</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="form-check form-check-reverse"><h4>Inline Checkboxes</h4><input class="form-check-input" type="checkbox" value="" id="deafultReverseCheckbox"><label class="form-check-label" for="deafultReverseCheckbox">
    
       English
      &lt;/label&gt;&lt;/div&gt;&lt;div class="form-check form-check-reverse"&gt;&lt;input class="form-check-input" type="checkbox" value="" id="disabledReverseCheckbox" disabled&gt;&lt;label class="form-check-label" for="disabledReverseCheckbox"&gt;
       Hindi
      &lt;/label&gt;&lt;/div&gt;&lt;div class="form-check form-switch form-check-reverse"&gt;&lt;input class="form-check-input" type="checkbox" id="switchReverseCheckbox"&gt;&lt;label class="form-check-label" for="switchReverseCheckbox"&gt;Wifi&lt;/label&gt;&lt;/div&gt;&lt;div class="form-check form-check-reverse"&gt;&lt;h4&gt;Inline Radios&lt;/h4&gt;&lt;input class="form-check-input" type="radio" value="" id="deafultReverseRadio"&gt;&lt;label class="form-check-label" for="deafultReverseRadio"&gt;
       Marathi
      &lt;/label&gt;&lt;/div&gt;&lt;div class="form-check form-check-reverse"&gt;&lt;input class="form-check-input" type="radio" value="" id="disabledReverseRadio" disabled&gt;&lt;label class="form-check-label" for="disabledReverseRadio"&gt;
        Japanes
      &lt;/label&gt;&lt;/div&gt;&lt;div class="form-check form-switch form-check-reverse"&gt;&lt;input class="form-check-input" type="radio" id="switchReverseRadio"&gt;&lt;label class="form-check-label" for="switchReverseRadio"&gt;Bluetooth&lt;/label&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Without Labels

    • Skip the wrapping class .form-check for checkboxes and radio that have no label text.
    • Provide an accessible name for assistive technologies (for instance, using aria-label). For information, refer accessibility section of the Forms overview section.
    https://www.tutorialspoint.com/bootstrap/examples/checkbox_radio_without_labels.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap Form - Checkbox and Radio Buttons</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div><input class="form-check-input" type="checkbox" id="checkboxNoLabel" value="" aria-label="...">
    
      Item 1
    &lt;/div&gt;&lt;div&gt;&lt;input class="form-check-input" type="radio" name="radioNoLabel" id="radioNoLabel1" value="" aria-label="..."&gt;
      Item 2
    &lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Toggle Buttons

    • Use .btn class on the <label> element rather than .form-check-label to create button-like checkboxes and radio buttons. These toggle buttons may also be placed together in a button group.
    • Use .btn-check class which indicate that the input is of a button-type checkbox.

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Checkbox and Radios</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><h5>Checkbox Toggle Buttons</h5><input type="checkbox" class="btn-check" id="defaultToggleChecbox" autocomplete="off"><label class="btn btn-primary" for="defaultToggleChecbox">Item 1</label><input type="checkbox" class="btn-check" id="checkedToggleChecbox" checked autocomplete="off"><label class="btn btn-secondary" for="checkedToggleChecbox">Item 2</label><input type="checkbox" class="btn-check" id="disabledToggleChecbox" autocomplete="off" disabled><label class="btn btn-info" for="disabledToggleChecbox">Item 3</label><h5>Radios Toggle Buttons</h5><input type="radio" class="btn-check"  id="defaultToggleRadio" autocomplete="off"><label class="btn btn-primary" for="defaultToggleRadio">Item 1</label><input type="radio" class="btn-check" id="checkedToggleRadio" checked autocomplete="off"><label class="btn btn-secondary" for="checkedToggleRadio">Item 2</label><input type="radio" class="btn-check" id="disabledToggleRadio" autocomplete="off" disabled><label class="btn btn-info" for="disabledToggleRadio">Item 3</label></body></html>

    Outlined Styles

    Different variants of .btn are supported, including different outline styles as demonstrated in below example.https://www.tutorialspoint.com/bootstrap/examples/checkbox_radio_outlined_styles.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Checkbox and Radio Buttons</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><input type="checkbox" class="btn-check" id="defualtOutlineCheckbox" autocomplete="off"><label class="btn btn-outline-primary" for="defualtOutlineCheckbox">Single toggle</label><br><br><input type="checkbox " class="btn-check" id="checkedOutlineCheckbox" checked autocomplete="off"><label class="btn btn-secondary" for="checkedOutlineCheckbox">Checked</label><br><br><input type="radio" class="btn-check" name="options-outlined" id="checkedOutlineRadio" autocomplete="off" checked><label class="btn btn-info" for="checkedOutlineRadio">Checked success radio</label><input type="radio" class="btn-check" name="options-outlined" id="defualtOutlineRadio" autocomplete="off"><label class="btn btn-outline-warning" for="defualtOutlineRadio">Danger radio</label></body></html>

  • Form Select

    This chapter will discuss about Bootstrap form select menu. Custom CSS can be used to alter the default appearance of the native <select> elements.

    Default

    • Custom class .form-select is required for custom <select> menus, to trigger the custom styles.
    • Due to browser restrictions, custom styles are only able to change the <select>‘s default appearance and cannot change the <options>s.

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Select Menu</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><select class="form-select" aria-label="Default select example"><option selected>Select Menu</option><option value="1">Item 1</option><option value="2">Item 2</option><option value="3">Item 3</option></select></body></html>

    Sizing

    In order to match the similar sized text inputs, you may also select from small and large custom selects.https://www.tutorialspoint.com/bootstrap/examples/select_menu_sizing.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Select Menu</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><select class="form-select form-select-lg mb-3" aria-label=".form-select-lg example"><option selected>Large Sized Select Menu</option><option value="1">Item 1</option><option value="2">Item 2</option><option value="3">Item 3</option></select><select class="form-select form-select-sm" aria-label=".form-select-sm example"><option selected>Small Sized Select Menu</option><option value="1">Item 1</option><option value="2">Item 2</option><option value="3">Item 3</option></select></body></html>

    You can give multiple options in drop-down list using multiple attribute.https://www.tutorialspoint.com/bootstrap/examples/select_menu_sizing_multiple_attributes.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Select Menu</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><select class="form-select" multiple aria-label="multiple select example"><option selected>Select Menu</option><option value="1">Item 1</option><option value="2">Item 2</option><option value="3">Item 3</option></select></body></html>

    size attribute restricts the number of options in a drop-down list.https://www.tutorialspoint.com/bootstrap/examples/select_menu_sizing_size_attributes.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Select Menu</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><select class="form-select" size="4" aria-label="size 3 select example"><option selected>Select Menu</option><option value="1">Item 1</option><option value="2">Item 2</option><option value="3">Item 3</option><option value="3">Item 4</option></select></html>

    Disabled

    In order to make a select appear greyed out and eliminate pointer events, add the disabled boolean attribute to it.https://www.tutorialspoint.com/bootstrap/examples/select_menu_disabled.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap Form - Select Menu</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><select class="form-select" aria-label="Disabled select example" disabled><option selected>Select Menu</option><option value="1">Item 1</option><option value="2">Item 2</option><option value="3">Item 3</option></select></html>

    Print Page

  • Form Controls

    This chapter will discuss about Bootstrap form controls. Custom styles, size, focus states, and other features can be used to upgrade textual form controls like <input> and <textarea>.

    Basic example

    Use the classes .form-control and .form-label to style the form controls.https://www.tutorialspoint.com/bootstrap/examples/formlayout_basic_example.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Form Control</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="mb-3"><label for="formControlName" class="form-label">Full Name</label><input type="text" class="form-control" id="formControlName" placeholder="name"></div><div class="mb-3"><label for="formControlEmail" class="form-label">Email id</label><input type="text" class="form-control" id="formControlEmail" placeholder="[email protected]"></div><div class="mb-3"><label for="formControlTextarea" class="form-label">Add a comment</label><textarea class="form-control" id="formControlTextarea" rows="3"></textarea></div><button type="submit" class="btn btn-success">Submit</button></body></html>

    Sizing

    Use classes like .form-control-lg and .form-control-sm to specify the size for the form input field.https://www.tutorialspoint.com/bootstrap/examples/formlayout_sizing.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Form Control</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><input class="form-control  form-control-lg mt-2" type="text" placeholder="Large size input box" aria-label=".form-control-lg example"><input class="form-control  mt-2" type="text" placeholder="Default size input box" aria-label="default input example"><input class="form-control  form-control-sm  mt-2" type="text" placeholder="Small size input box" aria-label=".form-control-sm example"></body></html>

    Form text

    • Use .form-text to create block-level or inline-level form text .
    • A top margin is added to easily space the inputs above a block-level element.

    Associate form text with form controls using aria-labelledby or aria-describedby attributes to ensure it is announced by assistive technologies such as screen readers.

    https://www.tutorialspoint.com/bootstrap/examples/formlayout_form_text.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Form Control</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><label for="inputUsername" class="form-label mt-2">Username</label><input type="text" id="inputUsername" class="form-control" aria-labelledby="UsernameHelpBlock"><div id="UsernameHelpBlock" class="form-text">
    
      Your username 620 characters long and can be any combination of letters, numbers or symbols.
    &lt;/div&gt;&lt;label for="inputPassword" class="form-label mt-2"&gt;Password&lt;/label&gt;&lt;input type="text" id="inputPassword" class="form-control" aria-labelledby="PasswordHelpBlock"&gt;&lt;div id="PasswordHelpBlock" class="form-text"&gt;
      must be 6-20 characters long.
    &lt;/div&gt;&lt;button type="submit" class="btn btn-primary mt-2"&gt;Submit&lt;/button&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Inline text can use any typical inline HTML element (such as, <span><small>...etc) with only .form-text class.https://www.tutorialspoint.com/bootstrap/examples/formlayout_form_text_inline.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Form Control</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="row g-3 align-items-center mt-2"><div class="col-auto"><label for="inputUsername" class="col-form-label">Username</label></div><div class="col-auto"><input type="text" id="inputUsername" class="form-control" aria-labelledby="usernameHelpInline"></div><div class="col-auto"><span id="usernameHelpInline" class="form-text">
    
          Username 620 characters long.
        &lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Disabled

    For a grayed-out appearance and to remove pointer events use the disabled attribute to an input.https://www.tutorialspoint.com/bootstrap/examples/formlayout_disabled.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Form Control</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><input class="form-control mt-2" type="text" placeholder="Disable Input Field" aria-label="Disabled input example" disabled></body></html>

    Readonly

    Use the readonly attribute to prevent changes to an input's value.https://www.tutorialspoint.com/bootstrap/examples/formlayout_readonly.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Form Control</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><input class="form-control mt-2" type="text" value="Tutorialspoint" aria-label="readonly example" readonly></body></html>

    Readonly plain text

    .form-control-plaintext creates a readonly input field as a plaintext. This removes styling and preserves the proper margin and padding.https://www.tutorialspoint.com/bootstrap/examples/formlayout_readonly_plaintext.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Form Control</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="mb-3 row"><label for="name" class="col-sm-2 col-form-label">Name</label><div class="col-sm-3"><input type="text" readonly class="form-control-plaintext" id="name" value="Tutorialspoint"></div></div><div class="mb-3 row"><label for="bootstrap" class="col-sm-2 col-form-label">Language</label><div class="col-sm-3"><input type="text" class="form-control" id="bootstrap" placeholder="Bootstrap"></div></div></body></html>

    In readonly plaintext inline, you can make form labels and inputs will appear inline and horizontally.https://www.tutorialspoint.com/bootstrap/examples/formlayout_readonly_plaintext_inline.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Form Control</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><form class="row g-2 mt-2"><div class="col-auto"><input type="text" readonly class="form-control-plaintext" id="staticName" value="Tutorialspoint"></div><div class="col-auto"><input type="text" class="form-control" id="inputLanguage" placeholder="Bootstrap"></div></form></body></html>

    File input

    File input is used to browse the file as an input on your computer.

    File input using sizes

    • Use .form-control-sm to make the size of file input smaller.
    • Use .form-control-lg to make the size of file input bigger.
    https://www.tutorialspoint.com/bootstrap/examples/formlayout_file_input_sizes.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Form Control</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="mb-3"><label for="fileInputsm" class="form-label">Small size file input</label><input class="form-control form-control-sm" id="fileInputsm" type="file"></div><div><label for="fileInputlg" class="form-label">Large size file input</label><input class="form-control form-control-lg" id="fileInputlg" type="file"></div></body></html>

    File input using attribute

    • There is no need to explicitly define the default attribute.
    • Use disabled attribute which give grayed-out appearance and remove pointer events.
    • Multiple files can be accepted for input at once with multiple attribute.
    https://www.tutorialspoint.com/bootstrap/examples/formlayout_file_input_attribute.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Form Control</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="mb-3"><label for="defaultFileInput" class="form-label">Default file input</label><input class="form-control" type="file" id="defaultFileInput"></div><div class="mb-3"><label for="disabledFileInput" class="form-label">Disabled file input</label><input class="form-control" type="file" id="disabledFileInput" disabled></div><div class="mb-3"><label for="multipleFileInput" class="form-label">Multiple files input</label><input class="form-control" type="file" id="multipleFileInput" multiple></div></body></html>

    Color

    Use .form-control-color class and type="color" attribute in the <input> element to add color to the input field.https://www.tutorialspoint.com/bootstrap/examples/formlayout_color.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Form Control</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><label for="colorInput" class="form-label">Select a color</label><input type="color" class="form-control form-control-color" id="colorInput" value="#228b22"></body></html>

    Datalists

    You can create a group of <option>'s that can be accessed from a <input> by using datalists. Browsers and operating systems provide limited and inconsistent styling for <datalist> elements.https://www.tutorialspoint.com/bootstrap/examples/formlayout_datalist.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Form Control</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><label for="dataList" class="form-label">Languages</label><input class="form-control" list="datalistOptions" id="dataList" placeholder="Search languages..."><datalist id="datalistOptions"><option value="Bootstrap"><option value="HTML"><option value="CSS"></datalist></body></html>