Previous Next

HTML Forms

HTML forms play a vital role in web development as they enable users to communicate with web pages by filling information and submitting it. In HTML, a form is established through the <form> tag.

Example:

<form>
   <label for="name"> Name: </label>
   <input type="text" id="name" name="name" required>
   <label for="email"> Email: </label>
   <input type="email" id="email" name="email" required>
   <textarea name="message" cols="30" rows="4"></textarea>
   <input type="submit" value="submit">
</form>

Output

html form output

Form elements

The HTML <form> elements are as follows:

HTML <input> tag

It is employed to gather form input data in different formats such as text, password, email, etc.

Example:

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

Output

input tag output

HTML <label> Tag

It sets the label for <form> tag.

Example:

<label for="name"> Name: </label>
<input type="text" id="name" name="name">

Output

label tag output

HTML <select> and <option> Tag

It is utilized to design a drop-down menu.

Example:

<label for="cars"> Cars: </label>
<select id="cars">
    <option value="lamborghini"> lamborghini </option>
    <option value="ferrari"> Ferrari </option>
</select>

Output

select and option tag output

HTML <textarea> Tag

It is applied to retrieve long text inputs.

Example:

<textarea name="message" cols="30" rows="4"> Write Something... </textarea>

Output

textarea tag output

HTML <fieldset> Tag

It is applied to put a box around the other form fields and align the related data.

Example:

<form>
 <fieldset>
     <label for="name"> Name: </label>
     <input type="text" id="name" name="name"> 
     <label for="email"> Email: </label>
     <input type="email" id="email" name="email">
 <fieldset>
</form>

Output

HTML <legend> Tag

It gives a caption for fieldset tag.

Example:

<form>
 <fieldset>
  <legend> Info </legend>
     <label for="name"> Name: </label>
     <input type="text" id="name" name="name">
     <label for="email"> Email: </label>
     <input type="email" id="email" name="email">
 <fieldset>
</form>

Output

form output
Previous Next