ADVERTISEMENT
Google AdSense Slot (headerLeaderboard)

Set your Publisher ID in src/config/ads.ts to display live ads.

HTML5 Tutorial• 6 min read

HTML Forms & Inputs

Collecting user input with textboxes, checkboxes, and buttons

HTML forms are used to collect user input. The user input is most often sent to a server for processing.

The <form> Element and Input Types

The <form> element is a container for different types of input elements, such as text fields, checkboxes, radio buttons, and submit buttons.

The <input> element is the most important form element, controlled by its type attribute.

Complete User Registration Form
<form action="/submit" method="POST" style="max-width: 320px; font-family: sans-serif;">
  <label for="fname">First Name:</label><br>
  <input type="text" id="fname" name="fname" placeholder="John" required style="width: 100%; margin: 6px 0 12px 0; padding: 6px;"><br>

  <label for="email">Email Address:</label><br>
  <input type="email" id="email" name="email" placeholder="john@example.com" required style="width: 100%; margin: 6px 0 12px 0; padding: 6px;"><br>

  <label for="pass">Password:</label><br>
  <input type="password" id="pass" name="pass" required style="width: 100%; margin: 6px 0 12px 0; padding: 6px;"><br>

  <input type="checkbox" id="terms" name="terms" required>
  <label for="terms"> I agree to the Terms</label><br><br>

  <button type="submit" style="background-color: #04AA6D; color: white; padding: 10px 20px; border: none; cursor: pointer; border-radius: 4px; font-weight: bold;">
    Register Account
  </button>
</form>
Pro Tip

Always pair inputs with a <label> element using the for attribute matching the input's id. This dramatically improves accessibility and tap targets on mobile devices.

ADVERTISEMENT
Google AdSense Slot (inContentBanner)

Set your Publisher ID in src/config/ads.ts to display live ads.

Test Yourself With Exercise

+15 XP

Which input type is specifically designed to safely hide entered passwords with bullets or asterisks?