Form Inputs And Sizing In Bootstrap

What is a form input?

Bootstrap provides several form control styles, layout options, and custom components for creating a wide variety of forms.

Form controls

It supports the following form controls,

  • Input
  • Textarea
  • Checkbox
  • Radio
  • Select

Bootstrap Input

The bootstrap supports all html5 inputs types for example text,password,datetime,date,month,time,week,number,email,url,search and color

It is not fully styled if their type is not properly declared

Sample program for form input

  1. <!DOCTYPE html>    
  2. <html>    
  3.     <head>    
  4.         <meta charset="utf-8">    
  5.         <meta name="viewport" content="width=device-width, initial scale=1">    
  6.         <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">    
  7.     </head>    
  8. <body>    
  9.         <div class="container">    
  10.             <div class="row">    
  11.                     
  12.                 <div class="form-group">    
  13.                     <label for="usr">Name:</label>    
  14.                     <input type="text" class="form-control" id="usr">    
  15.                 </div>    
  16.                 <div class="form-group">    
  17.                     <label for="pwd">Password:</label>    
  18.                     <input type="password" class="form-control" id="pwd">    
  19.                 </div>    
  20.             
  21.             </div>    
  22.         </div>    
  23.     <script type="text/javascript" src="js/bootstrap.min.js"></script>    
  24.     <script type="text/css" src="js/jquery"></script>     
  25. </body>    
  26. </html>    

Output

Output
It is the output for the bootstrap input

Textarea

In this text area basically used to the comment box, address box etc..

Sample program for textarea

  1. <!DOCTYPE html>    
  2. <html>    
  3.     <head>    
  4.         <meta charset="utf-8">    
  5.         <meta name="viewport" content="width=device-width, initial scale=1">    
  6.         <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">    
  7.     </head>    
  8. <body>    
  9.         <div class="container">    
  10.             <div class="row">    
  11.                 <div class="form-group">    
  12.   <label for="comment">Comment:</label>    
  13.   <textarea class="form-control" rows="5" id="comment">    
  14.     
  15.                 
  16.             
  17.     <script type="text/javascript" src="js/bootstrap.min.js"></script>    
  18.     <script type="text/css" src="js/jquery"></script>   
  19. </body>  
  20. </html>   

Output

Output

This is the output for the textarea

Checkboxes

This checkbox is basically used to select the many number of options from a list of the preset options

There are many checkboxes we can use to access the single list

Sample program for checkbox

  1. <!DOCTYPE html>    
  2. <html>    
  3.     <head>    
  4.         <meta charset="utf-8">    
  5.         <meta name="viewport" content="width=device-width, initial scale=1">    
  6.         <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">    
  7.     </head>    
  8. <body>    
  9.         <div class="container">    
  10.             <div class="row">    
  11.         <div class="checkbox">    
  12.   <label><input type="checkbox" value="">Option 1</label>    
  13. </div>    
  14. <div class="checkbox">    
  15.   <label><input type="checkbox" value="">Option 2</label>    
  16. </div>    
  17. <div class="checkbox">    
  18.   <label><input type="checkbox" value="">Option 3</label>    
  19. </div>    
  20.             </div>    
  21.         </div>    
  22.     <script type="text/javascript" src="js/bootstrap.min.js"></script>    
  23.     <script type="text/css" src="js/jquery"></script>     
  24. </body>    
  25. </html>    

Output

Output
This the output for the bootstrap checkbox

Checkboxes are used in inline

In this inline class it is used so the checkboxes appear in a single line

.checkbox-inline class is used to set an inline checkbox

Sample program for inline checkboxes (example 1)

  1. <!DOCTYPE html>    
  2. <html>        
  3.     <head>    
  4.         <meta charset="utf-8">    
  5.         <meta name="viewport" content="width=device-width, initial scale=1">    
  6.         <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">    
  7.     </head>    
  8. <body>    
  9.         <div class="container">    
  10.             <div class="row">    
  11.         <div class="checkbox-inline">    
  12.   <label><input type="checkbox" value="">Option 1</label>    
  13. </div>    
  14. <div class="checkbox-inline">    
  15.   <label><input type="checkbox" value="">Option 2</label>    
  16. </div>    
  17. <div class="checkbox-inline">    
  18.   <label><input type="checkbox" value="">Option 3</label>    
  19. </div>    
  20.             </div>    
  21.         </div>    
  22.     <script type="text/javascript" src="js/bootstrap.min.js"></script>    
  23.     <script type="text/css" src="js/jquery"></script>     
  24. </body>    
  25. </html>  

