I'm trying to update my app from Bootstrap 4 to Bootstrap 5, but all the elements that were using form classes such as form-group
, form-row
, form-inline
are completely broken.
The reason is form-group
, form-row
, and form-inline
classes have been removed in Bootstrap 5:
Breaking change: Dropped form-specific layout classes for our grid system. Use our grid and utilities instead of .form-group, .form-row, or .form-inline.
https://getbootstrap.com/docs/5.0/migration/#forms
So Grid and Utilities are supposed to be used instead.
...but if you are looking for a quick solution, here's how these classes were working in Bootstrap 4:
.form-group {
margin-bottom: 1rem;
}
.form-inline .form-control {
display: inline-block;
width: auto;
vertical-align: middle;
}
.form-row {
display: flex;
flex-wrap: wrap;
margin-right: -5px;
margin-left: -5px;
}
.form-row > .col {
padding-left: 5px;
padding-right: 5px;
}
label {
margin-bottom: 0.5rem;
}
.inline-form
to Bootstrap 5+inline-form
class with flexbox helper classes: d-flex flex-row align-items-center flex-wrap
.mr-*
class to space your form elements, replace these with the equivalent me-*
classes ("margin end"). E.x. mr-2
becomes me-2
. Similarly, ml-*
becomes ms-*
("margin start").custom-select
in v4 becomes form-select
in v5.Compare the Bootstrap 4 inline form below with the exact equivalent form in Bootstrap 5.
This is Bootstrap 4 code.
<form class="form-inline">
<label class="my-1 mr-2" for="inlineFormCustomSelectPref">Preference</label>
<select class="custom-select my-1 mr-sm-2" id="inlineFormCustomSelectPref">
<option selected>Choose...</option>
</select>
<div class="custom-control custom-checkbox my-1 mr-sm-2">
<input type="checkbox" class="custom-control-input" id="customControlInline">
<label class="custom-control-label" for="customControlInline">Remember my preference</label>
</div>
<button type="submit" class="btn btn-primary my-1">Submit</button>
</form>
<form class="d-flex flex-row align-items-center flex-wrap">
<label class="my-1 me-2" for="inlineFormCustomSelectPref">Preference</label>
<select class="form-select my-1 me-sm-2 w-auto" id="inlineFormCustomSelectPref">
<option selected>Choose...</option>
</select>
<div class="form-check my-1 me-sm-2">
<input type="checkbox" class="form-check-input" id="customControlInline" />
<label class="form-check-label" for="customControlInline">Remember my preference</label>
</div>
<button type="submit" class="btn btn-primary my-1">Submit</button>
</form>
form-group
, form-row
and form-inline
classes in Bootstrap 5As others have mentioned, the classes form-group
, form-row
and form-inline
are removed in Bootstrap 5. Here's how they can be replaced:
form-group
can be replaced with mb-3
, since it previously applied the property margin-bottom: 1rem
which the mb-3
class will do by default as well.form-row
can be replaced with row
in most instances.form-inline
can be recreated by applying the following classes: d-flex flex-row align-items-center flex-wrap
.Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With