Open In App

How to create a vertical or basic form using Bootstrap ?

Forms are used on almost every website that you visit. It is generally used to collect data from the users. It consists of various interactive controls that enable users to input the data. These controls are wrapped in the <form> tag and also can be designed or styled according to the need by setting different attributes of the controls, to different values.

Some of the major form controls are:



They can be integrated into the forms as per the requirements.

Bootstrap provides the following 3 types of form layouts :



  1. Vertical Forms (Default)
  2. Horizontal Forms
  3. Inline Forms

In this article, we will be learning to create the basic vertical forms.

How to create vertical or basic form in bootstrap?

<script src=”https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js”></script>
<script src=”https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js”></script>

<link rel=”stylesheet” href=”https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css”>

<form>
    <div class="form-group">
        <label>User Name</label>
        <input class="form-control" 
            type="text" 
            placeholder="Enter your User Name">
    </div>

    <div class="form-group">
        <label>Password</label>
        <input class="form-control" 
            type="password" 
            placeholder="Enter your password">
    </div>
</form>

Here,

Example 1: In this example, we are creating vertical forms using Bootstrap.




<!DOCTYPE html>
<html>
<head>
    <title>Vertical forms Example</title>
    <link rel="stylesheet"
          href=
    <script src=
    </script>
    <script src=
    </script>
</head>
 
<body>
    <div class="container" style="color:green">
        <h1>GeeksforGeeks</h1>
    </div>
    <div class="container">
        <h4>Vertical Form -> Example:1</h4>
        <form>
            <div class="form-group">
                <label>User Name</label>
                <input class="form-control" type="text"
                       placeholder="Enter your User Name">
            </div>
            <div class="form-group">
                <label>Password</label>
                <input class="form-control" type="password"
                       placeholder="Enter your password">
            </div>
            <div class="container">
                <button type="button" class="btn btn-success">
                    Login
                </button>
                <button type="button" class="btn btn-secondary">
                    Register
                </button>
            </div>
        </form>
    </div>
</body>
</html>

Output:

As you can see in the output, a basic form is created, having interactive form controls i.e. two labels, one text field, and one password field to enter the data i.e. name and password, and 2 buttons i.e. login and register.

Example 2: In this example, we have created more options in the vertical form.




<!DOCTYPE html>
<html>
<head>
    <title>Vertical forms Example</title>
    <link rel="stylesheet"
          href=
    <script src=
    </script>
    <script src=
    </script>
</head>
 
<body>
    <div class="container" style="color:green">
        <h1>GeeksforGeeks</h1>
    </div>
    <div class="container">
        <h4>Vertical Form -> Example:2</h4>
        <form>
            <div class="form-group">
                <label>Name</label>
                <input class="form-control" type="text"
                       placeholder="Enter your Name">
            </div>
 
            <div class="form-group">
                <label>Gender</label>
                <div class="form-check">
                    <input class="form-check-input" type="radio"
                           name="exampleRadios" id="exampleRadios1"
                           value="option1" checked>
                    <label class="form-check-label" for="exampleRadios1">
                        Male
                    </label>
                </div>
 
                <div class="form-check">
                    <input class="form-check-input" type="radio"
                           name="exampleRadios" id="exampleRadios1"
                           value="option1" checked>
                    <label class="form-check-label" for="exampleRadios1">
                        Female
                    </label>
                </div>
                <div class="form-check">
                    <input class="form-check-input" type="radio"
                           name="exampleRadios" id="exampleRadios1"
                           value="option1" checked>
                    <label class="form-check-label" for="exampleRadios1">
                        Others
                    </label>
                </div>
            </div>
            <div class="form-group">
                <label>Skills</label>
                <div class="form-check">
                    <input class="form-check-input" type="checkbox"
                           value="" id="defaultCheck1">
                    <label class="form-check-label" for="defaultCheck1">
                        Web Development
                    </label>
                </div>
                <div class="form-check">
                    <input class="form-check-input" type="checkbox"
                           value="" id="defaultCheck1">
                    <label class="form-check-label" for="defaultCheck1">
                        Android Development
                    </label>
                </div>
                <div class="form-check">
                    <input class="form-check-input" type="checkbox"
                           value="" id="defaultCheck1">
                    <label class="form-check-label" for="defaultCheck1">
                        DSA
                    </label>
                </div>
            </div>
            <div class="container">
                <button type="button" class="btn btn-success">
                    Submit
                </button>
                <button type="button" class="btn btn-secondary">
                    Clear
                </button>
            </div>
        </form>
    </div>
</body>
</html>

Output:

In this output form, radio buttons are included, enabling or forcing the user to choose only one gender option from the  list and Checkboxes are also introduced, enabling the user to select multiple skills and that too in a vertical form(default).


Article Tags :