Sample program for inline checkboxes (example 2)

  1. <!DOCTYPE html>    
  2. <html>    
  3.     <head>    
  4.         <meta charset="utf-8">    
  5.         <meta name="viewport" content="width=device-width, initial scale=1">    
  6.         <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">    
  7.     </head>    
  8. <body>    
  9.         <div class="container">    
  10.             <div class="row">    
  11. <label class="checkbox-inline"><input type="checkbox" value="">Option 1</label>    
  12. <label class="checkbox-inline"><input type="checkbox" value="">Option 2</label>    
  13. <label class="checkbox-inline"><input type="checkbox" value="">Option 3</label>    
  14.     
  15.             </div>    
  16.         </div>    
  17.     <script type="text/javascript" src="js/bootstrap.min.js"></script>    
  18.     <script type="text/css" src="js/jquery"></script>     
  19. </body>    
  20. </html>    

Output

Output

This the output for the bootstrap inline checkbox

Radio Buttons

Radio buttons are used if you want to limit the user to just one selection from a list of preset options.

The radio button is basically used to chose the identification for humans (male or female)

Sample program for the radio button

  1. <!DOCTYPE html>    
  2. <html>    
  3.     <head>    
  4.         <meta charset="utf-8">    
  5.         <meta name="viewport" content="width=device-width, initial scale=1">    
  6.         <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">    
  7.     </head>    
  8. <body>    
  9.         <div class="container">    
  10.             <div class="row">    
  11. <div class="radio">    
  12.   <label><input type="radio" name="optradio">Male</label>    
  13. </div>    
  14. <div class="radio">    
  15.   <label><input type="radio" name="optradio">Female</label>    
  16. </div>    
  17. <div class="radio">    
  18.   <label><input type="radio" name="optradio">Other</label>    
  19. </div>    
  20. </div>    
  21.         </div>    
  22.     <script type="text/javascript" src="js/bootstrap.min.js"></script>    
  23.     <script type="text/css" src="js/jquery"></script>     
  24. </body>    
  25. </html>    

Output

Output
This is the output for the radio button

Radio button using the inline

Inline class is used so the radio button apears in a single line

.radio-inline class is used to set an inline checkbox

Sample program for inline radio button

  1. <!DOCTYPE html>    
  2. <html>    
  3.     <head>    
  4.         <meta charset="utf-8">    
  5.         <meta name="viewport" content="width=device-width, initial scale=1">    
  6.         <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">    
  7.     </head>    
  8. <body>    
  9.         <div class="container">    
  10.             <div class="row">    
  11. <label class="radio-inline"><input type="radio" name="optradio">Male</label>    
  12. <label class="radio-inline"><input type="radio" name="optradio">Female</label>    
  13. <label class="radio-inline"><input type="radio" name="optradio">Other</label>    
  14.             </div>    
  15.         </div>    
  16.     <script type="text/javascript" src="js/bootstrap.min.js"></script>    
  17.     <script type="text/css" src="js/jquery"></script>     
  18. </body>    
  19. </html>   

Output

Output

This is the output for the inline radio button

Select List

Select lists are used if you want to allow the user to pick from multiple options.

Sample program for the select list

  1. <!DOCTYPE html>    
  2. <html>    
  3.     <head>    
  4.         <meta charset="utf-8">    
  5.         <meta name="viewport" content="width=device-width, initial scale=1">    
  6.         <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">    
  7.     </head>    
  8. <body>    
  9.         <div class="container">    
  10.             <div class="row">    
  11. <div class="form-group">    
  12.   <label for="sel1">Select list:</label>    
  13.   <select class="form-control" id="sel1">    
  14.     <option>1</option>    
  15.     <option>2</option>    
  16.     <option>3</option>    
  17.     <option>4</option>    
  18.   </select>    
  19. </div>    
  20.             </div>    
  21.         </div>    
  22.     <script type="text/javascript" src="js/bootstrap.min.js"></script>    
  23.     <script type="text/css" src="js/jquery"></script>     
  24. </body>    
  25. </html>    

Output

Output

This is the output for the bootstrap select list

Static Control

If you want plain text next to a form label within a horizontal form use .form-cotrol-static

That is included in to the <p> tag

