<form> Tag — HTML Technical Interview Questions & Answers

A container for interactive controls submitted together.

<form> Tag

  • A container for interactive controls submitted together.
  • <form> is a group of inputs that submit together. HTML uses this tag so the browser (and screen readers) know what the piece is, not only how it looks.
  • Board: <form method="post">…</form> Put it in body. Check it in the browser. Attributes go on the opening tag.
  • Trap: inputs outside form with no JS plan. CSS can still style it — don’t pick a tag only because of default italics.
  • Interview: name the tag, one attribute if it has a famous one (href, src, alt, for, type), one mistake.

Technical Interview Tip: <form>: a group of inputs that submit together. Example: <form method="post">…</form>

Code Examples for <form> Tag

<form> Tag — working example

<form action="/login" method="post">
  <fieldset>
    <legend>Sign in</legend>
    <label for="email">Email</label>
    <input id="email" name="email" type="email" required autocomplete="username" />
    <label for="password">Password</label>
    <input id="password" name="password" type="password" required autocomplete="current-password" />
    <label>
      <input type="checkbox" name="remember" value="1" />
      Remember me
    </label>
  </fieldset>
  <button type="submit">Sign in</button>
</form>

<form> Tag — forms POST sensitive data; label+id (or wrapping label) ties text to controls for accessibility.

How to Explain <form> Tag to an Interviewer

What is the <form> tag?

a group of inputs that submit together <form method="post">…</form>

One common mistake?

inputs outside form with no JS plan