Open In App

How to set the button alignment in Bootstrap ?

Bootstrap buttons are no different from any other DOM elements of an HTML document. Aligning them is more likely the same as aligning paragraphs, divs and sections. Here are some of the scenarios that one can encounter.

Syntax:

class="text-left"|"text-center"|"text-right"

Note: You can also use HTML5 <center> tag to align buttons to the center.



Example:




<!DOCTYPE html>
<html>
  
<head>
    <meta charset="utf-8">
    <meta name="viewport" 
    content="width=device-width, initial-scale=1, shrink-to-fit=no">
  
    <link rel="stylesheet"
  
    <title>Aligning Buttons</title>
</head>
  
<body>
    <h1 style="color:green;text-align:center;">GeeksforGeeks</h1>
    <div class="container">
        <div class="text-left">
            <button type="button" >Button 1</button>
            <button type="button" >Button 2</button>
        </div>
  
        <div class="text-center">
            <button type="button" >Button 1</button>
            <button type="button" >Button 2</button>
        </div>
  
        <div class="text-right">
            <button type="button" >Button 1</button>
            <button type="button" >Button 2</button>
        </div>
  
        <center>
            <button type="button" >Button 1</button>
            <button type="button" >Button 2</button>
        </center>
    </div>
  
    </script>
    <script src=
    </script>
</body>
  
</html>

Output:

The following pattern can be achieved by choosing either one of them.
Example:




<!DOCTYPE html>
<html>
  
<head>
    <meta charset="utf-8">
    <meta name="viewport" 
     content="width=device-width, initial-scale=1, shrink-to-fit=no">
  
    <link rel="stylesheet" 
  
    <title>Aligning Buttons</title>
  
    <style type="text/css">
        html,
        body {
            height: 200px;
        }
    </style>
</head>
  
<body>
    <h1 style="color:green;text-align:center;">GeeksforGeeks</h1>
    <div class="container h-100">
        <div class="d-flex h-100">
            <div class="align-self-start mr-auto">
                <button type="button" class="btn btn-danger">
                  Click Me!
                </button>
            </div>
            <div class="align-self-center mx-auto">
                <button type="button" class="btn btn-primary">
                  Click Me!
                </button>
            </div>
            <div class="align-self-end ml-auto">
                <button type="button" class="btn btn-success">
                  Click Me!
                </button>
            </div>
        </div>
    </div>
  
    </script>
    <script src=
    </script>
</body>
  
</html>

Output:

Article Tags :