Sample program for the static control

  1. <!DOCTYPE html>    
  2. <html>    
  3.     <head>    
  4.         <meta charset="utf-8">    
  5.         <meta name="viewport" content="width=device-width, initial scale=1">    
  6.         <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">    
  7.     </head>    
  8. <body>    
  9.         <div class="container">    
  10.             <div class="row">    
  11. <form class="form-horizontal">    
  12.   <div class="form-group">    
  13.     <label class="control-label col-sm-2" for="email">Email:</label>    
  14.     <div class="col-sm-10">    
  15.       <p class="form-control-static">[email protected]</p>    
  16.     </div>    
  17.   </div>    
  18. </form>    
  19.     </div>    
  20.         </div>    
  21.     <script type="text/javascript" src="js/bootstrap.min.js"></script>    
  22.     <script type="text/css" src="js/jquery"></script>     
  23. </body>    
  24. </html>    

Output

Output

This is the output for the static control

Input Groups

This .input-group is used to enhance an input by adding an icons, text or button in front or behind it as a “help text”,

  • .input-group-addon class attaches an icon or help text to the input field
  • .input-group-btn class is used button next an input it is combined to gather in to the search bar

Sample program for the input groups

  1. <!DOCTYPE html>    
  2. <html>    
  3.     <head>    
  4.         <meta charset="utf-8">    
  5.         <meta name="viewport" content="width=device-width, initial scale=1">    
  6.         <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">    
  7.     </head>    
  8. <body>    
  9.         <div class="container">    
  10.             <div class="row">    
  11. <form>    
  12.   <div class="input-group">    
  13.     <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>    
  14.     <input id="email" type="text" class="form-control" name="email" placeholder="Email">    
  15.   </div>    
  16.   <div class="input-group">    
  17.     <span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>    
  18.     <input id="password" type="password" class="form-control" name="password" placeholder="Password">    
  19.   </div>    
  20.   <div class="input-group">    
  21.     <span class="input-group-addon">Text</span>    
  22.     <input id="msg" type="text" class="form-control" name="msg" placeholder="Additional Info">    
  23.   </div>    
  24. <div class="input-group">    
  25.     <input type="text" class="form-control" placeholder="Search">    
  26.     <div class="input-group-btn">    
  27.       <button class="btn btn-default" type="submit">    
  28.         <i class="glyphicon glyphicon-search"></i>    
  29.       </button>    
  30.     </div>    
  31. </form>    
  32. </div>    
  33.         </div>    
  34.     <script type="text/javascript" src="js/bootstrap.min.js"></script>    
  35.     <script type="text/css" src="js/jquery"></script>     
  36. </body>    
  37. </html>   

Output

Output

This the output for the bootstrap input groups

Input Sizing

Input sizing in form

There are two types of input sizing;  one is large another one is small,

  • .input-lg-* class is used for the large size
  • .input-sm-* class is used for the small size

Quickly size labels and form controls within horizontal forms to add .form-group class to the <div class=”form-group”> tag element

Sample program for input sizing

  1. <!DOCTYPE html>    
  2. <html>    
  3.     <head>    
  4.         <meta charset="utf-8">    
  5.         <meta name="viewport" content="width=device-width, initial scale=1">    
  6.         <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">    
  7.     </head>    
  8. <body>        
  9.         <div class="container">    
  10.             <div class="row">    
  11. <form>    
  12.   <div class="form-group">    
  13.     <label for="inputsm">Small input</label>    
  14.     <input class="form-control input-sm" id="inputsm" type="text">    
  15.   </div>    
  16.    <div class="form-group">    
  17.     <label for="inputdefault">Default input</label>    
  18.     <input class="form-control" id="inputdefault" type="text">    
  19.   </div>    
  20.   <div class="form-group">    
  21.     <label for="inputlg">Large input</label>    
  22.     <input class="form-control input-lg" id="inputlg" type="text">    
  23.   </div>    
  24. </form>    
  25. </div>    
  26.         </div>    
  27.     <script type="text/javascript" src="js/bootstrap.min.js"></script>    
  28.     <script type="text/css" src="js/jquery"></script>     
  29. </body>    
  30. </html>   

Output

Output


This is the output for the input sizing

Conclusion

I hope now you can understand how to use and create the Bootstrap Form inputs and sizing. In the future we can learn about the Bootstrap techniques step by step. Stay tuned.

Up Next
    Ebook Download
    View all
    CSS by AI
    Read by 3 people
    Download Now!
    Learn
    View all