Fieldset groups related form questions, and legend gives the group a label. Radio choices are easier to understand when users hear the question before the options. We will keep the example small, so you can see how the fields work without building a whole application first.
What You Need to Know
Radio buttons in one group share the same name so only one can be chosen. Use a clear legend instead of relying only on spacing or color.
A form is like a question sheet. The label asks the question, the control holds the answer, and the name tells the receiving application what that answer is called.
Example: See It in Action
Add this example to the appropriate part of a practice HTML page. Read each line before you open the page in your browser.
This is a short HTML fragment. To try it as a webpage, put it inside the body element of a complete HTML document.
<form action="/survey" method="post">
<fieldset>
<legend>Preferred activity</legend>
<label><input type="radio" name="activity" value="art"> Art</label>
<label><input type="radio" name="activity" value="sports"> Sports</label>
</fieldset>
<button type="submit">Submit</button>
</form>
Let’s Understand the Example
- Fieldset groups controls that answer one question or belong together.
- Legend names a fieldset so the group makes sense.
- Action names the destination where the browser sends a form submission. A real server handler must exist there.
- Method controls how a form submits; GET makes values part of the URL, while POST sends them in the request body.
- Type changes the kind of input, script, resource or button, depending on the element.
- Name is the key the browser normally sends when a form control is submitted.
The browser can submit values with keys such as activity. A control without a name normally contributes no entry. Whether the submission produces a result depends on the action URL and the server behind it.
What Should You See?
You should see controls for Art, Sports. The example uses an input of type radio and sends a POST request when submitted. If the action points to a missing server endpoint, the browser cannot complete the task.
Choose one field and predict its submitted name and value. Then change the value and check whether the browser accepts it. Do not assume that a working-looking form has a real server behind it.
Try It Yourself
- Add a third activity option that belongs to the same group.
- Save your changes, open or refresh the page, and compare the result with the original example.
- Tell a friend what your change did. If you are not sure, undo it, refresh the page, and compare.
Common Beginner Mistakes
- Giving each radio choice a different name and allowing both to be selected.
- Client-side HTML validation is a helpful first check, not a security boundary. A real receiving application must validate the values again.
Key Takeaways
- Fieldset groups related form questions, and legend gives the group a label.
- Fieldset groups controls that answer one question or belong together.
- Radio buttons in one group share the same name so only one can be chosen. Use a clear legend instead of relying only on spacing or color.