Performance: Form layout (inline, horizontal)
This affects how quickly the form content appears and how smoothly the browser renders form elements on different screen sizes.
<form class="row g-3 align-items-center"> <div class="col-auto"> <label for="name" class="col-form-label">Name</label> </div> <div class="col-auto"> <input type="text" id="name" class="form-control"> </div> <div class="col-auto"> <label for="email" class="col-form-label">Email</label> </div> <div class="col-auto"> <input type="email" id="email" class="form-control"> </div> </form>
<form> <label>Name</label> <input type="text"> <label>Email</label> <input type="email"> </form>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Vertical stacked form (no grid) | Low (few nodes) | Multiple on resize | High due to vertical stacking | [X] Bad |
| Bootstrap horizontal form (grid + inline) | Moderate (grid divs) | Single on resize | Low due to efficient layout | [OK] Good |
inline form layout in Bootstrap?.form-horizontal to align labels and inputs side by side..form-inline is for inline forms; .form-control styles inputs; .form-row is for grid rows..form-horizontal -> Option A<form class="form-inline"> <label for="email" class="mr-2">Email</label> <input type="email" class="form-control mr-2" id="email" placeholder="Enter email"> <button type="submit" class="btn btn-primary">Submit</button> </form>
form-inline, which arranges controls horizontally.<form class="form-horizontal"> <label class="col-sm-2 control-label" for="name">Name</label> <input type="text" class="form-control col-sm-10" id="name" placeholder="Name"> </form>
col-md-3 and col-md-9 applies columns on medium screens and larger, stacking on smaller.form-horizontalcol-md-3 on labels and col-md-9 wrapped in div on inputs inside a form-horizontal -> Option APass the test and this pattern moves unknown