Bootstrap Form Layout
Posted by Superadmin on April 30 2023 16:46:54

Bootstrap Form Layout

Bootstrap Form Layout

Introduction to Bootstrap Form Layout

The bootstrap form layout is an arrangement of user form on the web page using bootstrap. It is a design as per web application helping bootstrap classes. There are three types of form layout in bootstrap3 which are the vertical layout, horizontal layout, and inline layout. There are two types of form layout in bootstrap4 which are vertical layout (Stacked form) and inline layout. The label and bootstrap form attribute set in vertical order known as vertical bootstrap form layout or stacked form. The form label and their bootstrap attribute set in horizontal order known as horizontal form layout. The all form label and their bootstrap attribute set in a single line known as an inline form layout. This is used to make form elegant and attractive on the website.

Syntax

The following syntax is the three form layouts.

1. Vertical Layout form(Stacked form)

Syntax:

<form>
<div class ="form-group">
<label for ="username">User Name: </label>
<input class ="form-control"type ="text" id="username" />
</div>
</form>

Explanation:

2. Horizontal Layout form

Syntax:

<form class = "form-horizontal">
<div class = "form-group">
<label for ="username"class = "control-label col-md-4">User Name: </label>
<input class ="form-control col-md-8"type ="text" id="username" />
</div>
</form>

Explanation:

3. Inline form Layout

Syntax:

<form class = "form-inline">
<div class = "form-group">
<label for ="search">Search Here: </label>
<input class ="form-control"type ="search" id="search" />
</div>
</form>

Explanation:

How to Set Form Layout in Bootstrap?

Step #1:

<link rel = "stylesheet" href ="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"> </script>
<script src = "https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>

The bootstrap4 supports files are below.

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js">
</script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js">
</script>

Step #2:

1. Vertical form Layout

Code:

<form>
<div class = "form-group">
<label for = "eml"> Enter Email: </label>
<input class = "form-control" type = "email" id = "eml" name = "eml"
placeholder = "Enter email here">
</div>
<input class = "btnbtn-warning" type = "submit" >
</form>

Steps:

2. Horizontal form Layout

The horizontal form layout use class = “form-horizontal” in.

Code:

<form class = "form-horizontal">
<div class = "form-group">
<label class = "control-label col-md-4" for="eml"> Enter Email: </label>
<div class = "col-md-8">
<input class = "form-control" type = "email" id = "eml" name = "eml"
placeholder = "Enter email here" >
</div>
</div>
<div class = "form-group">
<div class = "col-md-offset-4 col-md-8">
<input class = "btnbtn-warning" type = "submit">
</div>
</div>
</form>

Steps:

3. Inline form Layout

The inline form layout use class = “form-inline” in <form> component.

Code:

<form class="form-inline">
<div class = "form-group">
<label for = "eml"> Enter Email: </label>
<input class = "form-control" type = "email" id = "eml" name = "eml"
placeholder = "Enter email here">
</div>
<input class = "btnbtn-warning" type = "submit" >
</form>

Steps:

Examples to Implement Bootstrap Form Layout

Below are the different examples:

Example #1 – Vertical form layout

Code:

<!DOCTYPE html>
<html>
<head>
<title> Bootstrap form layout Example </title>
<meta charset = "utf-8">
<meta name = "viewport" content = "width=device-width, initial-scale=1">
<link rel = "stylesheet" href = "https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
</script>
<script src = "https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js">
</script>
</head>
<body>
<div class = "container">
<h2> Vertical form (Stacked form) </h2>
<form>
<div class = "form-group">
<label for = "eml"> Enter Email: </label>
<input class = "form-control" type = "email" id = "eml" name = "eml" placeholder = "Enter email here">
</div>
<div class = "form-group">
<label for = "password"> Enter Password: </label>
<input class = "form-control" type = "password" id = "password" name = "password" placeholder = "Enter password here" >
</div>
<input class = "btnbtn-warning" type = "submit" >
</form>
</div>
</body>
</html>

Output:

Bootstrap Form Layout Example 1

Explanation:

Example #2 – Horizontal form layout

Code:

<!DOCTYPE html>
<html>
<head>
<title> Bootstrap form layout Example </title>
<meta charset = "utf-8">
<meta name = "viewport" content = "width=device-width, initial-scale=1">
<link rel = "stylesheet" href = "https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
</script>
<script src = "https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js">
</script>
</head>
<body>
<div class="container">
<h2><center> Horizontal bootstrap form layout </center></h2>
<form class = "form-horizontal">
<div class = "form-group">
<label class = "control-label col-md-4" for="eml"> Enter Email: </label>
<div class = "col-md-8">
<input class = "form-control" type = "email" id = "eml" name = "eml" placeholder = "Enter email here" >
</div>
</div>
<div class = "form-group">
<label class = "control-label col-md-4" for = "password"> Enter Password: </label>
<div class = "col-md-8">
<input class = "form-control" type = "password" id = "password" name = "password" placeholder = "Enter password here" >
</div>
</div>
<div class = "form-group">
<div class = "col-md-offset-4 col-md-8">
<input class = "btnbtn-warning" type = "submit">
</div>
</div>
</form>
</div>
</body>
</html>

Output:

Bootstrap Form Layout Example 2

Explanation:

Example #3 – Inline form layout

Code:

<!DOCTYPE html>
<html>
<head>
<title> Bootstrap form layout Example </title>
<meta charset = "utf-8">
<meta name = "viewport" content = "width=device-width, initial-scale=1">
<link rel = "stylesheet" href = "https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
</script>
<script src = "https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js">
</script>
</head>
<body>
<div class = "container">
<h2> Inline bootstrap form layout </h2>
<form class="form-inline">
<div class = "form-group">
<label for = "eml"> Enter Email: </label>
<input class = "form-control" type = "email" id = "eml" name = "eml" placeholder = "Enter email here">
</div>
<div class = "form-group">
<label for = "password"> Enter Password: </label>
<input class = "form-control" type = "password" id = "password" name = "password" placeholder = "Enter password here" >
</div>
<input class = "btnbtn-warning" type = "submit" >
</form>
</div>
</body>
</html>

Output:

Inline Example 3

Explanation:

Conclusion