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
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 <select> Element
The <select>
element defines a drop-down list:
Example
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
Fiat
Visible Values:
Use the size
attribute to specify the number of visible values:
Example
Allow Multiple Selections:
Use the multiple
attribute to allow the user to select more than one value:
Example
The <textarea> Element
The <textarea>
element defines a multi-line input field (a text area):
Example
The rows
attribute specifies the visible number of lines in a text area.
The cols
attribute specifies the visible width of a text area.
This is how the HTML code above will be displayed in a browser:
The cat was playing in the garden.
You can also define the size of the text area by using CSS:
Example
The <button> Element
The <button>
element defines a clickable button:
Example
This is how the HTML code above will be displayed in a browser:
HTML5 Form Elements
HTML5 added the following form elements:
<datalist>
<output>
HTML5 <datalist> Element
The <datalist>
element specifies a list of pre-defined options for an <input>
element.
Users will see a drop-down list of the pre-defined options as they input data.
The list
attribute of the <input>
element, must refer to the id
attribute of the <datalist>
element.
Example
HTML5 <output> Element
The <output>
element represents the result of a calculation (like one performed by a script).
Example
Perform a calculation and show the result in an <output>
element:
Leave A Comment