Bootstrap5 Forms
In this chapter, we will learn how to create forms with Bootstrap. Bootstrap can create forms of different styles using simple HTML tags and extended classes.
Form Element ,
Bootstrap5 Form Layout
- Stacked form (full width): vertical direction
- Inline form: horizontal direction
Bootstrap provides two types of form layouts:
Stacked forms
The following example uses two input boxes, one checkbox, and one submit button to create a stacked form:
Example
<form>
<div class=">mb-3 mt-3
"
<label for="email" class="form-label">Email:
</
label
<
input
type
=
"
email
"
class
=
"
form-control
"
id
=
"
email
"
placeholder
=
"Enter email
"
name
=
"
"
</
div
<
div
class
=
"
mb-3
"
<
label
for
=
"
pwd
"
class
=
"
form-label
"Password:
</
label
<
input
type
=
"
password
"
class
=
"
form-control
"
id
=
"
pwd
"
placeholder
=
"Enter password
"
name
=
"
pswd
"
</
div
<
div
class
=
"form-check mb-3
"
<label class="form-check-label">
<input class="form-check-input" type="checkbox" name="remember">Remember me
</
label
</
div
<
button
type
=
"
submit
"
class
=
"btn btn-primary
"
Submit
</
button
</
formTry it »
Display effect:

In the example we use the .form-label class to ensure the label element has some padding.
Checkboxes (checkboxe) use different markup. They use .form-check wrapped around the container element. Checkboxes and radio buttons use .form-check-input, and their labels can use the .form-check-label class.
Inline form
If you want form elements to be displayed side by side, use .row and .col:
In the example below, the two input boxes are displayed side by side, creating an inline form:
Example
<form>
<div class="row">
<div class="col">
<input type="text" class="form-control" placeholder=">Enter email
"
name
=
"
"
</
div
<
div
class
=
"
col
"
<
input
type
=
"
password
"
class
=
"
form-control
"
placeholder
=
"Enter password
"
name
=
"
pswd
"
</
div
</
div
</
formTry it »
Display effect:

Text box
Use the textarea tag to create a text box for form submission, and use the .form-control class to render the text box textareas tag:
Example
<label for="comment">Please enter a comment:
</
label
<
textarea
class
=
"
form-control
"
rows
=
"
5
"
id
=
"
comment
"
name
=
"
text
"
</
textareaTry it »
Display effect:

Input Group Sizing
We can add the .img-fluid class to the .form-control Use the .form-control-lg or .form-control-sm class on an input box to set its size:
Example
<input type="text" class=">form-control form-control-lg
"
placeholder
=
"
Large input box
"
<input type="text" class="form-control" placeholder=">Normal-sized input box
"
<input type="text" class=">form-control form-control-sm
"
placeholder
=
"
Small input box
"
Try it »
Display effect:

Disabled/readonly form
Use the disabled/readonly attributes to set an input field as disabled/read-only:
Example
<input type="text" class="form-control" placeholder=">Normal input
"
<input type="text" class="form-control" placeholder=">Disabled input
"
disabled
<input type="text" class="form-control" placeholder=">Readonly input
"
readonly
Try it »
Plain text input
Using the .form-control-plaintext class removes the border of the input box::
Example
<input type="text" class="form-control-plaintext" placeholder=">Plaintext input
"
<input type="text" class="form-control" placeholder=">Normal input
"
Try it »
Color picker
Using the .form-control-color class creates a color picker:
Example
<input type="color" class=">form-control form-control-color
"
value
=
"
#CCCCCC
"
Try it »
Display effect:
