0% found this document useful (0 votes)
42 views

HTTML Form Elements

The document describes HTML form elements like <input>, <select>, <textarea>, and <button>. It also covers newer HTML5 form elements like <datalist> and <output>.

Uploaded by

yard.pro.991
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

HTTML Form Elements

The document describes HTML form elements like <input>, <select>, <textarea>, and <button>. It also covers newer HTML5 form elements like <datalist> and <output>.

Uploaded by

yard.pro.991
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

9/5/2019 dayframe.

html

HTML Form Elements


❮ Previous Next ❯

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 typeattribute.

Example

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


Try it Yourself »

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


file:///C:/Users/Rocky/Irfanview/Irfanview-Coding-Playground/listset/dayframe.html 1/9
9/5/2019 dayframe.html

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

Example

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

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

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


Try it Yourself »

Visible Values:

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

file:///C:/Users/Rocky/Irfanview/Irfanview-Coding-Playground/listset/dayframe.html 2/9
9/5/2019 dayframe.html

Example

<select name="cars" size="3">


<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
Try it Yourself »

Allow Multiple Selections:

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

Example

<select name="cars" size="4" multiple>


<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
Try it Yourself »

The <textarea> Element


file:///C:/Users/Rocky/Irfanview/Irfanview-Coding-Playground/listset/dayframe.html 3/9
9/5/2019 dayframe.html

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

Example

<textarea name="message" rows="10" cols="30">


The cat was playing in the garden.
</textarea>
Try it Yourself »

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:

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

Example

<textarea name="message" style="width:200px; height:600px;">


The cat was playing in the garden.
</textarea>

file:///C:/Users/Rocky/Irfanview/Irfanview-Coding-Playground/listset/dayframe.html 4/9
9/5/2019 dayframe.html

Try it Yourself »

The <button> Element


The <button> element defines a clickable button:

Example

<button type="button" onclick="alert('Hello World!')">Click Me!</button>


Try it Yourself »

This is how the HTML code above will be displayed in a browser:

Click Me!

Note: Always specify the type attribute for the button element. Different browsers may use different
default types for the button element.

HTML5 Form Elements


HTML5 added the following form elements:

<datalist>
<output>

file:///C:/Users/Rocky/Irfanview/Irfanview-Coding-Playground/listset/dayframe.html 5/9
9/5/2019 dayframe.html

Note: Browsers do not display unknown elements. New elements that are not supported in older
browsers will not "destroy" your web page.

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

<form action="/action_page.php">
<input list="browsers">
<datalist id="browsers">
<option value="Internet Explorer">
<option value="Firefox">
<option value="Chrome">
<option value="Opera">
<option value="Safari">
</datalist>
</form>
Try it Yourself »

file:///C:/Users/Rocky/Irfanview/Irfanview-Coding-Playground/listset/dayframe.html 6/9
9/5/2019 dayframe.html

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:

<form action="/action_page.php"
oninput="x.value=parseInt(a.value)+parseInt(b.value)">
0
<input type="range" id="a" name="a" value="50">
100 +
<input type="number" id="b" name="b" value="50">
=
<output name="x" for="a b"></output>
<br><br>
<input type="submit">
</form>
Try it Yourself »

HTML Exercises

file:///C:/Users/Rocky/Irfanview/Irfanview-Coding-Playground/listset/dayframe.html 7/9
9/5/2019 dayframe.html

Test Yourself With Exercises

Exercise:
In the form below, add an empty drop down list with the name "cars".

<form action="/action_page.php">
< >
</ >
</form>

Submit Answer »

Start the Exercise

HTML Form Elements


Tag Description
<form> Defines an HTML form for user input
file:///C:/Users/Rocky/Irfanview/Irfanview-Coding-Playground/listset/dayframe.html 8/9
9/5/2019 dayframe.html

<input> Defines an input control


<textarea> Defines a multiline input control (text area)
<label> Defines a label for an <input> element
<fieldset> Groups related elements in a form
<legend> Defines a caption for a <fieldset> element
<select> Defines a drop-down list
<optgroup> Defines a group of related options in a drop-down list
<option> Defines an option in a drop-down list
<button> Defines a clickable button
<datalist> Specifies a list of pre-defined options for input controls
<output> Defines the result of a calculation

For a complete list of all available HTML tags, visit our HTML Tag Reference.

❮ Previous Next ❯

file:///C:/Users/Rocky/Irfanview/Irfanview-Coding-Playground/listset/dayframe.html 9/9

You might also like