HTML forms elements

Author: MDBootstrap

The <input> Element

The most important form element is the <input> element.

The <input> element can be displayed in several ways, depending on the type attribute.

                      <input name="firstname" type="text">

Live preview

Note: If the type attribute is omitted, the input field gets the default type: "text".

The <select> Element

The <select> element defines a drop-down list:

                      <select name="cars">
                          <option value="volvo">Volvo</option>
                          <option value="saab">Saab</option>
                          <option value="fiat">Fiat</option>
                          <option value="audi">Audi</option>

Live preview

The <option> elements defines an option that can be selected.

By default, the first item in the drop-down list is selected.

To define a pre-selected option, add the selected attribute to the option:

                        <option value="fiat" selected>Fiat</option>

The <textarea> Element

The <textarea> element defines a multi-line input field (a text area):

          <textarea name="message" rows="10" cols="30">
              The cat was playing in the garden.

Live preview

The rows attribute specifies the visible number of lines in a text area.

The cols attribute specifies the visible width of a text area.

You can also define the size of the text area by using CSS:

                      <textarea name="message" style="width:200px; height:600px">
                          The cat was playing in the garden.

Previous lesson Next lesson

Spread the word:
Do you need help? Use our support forum

About the author