What are floating labels in Bootstrap?
label enables the developer to name an input field. By default, label content and the input field stand separately.
Bootstrap comes with form-floating to enable floating labels with Bootstrap’s textual form fields.
Procedure
The following is a step-by-step procedure to create a floating label in bootstrap:
-
Create a container, for example
div, with the classform-floating -
Create your
inputfield.
The input field should have the following:
-
type— to set the form validation -
class = “form-control” -
An
id— which should match theforattribute in thelabel -
A
placeholder
- Create the
labelwith aforattribute that matches theidof theinputelement.
NOTE
The input must come before the label.
Floating labels can also be used with bootstrap’s textarea and select.
Try it yourself for better understanding.