A form should feel easy to use. The visitor sees a question, gives an answer, and needs to know what will happen next.
What You Need to Know
Pattern checks the username shape and type=email checks basic email syntax. Only the server can verify whether either is already registered.
Try the Example
Take a look at the example. We’ll explain the important lines right below it.
<form action="/register" method="post">
<label for="username">Username</label>
<input id="username" name="username" pattern="[A-Za-z0-9_]{4,15}" required>
<label for="email">Email</label>
<input id="email" name="email" type="email" required>
<button type="submit">Check registration</button>
</form>
Let’s Read the Code
- name: The name is the key used for the submitted value.
- <form>: The form groups controls and identifies where submitted data goes.
- <label>: The label tells people what the input is for. A matching for/id pair makes the label clickable.
- for: For connects a label or output with a control by ID.
Read the named elements and attributes together. They explain how the browser connects this feature to the rest of the page.
What Happens in the Browser?
The HTML controls work in the browser, but saving an answer requires the example action path to be handled by a real server.
Where does the answer go? The example uses the submitted name(s) username, email. Those names help the receiving server identify each answer. A label is for people; a name attribute is for the form data; an ID connects elements in the page.
Your Turn
Enter two syntactically valid names and explain why one could still be unavailable.
Common Beginner Mistakes
- Copying the example without giving the fields a clear label and a usable name.
- Never claim a name is available until the server has checked it.
Key Takeaways
- Choose the HTML feature that explains this task clearly.
- name: The name is the key used for the submitted value.
- Test the behavior you expect rather than trusting how the snippet looks in your editor.