Sure! Form elements in HTML allow users to input data that can be submitted to a server for processing. Here are some commonly used form elements:
Input:
<input type="text">
: A single-line text input field.<input type="password">
: A password input field where the input is masked.<input type="email">
: An email input field with built-in email validation.<input type="number">
: A numeric input field.<input type="checkbox">
: A checkbox that can be checked or unchecked.<input type="radio">
: Radio buttons for selecting one option from multiple choices.<input type="file">
: A file input field for uploading files.<input type="submit">
: A submit button for submitting the form.<input type="reset">
: A reset button for resetting the form fields to their default values.Select:
<select>
: A dropdown list for selecting one option from multiple choices.
<option>
: Defines an option in a <select>
dropdown.Textarea:
<textarea>
: A multi-line text input field for entering longer text.Button:
<button>
: A clickable button that can perform custom JavaScript actions.Here's an example demonstrating the usage of these form elements:
<form action="/submit-form" method="post">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required><br>
<label for="age">Age:</label>
<input type="number" id="age" name="age" min="18" max="100"><br>
<label for="gender">Gender:</label>
<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><br>
<label for="country">Country:</label>
<select id="country" name="country">
<option value="usa">USA</option>
<option value="canada">Canada</option>
<option value="uk">UK</option>
</select><br>
<label for="message">Message:</label><br>
<textarea id="message" name="message" rows="4"></textarea><br>
<input type="checkbox" id="agree" name="agree">
<label for="agree">I agree to the terms and conditions</label><br>
<button type="submit">Submit</button>
<button type="reset">Reset</button>
</form>
These form elements allow users to interact with your website and submit data, which can then be processed on the server-side.