MyInternships.in

HTML Basics

HTML Forms

Forms let visitors send information to a website — logging in, searching, or applying for a job. This page covers the form element and the controls that go inside it.


What is an HTML Form?

A form is a section of a page that collects user input. It is defined by the <form> element and contains controls such as text fields, checkboxes, dropdowns, and buttons. When submitted, the form sends its data to a server.

The most common control is <input>, whose type attribute decides its behaviour — text, email, password, checkbox, radio, and many more. Each control should have a <label> so users know what it is for.

Basic Usage

A labelled text field
Example
<form>
  <label for="name">Name:</label>
  <input type="text" id="name" name="name">
  <button type="submit">Send</button>
</form>

Example: A Simple Contact Form

Several input types together
Example
<!DOCTYPE html>
<html>
<body>
  <form style="display:grid; gap:10px; max-width:320px;">
    <label for="fullname">Full name</label>
    <input type="text" id="fullname" name="fullname" placeholder="Asha Kumar">

    <label for="email">Email</label>
    <input type="email" id="email" name="email" required>

    <label for="msg">Message</label>
    <textarea id="msg" name="msg" rows="3"></textarea>

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

More Examples

Checkboxes, radios, and a dropdown
Example
<!DOCTYPE html>
<html>
<body>
  <form>
    <p>Skills:
      <input type="checkbox" id="html" name="skill"> <label for="html">HTML</label>
      <input type="checkbox" id="css" name="skill"> <label for="css">CSS</label>
    </p>
    <p>Level:
      <input type="radio" id="beg" name="level"> <label for="beg">Beginner</label>
      <input type="radio" id="adv" name="level"> <label for="adv">Advanced</label>
    </p>
    <label for="city">City</label>
    <select id="city" name="city">
      <option>Bengaluru</option>
      <option>Mumbai</option>
      <option>Pune</option>
    </select>
  </form>
</body>
</html>

Common Input Types

typeControl
textA single-line text box.
emailText box that checks for an email format.
passwordText box that hides characters.
numberA numeric input with spinner arrows.
checkboxA box that can be ticked on or off.
radioOne choice from a group of options.
dateA date picker.
submitA button that submits the form.
💡

Always connect a <label> to its input using for="id". Clicking the label then focuses the field, and screen readers announce the label — a big accessibility win.

⚠️

Never trust form data on its own. Always validate and sanitise input on the server too, because attributes like required can be bypassed.

Key Takeaways

  • A <form> collects user input and sends it to a server.
  • The <input> type attribute defines each control's behaviour.
  • Pair every control with a <label> for accessibility.
  • Use <textarea> for long text and <select> for dropdowns.

Related HTML Topics

Keep learning with these closely related tutorials.

Ready to use your HTML skills?

Find web development internships and fresher jobs across India.

Browse Web Dev Internships