HTML Radio Buttons

HTML Radio Buttons: Making One Choice, Clearly

Radio buttons are used when you want users to pick just one option from a set — and only one. Whether you're asking for a favorite fruit or selecting a payment method, radio buttons help guide clean, exclusive decisions.

Creating a Single Group of Radio Buttons

Radio buttons are created using <input type="radio">. All buttons in the same group must share the same name. Each one should have a unique value and an id for labeling.

<p>Pick your favorite fruit:</p>
<input type="radio" id="apple" name="fruit" value="apple">
<label for="apple">Apple</label><br>

<input type="radio" id="banana" name="fruit" value="banana">
<label for="banana">Banana</label><br>

<input type="radio" id="cherry" name="fruit" value="cherry">
<label for="cherry">Cherry</label>
◯ Apple  
◯ Banana  
◯ Cherry

Only one button can be selected at a time. Selecting one automatically deselects the others.

Setting a Default Selection

Use the checked attribute to preselect a value:

<input type="radio" id="banana" name="fruit" value="banana" checked>
<label for="banana">Banana</label>
◉ Banana

This makes "Banana" the selected option when the page loads.

Radio Buttons Inside a Form

Let’s wrap them in a full form that users can submit:

<form action="/submit" method="post">
  <p>Choose one fruit:</p>

  <input type="radio" id="apple" name="fruit" value="apple">
  <label for="apple">Apple</label><br>

  <input type="radio" id="banana" name="fruit" value="banana">
  <label for="banana">Banana</label><br>

  <input type="radio" id="cherry" name="fruit" value="cherry">
  <label for="cherry">Cherry</label><br><br>

  <input type="submit" value="Submit">
</form>
Choose one fruit:
◯ Apple  
◯ Banana  
◯ Cherry  
[Submit]

Only one value (like "cherry") will be submitted with the form under the name fruit.

Grouping Radio Buttons with Fieldset

Use <fieldset> and <legend> for better organization and accessibility.

<fieldset>
  <legend>Pick one:</legend>

  <input type="radio" id="item1" name="choice" value="item1">
  <label for="item1">Item 1</label><br>

  <input type="radio" id="item2" name="choice" value="item2">
  <label for="item2">Item 2</label>
</fieldset>
Pick one:
◯ Item 1  
◯ Item 2

Best Practices

  • Use the same name for all options in a group
  • Label each radio button with <label> for usability
  • Use checked for default selections only when it makes sense
  • Group related radio buttons with <fieldset> and <legend>

Common Mistake to Avoid

Giving each radio button a different name prevents them from behaving as a group.

<!-- This will NOT work as expected -->
<input type="radio" name="apple" value="apple">
<input type="radio" name="banana" value="banana">

This will allow multiple selections — which defeats the point of radio buttons. Stick to a shared name.

Summary

Radio buttons are designed for exclusive choices. They are simple, intuitive, and easy to implement. You now know how to:

  • Create single-selection groups with <input type="radio">
  • Set default selections using checked
  • Group and label radio buttons semantically

Check your understanding 1

Which input type is used to create radio buttons in HTML?
Choose one answer. You can try again.

Answer and explanation

<code><input type="radio"></code>

To create a radio button, use <input type="radio">. Radio buttons are designed for selecting one item from a list of options.

Check your understanding 2

Radio buttons allow users to select more than one option at a time.
Choose one answer. You can try again.

Answer and explanation

False

Radio buttons are used for mutually exclusive choices. Only one option can be selected within the same name group.

Check your understanding 3

Choose the option that lists all and only the correct statements.

  1. Choosing gender: Male, Female, Other
  2. Selecting multiple subjects
  3. Choosing a preferred shift: Morning or Afternoon
  4. Selecting multiple clubs
Which of the following are best suited for radio buttons in a school form?
Choose one answer. You can try again.

Answer and explanation

Statements 1 and 3

Radio buttons work best for exclusive options like gender or shift. For multiple choices, such as clubs or subjects, checkboxes are more appropriate.

Check your understanding 4

How do you ensure that a group of radio buttons work as a single selection set?
Choose one answer. You can try again.

Answer and explanation

Assign the same <code>name</code> to each input

To make radio buttons part of the same group, they must share the same name attribute. That way, selecting one will unselect the others in that group.

Check your understanding 5

A radio button can be pre-selected using the checked attribute.
Choose one answer. You can try again.

Answer and explanation

True

You can make a radio button selected by default by including the checked attribute. For example: <input type="radio" checked>.

Check your understanding 6

Choose the option that lists all and only the correct statements.

  1. <input type="radio" name="gender" value="male" checked> Male
  2. <input type="radio" value="female"> Female
  3. <input type="radio" name="class" value="X"> Class 10
  4. <radio name="shift"> Morning
Which of these examples show correct usage of radio buttons?
Choose one answer. You can try again.

Answer and explanation

Statements 1 and 3

The first and third examples are valid radio button implementations. The second is missing the name attribute, which is necessary to group options. The fourth is invalid syntax — <radio> is not a valid HTML tag.

What’s Next?

Now that you’ve handled text inputs, checkboxes, and radio buttons — it’s time to dive into Textareas in HTML for larger, multi-line input fields.

Reaching the recap and completing the quizzes are separate milestones.

    Next lesson: HTML Textarea →