HTML chapters

Chapter 12 of 17

Forms, labels and input names

Try this in our HTML Compiler →

The idea

A form groups controls for submission. A label connects a description to a control through for and id. The name identifies a submitted value; id alone is not submitted. Choose a suitable input type and use a button with an explicit type. This example has no receiving service and does not store a response.

Worked example

<form>
  <label for="student">Student name</label>
  <input id="student" name="student" required>
  <label for="email">Email</label>
  <input id="email" name="email" type="email">
  <button type="button">Practice only</button>
</form>

What to check

Clicking a label focuses its input. The practice button does not send personal information anywhere.

Practice task

Add a labelled select for a favourite topic. Give the select a name and at least three options.

Check your understanding

Explain the result in your own words before changing the example. Change one thing at a time, compare the result with your prediction, and keep the version that demonstrates the concept clearly.

Try it yourself

Output
Ctrl/Cmd+Enter runs · Ctrl/Cmd+S downloads the project · Local auto-save is always on