codegurukool.com · Free coding tutorials & online compiler

Home › HTML Tutorial › Forms

Forms

Collect input from people with form controls.

Pair every input with a label. The required attribute makes the browser check the field before sending.

Commands in this lesson

input

Definition: Form control where the user types or chooses a value.

Syntax:

<input type="text" name="n">

Example:

<input type="text" placeholder="Your name">

label

Definition: Caption tied to a form control. Clicking it focuses the field.

Syntax:

<label for="id">Text</label>

Example:

<label for="n">Name</label> <input id="n">

required

Definition: Attribute that forces a field to be filled before submit.

Syntax:

<input required>

Example:

<form><input required><button>Send</button></form>

Example code

<form>
  <label>Name <input name="n" required></label><br><br>
  <label>Email <input type="email" name="e"></label><br><br>
  <label><input type="checkbox"> Subscribe</label><br><br>
  <button>Send</button>
</form>

Run this code in the online editor

← Lists and tablesSemantic layout →