Bootstrap (Part-4) | Vertical Forms, Horizontal Forms, Inline Forms

Hello Everyone,

In this article, we’ll learn creating forms. Forms are used almost in every website and they are used to collect user input.

Forms:
Bootstrap provides 3 types of form layout, namely:

Vertical Forms (Default)
Horizontal Forms
Inline Forms
We’ll look into each of them separately :
Vertical Forms:
First of all, we’ll initialize the form using tag. We’ll wrap all the labels and form controls inside the tag

. This is needed for optimum spacing between the form components.

Now, we can design the form within these tags as per our need. We can use a label to define a label for an input element. Remember that the attribute of the tag should be equal to the id attribute of the related element to bind them together. After the label tag, one can enter the tag that specifies an input field where the user can enter data. The class to be used inside the input tag must be class=”form-control”. One can also use placeholder attribute which specifies a short hint that describes the expected value of an input field.

In this article, we’ll learn creating forms. Forms are used almost in every website and they are used to collect user input.

Forms:
Bootstrap provides 3 types of form layout, namely:

Vertical Forms (Default)
Horizontal Forms
Inline Forms
We’ll look into each of them separately :
Vertical Forms:
First of all, we’ll initialize the form using tag. We’ll wrap all the labels and form controls inside the tag

. This is needed for optimum spacing between the form components.

Now, we can design the form within these tags as per our need. We can use a label to define a label for an input element. Remember that the attribute of the tag should be equal to the id attribute of the related element to bind them together. After the label tag, one can enter the tag that specifies an input field where the user can enter data. The class to be used inside the input tag must be class=”form-control”. One can also use placeholder attribute which specifies a short hint that describes the expected value of an input field.

Horizontal Forms:

Horizontal forms are different from Vertical forms not only in the amount of markup, but also in the presentation of the form. To make a form horizontal, add class=”form-horizontal” in the element. If you’re using the element then you must use class=”control-label”. Also, remember that you can use Bootstrap’s predefined grid classes to align labels and groups of form controls in a horizontal layout.

You can also add particular styles to the labels and input field. Add any of the classes has-warning, has-success, has-error,etc. in the

tag which contains class which has form-group to give it different effects when selected.

Inline Forms:

As the name suggests, in an inline form, all of the elements are inline, left-aligned, and the labels are alongside. You just need to add the class=”form-inline” in the form element.

Using the class=”sr-only” you can hide the labels of the inline forms which might cause problems sometime.

You can also add glyphicons inside the forms. For that you have to add class=”has-feedback” and add the span tag in which the glyphicon is present after the tag. Remember adding form-control-feed as the class of the span tag.

Thankyou.