The stacked, or vertical, form is Bootstrap’s default layout: each label sits above its input, and every field takes the full width of its container. It is the easiest layout to read on a phone and the right default for a login form.
Page setup
Load the stylesheet from jsDelivr. The form itself needs no JavaScript, but the bundle is required if you add Bootstrap’s client-side validation or other interactive components:
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
The form
<main class="container py-5">
<div class="row justify-content-center">
<div class="col-sm-8 col-md-6 col-lg-4">
<h1 class="h3 mb-4">Log in</h1>
<form action="/account/login" method="post">
<div class="mb-3">
<label for="loginEmail" class="form-label">Email</label>
<input type="email" class="form-control" id="loginEmail" name="email"
autocomplete="username" required>
</div>
<div class="mb-3">
<label for="loginPassword" class="form-label">Password</label>
<input type="password" class="form-control" id="loginPassword" name="password"
autocomplete="current-password" required>
</div>
<div class="mb-3 form-check">
<input type="checkbox" class="form-check-input" id="rememberMe" name="rememberMe" value="true">
<label class="form-check-label" for="rememberMe">Remember me</label>
</div>
<button type="submit" class="btn btn-primary w-100">Log in</button>
</form>
</div>
</div>
</main>
The grid wrapper keeps the form narrow and centered on large screens, and lets it use the full width on a phone.
What changed from Bootstrap 3
.form-groupwas removed in Bootstrap 5. Use a margin utility such as.mb-3on the wrapper instead.- Labels get
.form-label, which adds the small gap below them. - The checkbox markup changed:
<div class="checkbox"><label><input ...></label></div>became.form-checkwith.form-check-inputand a separate.form-check-labellinked byfor. - Full-width buttons used
.btn-block, which was removed in Bootstrap 5..w-100on the button does the same.
Details that matter on a login form
Labels, not placeholders. The old example used both a label and a placeholder with the same text, which adds nothing. A placeholder alone is worse: it disappears as soon as the user types, and its light gray text often fails contrast requirements. Keep the visible label.
autocomplete attributes. autocomplete="username" on the email field and autocomplete="current-password" on the password field tell browsers and password managers exactly what to fill in. Use username even when the identifier is an email address; that is the token password managers look for. On a registration or change-password form, the new password field gets new-password instead.
name attributes. Without them the browser submits nothing. The 2014 version of this form had none, so it could not have worked as a real login.
method="post". A form without a method uses GET and puts the password in the URL, where it ends up in server logs and browser history. Always post login forms, and only over HTTPS.
The checkbox value. An unchecked checkbox is not sent at all; a checked one sends on unless you set a value. value="true" lets ASP.NET Core bind it straight to a bool RememberMe property.
Floating labels
Bootstrap 5 added floating labels, where the label sits inside the input and moves up when the field has a value. They save vertical space and are popular on login pages:
<div class="form-floating mb-3">
<input type="email" class="form-control" id="floatingEmail" name="email"
placeholder="name@example.com" autocomplete="username" required>
<label for="floatingEmail">Email</label>
</div>
<div class="form-floating mb-3">
<input type="password" class="form-control" id="floatingPassword" name="password"
placeholder="Password" autocomplete="current-password" required>
<label for="floatingPassword">Password</label>
</div>
Two rules: the <label> must come after the <input>, and the input must have a placeholder. Bootstrap uses the :placeholder-shown selector to decide where the label goes, so the placeholder text itself is never shown.
Using it in ASP.NET Core
In a Razor Page or MVC view, use the tag helpers instead of hard-coded attributes: <input asp-for="Email" class="form-control"> generates the id, name, type and validation attributes from your model, and <label asp-for="Email" class="form-label"> links the label. A <form method="post"> rendered by the form tag helper also includes the antiforgery token automatically.
For showing validation errors with Bootstrap’s .is-invalid and .invalid-feedback classes, see the form validation example below.
Related examples
- Bootstrap horizontal login form
- Bootstrap form validation states
- Bootstrap input samples
- Forms overview in the Bootstrap documentation