How to use a select tag in Bootstrap
Overview
The form is a Bootstrap element, which is mainly used in creating a form on our website.
Bootstrap select is a form-control. It sets up a collapsible list of items that are selectable.
Usage
Bootstrap select can be used in two ways.
-
Using the
selecttag with theform-controlclass. -
Using the
selecttag with thecustom-controlclass.
Note: Bootstrap 4 comes with customized form elements, which are meant to replace browser defaults. One of it is the
custom-selectclass.
The select tag with the form-control class
Explanation
- Line 8: The
formelement creates our form. - Line 9: A
labelis included. This gives a caption to what is going to follow. - Line 10: A
selecttag with the classform-controlis included. This sets up for us, theselectbutton.
The select tag with the custom-select class
Explanation
-
Line 8: The
formelement creates our form. -
Line 9: A
labelis included. This gives a caption to what is going to follow. -
Line 10: A
selecttag with the classcustom-selectis included. This sets up the custom “select” button for us.
Bootstrap select is easy to use in creating collapsible options to choose from. Notice the difference between the two outputs and try it yourself.