Think of filling out a sign-up page. Clear fields make the job simple; confusing fields make people leave.
What You Need to Know
This example uses the browser’s built-in radio control, so you do not have to create a picker from scratch.
In this example: select one delivery method.
Try the Example
Take a look at the example. We’ll explain the important lines right below it.
<form action="/choose-plan" method="post">
<fieldset>
<legend>Choose your plan</legend>
<label><input type="radio" name="plan" value="basic" checked> Basic</label>
<label><input type="radio" name="plan" value="plus"> Plus</label>
</fieldset>
<button type="submit">Continue</button>
</form>
Let’s Read the Code
- <form>: The form groups controls and identifies where submitted data goes.
- <fieldset>: The fieldset keeps related choices together.
- type: Type changes what sort of control or resource the browser uses.
- name: The name is the key used for the submitted value.
What the example shows: Radio buttons with the same name act as one choice group.
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.
What gets sent? With ordinary form submission, the browser builds a set of name/value entries. For checkboxes, only checked choices are normally included. Radio buttons in the same group contribute one selected value. Open the browser Network panel to see the request rather than guessing.
Your Turn
Change both name attributes to different values and see why that breaks the single-choice behavior.
Common Beginner Mistakes
- Copying the example without giving the fields a clear label and a usable name.
- Use a fieldset and legend to identify the whole question.
Key Takeaways
- A control needs a clear label and, when submitted, a meaningful name and value.
- <form>: The form groups controls and identifies where submitted data goes.
- Remember that HTML form rules help the visitor, but server-side code must decide whether received data is valid.