Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to align the label and the input at the same line in Bootstrap 5?

Tags:

bootstrap-5

I would like to know if it is possible to position the label and the input on the same line, please. I don't know how to do this in Bootstrap 5.

Thank you in advance for your help.

<!DOCTYPE html>
<html>
  <head>
    <title>HTML CSS JS</title>
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
  </head>
  <body>
    <div class="container pt-5">
      <form (ngSubmit)="login()">
        <div class="mb-3">
          <label for="exampleInputEmail1" class="form-label">User</label>
          <input type="text" class="form-control" name="exampleInputEmail1" style="width: 40%" aria-describedby="emailHelp" [(ngModel)]="loginForm.user" required maxlength="4">
          <div id="emailHelp" class="form-text">We'll never share your email with anyone else.</div>
        </div>
        <div class="mb-3">
          <label for="exampleInputPassword1" class="form-label">Password</label>
          <input type="password" class="form-control" name="exampleInputPassword1" style="width: 40%" [(ngModel)]="loginForm.password" required maxlength="4">
        </div>
        <button type="submit" class="btn btn-primary">Connection</button>
      </form>
    </div>
  </body>
</html>

1 Answers

<!DOCTYPE html>
<html>
  <head>
    <title>HTML CSS JS</title>
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
  </head>
  <body>
    <div class="container pt-5">
      <form (ngSubmit)="login()">
      <div class="mb-3">
      <div class="d-inline-flex align-items-center">
          <label for="exampleInputEmail1" class="form-label" style="min-width: 100px !important">User</label>
          <input type="text" class="form-control" name="exampleInputEmail1" style="width: 40%" aria-describedby="emailHelp" [(ngModel)]="loginForm.user" required maxlength="4">
          
        </div>
        <div id="emailHelp" class="form-text">We'll never share your email with anyone else.</div>
      </div>
        
        
        <div class="mb-3">     
        <div class="d-inline-flex align-items-center">
          <label for="exampleInputPassword1" class="form-label" style="min-width: 100px !important">Password</label>
          <input type="password" class="form-control" name="exampleInputPassword1" style="width: 40%" [(ngModel)]="loginForm.password" required maxlength="4">
        </div>
        </div>
        
        <button type="submit" class="btn btn-primary">Connection</button>
      </form>
    </div>
  </body>
</html>
like image 114
Rushit Vaishnani Avatar answered Sep 07 '25 23:09

Rushit Vaishnani