HTML Form Elements

in #formelement6 years ago

images (6).jpeg
source

HTML Form Elements

This chapter describes all HTML form elements.

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.

Example

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

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

All the different input types are covered in the next chapter.
The textarea Element

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

Example

textarea name="messages"rows="12" cols="30"
The birds was playing in the garden.

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

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

<option value="fiat"selected>Fiat

Visible Values:

Use the size attribute to specify the number of visible values:

Example

select name="cars"size="3"
<optionvalue="volvo">Volvo
<optionvalue="saab">Saab
<optionvalue="fiat">Fiat
<optionvalue="audi">Audi

The select Element

The select element defines a drop-down list:

Example

select name="cars"
<optionvalue="volvo">Volvo
<optionvalue="saab">Saab
<optionvalue="fiat">Fiat
<optionvalue="audi">Audi

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:

Example

Allow Multiple Selections:

Use the multiple attribute to allow the user to select more than one value:

Example

<select name="cars"size="4" multiple>
<optionvalue="volvo">Volvo
<optionvalue="saab">toyota
<optionvalue="fiat">volvo
<optionvalue="audi">diat

Sort:  

This post has received a 0.37 % upvote from @drotto thanks to: @rabiul21.