The input Element


The HTML <form> element can contain one or more of the following form elements:

  • <input>
  • <label>
  • <select>
  • <textarea>
  • <button>
  • <fieldset>
  • <legend>
  • <datalist>
  • <output>
  • <option>
  • <optgroup>

 

 

One of the most used form element is the <input> element.

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


Live Demo & Try it yourself! Read More » »

The select Element


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

Example

<label for="class">Choose your Class:</label>
  <select id="class" name="class">
    <option value="6th">6th</option>
    <option value="7th">7th</option>
    <option value="8th">8th</option>
    <option value="9th">9th</option>
    <option value="10th">10th</option>
    <option value="11th">11th</option>
    <option value="12th">12th</option>
  </select>

 

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="10th" selected>10th Class</option>

 


Live Demo & Try it yourself! Read More » »

Visible Values - select Element


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

 


Live Demo & Try it yourself! Read More » »

Allow Multiple Selections - select Element


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


Live Demo & Try it yourself! Read More » »

The textarea Element


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

 

 

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:


Live Demo & Try it yourself! Read More » »

The textarea element using CSS


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


Live Demo & Try it yourself! Read More » »

The fieldset and legend Elements


The <fieldset> element is used to group related data in a form.

The <legend> element defines a caption for the <fieldset> element.


Live Demo & Try it yourself! Read More » »