HTML Forms & Input Elements

Example + Code View (Student Learning Format)

What is an HTML Form?

HTML forms are used to collect user input such as text, selections, passwords, files, and more. Forms are commonly used for:

Basic Syntax


<form>
   <!-- input fields go here -->
</form>

Input Type: Text and Number

Output:




Code:


<form>
<label>Name:</label><br>
<input type="text" placeholder="Enter your name" required>

<br>

<label>Age:</label><br>
<input type="number" min="1" max="100">
</form>
Important Attributes:

Input Type: Date and Time





<form>
<label>Select Date:</label><br>
<input type="date">

<br>

<label>Select Time:</label><br>
<input type="time">
</form>

Used for booking systems, appointments, scheduling etc.

Input Type: Email and Password





<form>
<label>Email:</label><br>
<input type="email" placeholder="example@mail.com">

<br>

<label>Password:</label><br>
<input type="password" maxlength="12">
</form>

Radio and Checkbox

Output:


Male Female


HTML CSS JavaScript

Code:


<form>
<label>Gender:</label><br>
<input type="radio" name="gender"> Male
<input type="radio" name="gender"> Female

<br><br>

<label>Skills:</label><br>
<input type="checkbox"> HTML
<input type="checkbox"> CSS
<input type="checkbox"> JavaScript
</form>

Select Dropdown

Output:


Code:


<form>

<label>Select Course:</label><br>

<select>

<option>HTML</option>
<option>CSS</option>
<option selected>-- Choose Course --</option>
<option>JavaScript</option>
<option>PHP</option>
</select>

</form>
Important:

Textarea Input

Output:


Code:


<form>
<label>Message:</label><br>
<textarea rows="4" cols="30"
placeholder="Type your message"></textarea>
</form>

Range Input



<form>
<label>Rate:</label><br>
<input type="range" min="0" max="10">

Search Input



<form>
<label>Search:</label><br>
<input type="search">
</form>


Color Input



<form>
<label>Pick Color:</label><br>
<input type="color">
</form>


File Input

Output:

Code:


<form>
<input type="file" value="Upload File">
</form>
File input allows users to upload files from their device.

Form Buttons

Output:

Code:


<form>
<input type="submit" value="Submit">
<input type="reset" value="Reset">
<input type="button" value="Normal Button">
</form>

Conclusion

HTML forms are essential for interactive websites. By combining different input types, developers can collect structured data efficiently and improve user experience.