


Khusboo Tayal
HTML forms are essential for collecting user data. Whether it's logging in, signing up, submitting feedback, or placing an order, forms provide a structured way for users to send data to a web server.
An HTML form is created using the <form> tag. Inside the form, various input elements like text fields, checkboxes, buttons, etc., allow users to enter information.
<form action="submit_form.php" method="post"> <!-- input elements go here --> </form>
1. Text Input
<label for="name">Name:</label> <input type="text" id="name" name="username">
2. Email Input
<label for="email">Email:</label> <input type="email" id="email" name="email">
3. Password Input
<label for="password">Password:</label> <input type="password" id="password" name="password">
4. Number Input
<label for="age">Age:</label> <input type="number" id="age" name="age">
5. Date Input
<label for="dob">Date of Birth:</label> <input type="date" id="dob" name="dob">
Submit Button
<input type="submit" value="Submit">
Reset Button
<input type="reset" value="Reset">
Button Element (custom JavaScript or action)
<button type="button" onclick="alert('Clicked!')">Click Me</button>
Allow the user to select one option from a group.
<p>Gender:</p> <input type="radio" id="male" name="gender" value="male"> <label for="male">Male</label> <input type="radio" id="female" name="gender" value="female"> <label for="female">Female</label>
Allow the user to select multiple options.
<p>Hobbies:</p> <input type="checkbox" id="reading" name="hobby" value="reading"> <label for="reading">Reading</label> <input type="checkbox" id="sports" name="hobby" value="sports"> <label for="sports">Sports</label>
<label for="country">Choose a country:</label> <select id="country" name="country"> <option value="india">India</option> <option value="usa">USA</option> <option value="uk">UK</option> </select>
<label for="message">Message:</label><br> <textarea id="message" name="message" rows="4" cols="40"></textarea>
<fieldset> <legend>Contact Info</legend> <label>Email:</label> <input type="email" name="email"> </fieldset>
Required:
<input type="text" name="username" required>
Placeholder:
<input type="text" name="username" placeholder="Enter your name">
HTML5 input types like email, number, url, and attributes like required, min, max, pattern, help validate input before submission.
<input type="email" required> <input type="number" min="18" max="99">
<form action="/submit" method="post"> <label>Name:</label> <input type="text" name="name" required><br><br> <label>Email:</label> <input type="email" name="email" required><br><br> <label>Message:</label><br> <textarea name="message" rows="4" cols="40"></textarea><br><br> <input type="submit" value="Send"> </form>
Learn how to use AI to build, market and grow your business. Subscribe our newsletter to get AI tips, tools and prompts in your inbox to power your marketing, sales and business.
Tags
#htmlforms #htmlinput #htmltutorial #webdevelopment #formsinhtml #learnhtml #htmlforbeginners #userinput #formvalidation