SyntaxStudy
Sign Up
HTML Beginner 1 min read

HTML Form Basics

HTML Form Basics

Forms are used to collect input from users. The <form> element wraps all form controls.

Key Attributes

  • action — URL to send form data to
  • method — HTTP method: get (data in URL) or post (data in body)

The <label> Element

Labels are linked to inputs via the for attribute matching the input's id. This improves accessibility — clicking the label focuses the input.

The <input> Element

The most versatile form element. Its behaviour depends on the type attribute.

Example
<form action="/submit" method="post">
  <label for="name">Full Name:</label>
  <input type="text" id="name" name="name" placeholder="Enter your name">

  <label for="email">Email:</label>
  <input type="email" id="email" name="email" placeholder="you@example.com">

  <button type="submit">Submit</button>
</form>