HTML Radio Button — Working Code and Common Patterns
A radio button is `<input type="radio">`. Multiple radios with the same `name` attribute form a group; only one can be selected at a time. Complete reference with code, common gotchas, and a working form.
An HTML radio button is `<input type="radio">`. By itself, one radio is a useless checkbox alternative — radios become useful when grouped. Group radios by giving multiple `<input type="radio">` elements the same `name` attribute. The browser enforces single selection across the group: clicking one deselects the others.
Wrap radio groups in a `<fieldset>` with a `<legend>` for accessibility. The fieldset semantically groups related inputs, and screen readers announce the legend when the user focuses any radio inside. This is the difference between an accessible radio group and a confusing list of unlabeled choices.
Each radio needs a `value` attribute — that's what gets submitted with the form. The value is what your backend receives; the visible label text (next to the radio) is just for the user. Avoid relying on `checked` for the default — if you need a default selected option, set `checked` on the appropriate radio in HTML. If no radio is `checked` initially and the group is `required`, the form won't submit until the user picks one.
Common gotcha: forgetting the `name` attribute. A radio without a name is selectable but the user can pick multiple at once (because the browser has no group to enforce uniqueness against). Always give all radios in a group the same name — that's what makes them mutually exclusive.
How to set this up
Use <input type="radio">
Each option is one input element. Don't use checkboxes for single-choice questions — radios are the right semantic choice.
Group with the name attribute
Every radio in a group shares the same name. That's what makes them mutually exclusive.
Wrap in <fieldset> + <legend>
Semantic grouping for accessibility. Screen readers announce the legend when any radio in the group is focused.
Add required for mandatory choices
Set required on at least one radio in the group; the browser enforces a selection before submission.
Same name attribute = mutually exclusive group. That's the whole trick.
Frequently asked questions
What is a radio button in HTML?
An HTML radio button is an `<input type="radio">` element that lets the user pick exactly one option from a group of mutually-exclusive choices. Radios with the same `name` attribute form a group; selecting one deselects the others.
How do I make only one radio button selectable?
Give all the radio inputs the same `name` attribute. The browser automatically enforces single selection across radios with matching names.
How do I set a default selected radio button?
Add the `checked` attribute to the radio that should be selected by default: `<input type="radio" name="x" value="a" checked>`. Only set checked on one radio per group.
How do I require a radio button selection?
Add `required` to at least one radio in the group. The browser blocks form submission until the user selects one.
How do I get the selected radio value in JavaScript?
Use `document.querySelector('input[name="yourname"]:checked').value` to read the value of the currently-selected radio in the group.
Should I use a radio button or a dropdown?
Use radios when there are 2-5 options and you want all of them visible. Use a <select> dropdown when there are more options or screen space is tight. Radios are faster to scan when the list is short; dropdowns scale better.
Related guides
Ship the form, not the backend.
Free for 1,000 submissions/month. Email delivery, AI spam filtering, signed webhooks, real dashboard — all on the free plan. No credit card.
Get a free access key →