#1 India's Top IT Training Institute
×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
Mentors

Mentors

Meet the industry experts who train and guide you through your course.

Read More →
Free Resources

Free Resources

Free tutorials, interview questions, tools and calculators to help you learn.

Explore →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
Bootstrap Fundamentals

Forms

Bootstrap 5 gives HTML forms a clean, consistent look with a handful of classes. Inputs become full-width, labels get proper spacing, and you can build grids, inline layouts, floating labels and validation feedback without writing custom CSS. You use it whenever you want a form that looks good on phones and desktops with minimal effort.

The core classes

  • form-label on a label gives consistent spacing above the field.
  • form-control on text inputs, email inputs, passwords and textareas makes them full-width with a border, padding and focus ring.
  • form-select styles a select dropdown. Bootstrap 5 replaced the older custom-select classes with this one.
  • form-check, form-check-input and form-check-label work together for checkboxes and radio buttons.
  • form-text styles small helper text under a field.
  • mb-3 is a spacing utility used on a wrapper div to separate fields.

Bootstrap 4 had a form-group class for that wrapper. It no longer exists in version 5, so use margin utilities instead.

A complete sign-up form

<form class="row g-3">
  <div class="col-md-6">
    <label for="firstName" class="form-label">First name</label>
    <input type="text" class="form-control" id="firstName">
  </div>
  <div class="col-md-6">
    <label for="email" class="form-label">Email</label>
    <input type="email" class="form-control" id="email" aria-describedby="emailHelp">
    <div id="emailHelp" class="form-text">We only use this to contact you.</div>
  </div>
  <div class="col-12">
    <label for="city" class="form-label">City</label>
    <select id="city" class="form-select">
      <option selected>Choose...</option>
      <option>Delhi</option>
      <option>Pune</option>
    </select>
  </div>
  <div class="col-12 form-check">
    <input class="form-check-input" type="checkbox" id="terms">
    <label class="form-check-label" for="terms">I accept the terms</label>
  </div>
  <div class="col-12">
    <button type="submit" class="btn btn-primary">Create account</button>
  </div>
</form>

Adding row g-3 to the form turns it into a grid with even gutters. The col-md-6 fields sit side by side on medium screens and stack on phones.

Sizes, floating labels and input groups

Add form-control-lg or form-control-sm to change the height of a field. For a modern look, wrap an input and its label in div class="form-floating", placing the input first and the label second; the label then sits inside the field and shrinks upward when you type. Floating labels need a placeholder attribute on the input to work, even though the placeholder text itself is hidden.

An input-group attaches text or buttons to the side of a field, such as a "+91" prefix before a phone number or a "Search" button after a search box.

Showing validation states

Bootstrap can colour fields green or red. Add is-valid or is-invalid to the input and place a div class="invalid-feedback" right after it with the message. To use the browser's built-in checks instead, add novalidate and the needs-validation class to the form, then add was-validated with a few lines of JavaScript when the user submits.

Mistakes that break the layout

The feedback message only shows if it is a sibling that comes after the input with the invalid state. If you wrap the input in an extra div, the message stays hidden. Another frequent slip is forgetting the for attribute on labels; clicking the label then does not focus the field, and screen readers cannot connect the two. For checkboxes this also means clicking the text does nothing, which annoys mobile users.

Inline and horizontal layouts

For a compact search bar or newsletter box, put fields in a row with col-auto columns so each takes only the width it needs. For a horizontal form, where labels sit to the left of fields on wider screens, give each label col-sm-3 col-form-label and wrap the input in a col-sm-9 column inside a row. On phones the columns stack again automatically.

Takeaway: use form-control and form-select for fields, form-check for options, grid rows for layout, and keep feedback elements directly after their inputs.

Ready to master real-world web development?

Learn HTML, CSS3, Bootstrap and JavaScript hands-on with mentor-led sessions.

Explore Course