Bootstrap 5 Layout Horizontal form label sizing
Last Updated :
18 Nov, 2022
Improve
Bootstrap 5 Layout Horizontal form label sizing is used to set the label of the form input field in different sizes. To set the label size, use the .col-form-label-sm or .col-form-label-lg class to <label> or <legend> tag with the size of .form-control-lg and .form-control-sm.
Horizontal form label sizing used Classes:
- .col-form-label-sm: This class is used to set the size of the form label to small.
- .col-form-label-lg: This class is used to set the size of the form label to large.
- .form-control-sm: This class is used to set the size of the form control to small.
- .form-control-lg: This class is used to set the size of the form control to large.
Syntax:
<div class="row"> <label for="" class="col-form-label col-form-label-sm"></label> <div class="col-*-*"> <input type="email" class="form-control form-control-sm" id="" placeholder=""> </div> </div>
Example 1: In this example, we will create horizontal form labels in different sizes.
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap5 Layout Horizontal form label sizing</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous">
</script>
</head>
<body>
<div class="container text-center">
<h1 class="text-success">
GeeksforGeeks
</h1>
<h2>Bootstrap5 Layout Horizontal form label sizing</h2>
<div class="row">
<label for="username" class="col-sm-2
col-form-label col-form-label-sm">Email</label>
<div class="col-sm">
<input type="text"
class="form-control form-control-sm"
id="username"
placeholder="Username/Email"
aria-label="Username/Email">
</div>
</div>
<br>
<div class="row">
<label for="password" class="col-sm-2
col-form-label col-form-label-lg">Password</label>
<div class="col-lg">
<input type="password"
class="form-control form-control-lg"
id="password"
placeholder="Password"
aria-label="Password">
</div>
</div>
</div>
</body>
</html>
Output:

Example 2: In this example, we will create horizontal form labels in different sizes.
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap5 Layout Horizontal form label sizing</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous">
</script>
</head>
<body>
<div class="container text-center">
<h1 class="text-success">
GeeksforGeeks
</h1>
<h2>Bootstrap5 Layout Horizontal form label sizing</h2>
<div class="row">
<label for="fname" class="col-sm-2
col-form-label col-form-label-sm">First Name</label>
<div class="col-sm">
<input type="text" class="form-control form-control-sm"
id="fname"
placeholder="First Name">
</div>
</div>
<div class="row mt-4">
<label for="lname" class="col-sm-2
col-form-label col-form-label-sm">Last Name</label>
<div class="col-sm">
<input type="text" class="form-control form-control-sm"
id="lname"
placeholder="Last Name">
</div>
</div>
<div class="row mt-4">
<label for="email" class="col-sm-2
col-form-label col-form-label">Email Id</label>
<div class="col-sm">
<input type="email" class="form-control form-control"
id="email"
placeholder="Last Name">
</div>
</div>
<div class="row mt-4">
<label for="mobile" class="col-sm-2
col-form-label col-form-label-lg">Mobile No</label>
<div class="col-sm">
<input type="tel" class="form-control form-control-lg"
id="mobile"
placeholder="Last Name">
</div>
</div>
</div>
</body>
</html>
Output:

Reference: https://getbootstrap.com/docs/5.0/forms/layout/#horizontal-form-label-sizing