<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bootstrap 5.3 Form Layouts Example</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<h2>Bootstrap 5.3 Form Layouts Example</h2>
<h3>Vertical Form</h3>
<form>
<div class="mb-3">
<label for="name" class="form-label">Name</label>
<input type="text" class="form-control" id="name">
</div>
<div class="mb-3">
<label for="email" class="form-label">Email</label>
<input type="email" class="form-control" id="email">
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
<h3>Horizontal Form</h3>
<form>
<div class="mb-3 row">
<label for="name" class="col-sm-2 col-form-label">Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="name">
</div>
</div>
<div class="mb-3 row">
<label for="email" class="col-sm-2 col-form-label">Email</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="email">
</div>
</div>
<div class="mb-3 row">
<label for="password" class="col-sm-2 col-form-label">Password</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="password">
</div>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
<h3>Inline Form</h3>
<form class="form-inline">
<div class="mb-3">
<label for="name" class="visually-hidden">Name</label>
<input type="text" class="form-control mb-2 me-2" id="name" placeholder="Name">
</div>
<div class="mb-3">
<label for="email" class="visually-hidden">Email</label>
<input type="email" class="form-control mb-2 me-2" id="email" placeholder="Email">
</div>
<div class="mb-3">
<label for="password" class="visually-hidden">Password</label>
<input type="password" class="form-control mb-2 me-2" id="password" placeholder="Password">
</div>
<button type="submit" class="btn btn-primary mb-2">Submit</button>
</form>
<h3>Multi-column Form</h3>
<form>
<div class="row">
<div class="col-sm-6 mb-3">
<label for="firstName" class="form-label">First Name</label>
<input type="text" class="form-control" id="firstName">
</div>
<div class="col-sm-6 mb-3">
<label for="lastName" class="form-label">Last Name</label>
<input type="text" class="form-control" id="lastName">
</div>
</div>
<div class="row">
<div class="col-sm-6 mb-3">
<label for="email" class="form-label">Email</label>
<input type="email" class="form-control" id="email">
</div>
<div class="col-sm-6 mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password">
</div>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</body>
</html>
Code Output
Bootstrap 5.3 Form Layouts Example
Vertical Form
Horizontal Form
Inline Form
Multi-column Form
Form Layouts
You can create various form layouts to suit your design requirements. Bootstrap provides flexible and responsive classes to help you structure and align form elements.
-
-
Vertical Form: This is the default form layout in Bootstrap. Each form element is stacked vertically, one below the other. To create a vertical form, use the
.row
class to group form controls in a row, and use column classes like.col-12
to specify the width of form elements. -
Horizontal Form: In a horizontal form, form elements, and labels are placed side by side, providing a more compact layout. To create a horizontal form, add the
.row
class to the form and use the.col-auto
class for labels and.col
class for form controls. -
Inline Form: An inline form displays form controls and labels in a single line, making it suitable for small forms or form inputs that require quick interaction. To create an inline form, add the
.form-inline
class to the form element, and use the.form-control
class for input elements. -
Multi-column Form: If you have a form with a large number of form elements, you can organize them into multiple columns to enhance readability. Use the Bootstrap grid system and column classes like
.col
to create a multi-column form layout.
-