Bootstrap - Floating Labels



This chapter will discuss about Bootstrap floating labels. Floating labels refer to form labels that float over the input fields.

Basic example

  • To allow floating labels with Bootstrap's textual form fields, include a pair of and elements in .form-floating.

  • Each must have a placeholder since the technique for CSS-only floating labels employs the :placeholder-shown pseudo-element. The needs to be placed first to make use of a sibling selector like (~).

Example

You can edit and try running this code using Edit & Run option.

    
    
    
        Bootstrap - Floating Labels
        
        
        
        
        
    
    
        

When a value is already assigned, elements will automatically align their position to float over the input field.

Example

You can edit and try running this code using Edit & Run option.

    
    
    
        Bootstrap - Floating Labels
        
        
        
        
        
    
    
        

By using form validation styles like is-invalid, you can provide visual feedback to users when they submit incorrect data.

Example

You can edit and try running this code using Edit & Run option.

    
    
    
        Bootstrap - Floating Labels
        
        
        
        
        
    
    
        

Textareas

The height of

Don't use the rows attribute if you want to customize the height of your

Selects

  • Floating labels are only accessible on .form-selects, in addition to .form-control.

  • The same concepts apply to them, except unlike s, they always display the in its floated state. Size-based and multiple selects are not supported.

Example

You can edit and try running this code using Edit & Run option.

    
    
    
        Bootstrap - Floating Labels
        
        
        
        
        
    
    
        

Disabled

Add the disabled boolean attribute on an input. This gives grayed-out appearance to an input, textarea, or select. It also removes pointer events, and prevents focusing.

Example

You can edit and try running this code using Edit & Run option.

    
    
    
        Bootstrap - Floating Labels
        
        
        
        
        
    
    
        

Readonly plaintext

When switching from an editable to a plaintext value without changing the page layout, .form-control-plaintext can be useful.

Example

You can edit and try running this code using Edit & Run option.

    
    
    
        Bootstrap - Floating Labels
        
        
        
        
        
    
    
        

Input groups

Similarly, floating labels support .input-group.

Example

You can edit and try running this code using Edit & Run option.

    
    
    
        Bootstrap - Floating Labels
        
        
        
        
        
    
    
        
    
    

The -feedback (it is a validation class to provide valuable feedback to users before submitting the form.) should be positioned outside of the .form-floating but inside of the .input-group when using .input-group and .form-floating along with form validation.

Example

You can edit and try running this code using Edit & Run option.

    
    
    
        Bootstrap - Floating Labels
        
        
        
        
        
    
    
        
Wrong Password

Layout

  • When using a grid system, the implementation of floating labels layout becomes beneficial as it enables the placement of form elements within column classes.

  • There is no pre-defined classes in bootstrap, so we must utilize form classes and position them according to our requirement.

Example

You can edit and try running this code using Edit & Run option.

    
    
    
        Bootstrap - Floating Labels
        
        
        
        
        
    
    
        
Advertisements