Back to HTML

Checkboxes and Radio Buttons in HTML

Coding Tutorials Team 30 June 2026

Checkboxes and radio buttons look similar and behave differently in ways that matter. Both also share one behaviour that catches out anyone processing form data for the first time.

Checkboxes are independent

Each checkbox is its own control, and any number can be selected. Use them when the answer is zero or more.

<input type="checkbox" id="news" name="topics" value="news"> <label for="news">Industry news</label> <input type="checkbox" id="tips" name="topics" value="tips"> <label for="tips">Practical tips</label>

Sharing a name across several checkboxes is how you collect multiple values under one key. Many server languages need the name written with brackets appended to receive them as an array, which is a convention of those languages rather than anything in HTML.

Radio buttons are exclusive

Radio buttons in the same group allow exactly one selection, and choosing another deselects the first.

<input type="radio" id="plan-free" name="plan" value="free" checked> <label for="plan-free">Free</label> <input type="radio" id="plan-pro" name="plan" value="pro"> <label for="plan-pro">Pro</label>

The grouping comes entirely from the shared name attribute. Nothing about the markup structure creates it, which means two radio groups on one page must use different names or they will interfere with each other. This is the most common radio button bug and it presents as options in one question deselecting options in another.

Unchecked controls send nothing

Here is the behaviour that surprises people. An unchecked checkbox does not submit an empty value or a false value. It submits nothing at all, and the key is simply absent from the data the server receives.

Server code therefore has to test whether the key exists rather than examining its contents. Checking whether a value equals false will never be true, because the value never arrives.

The established workaround for a single yes or no field is a hidden input with the same name placed immediately before the checkbox. The hidden field always submits, the checkbox overrides it when checked, and the server always receives a value. Many frameworks generate this automatically.

The value attribute matters

A checked control with no value attribute submits the string on, which is rarely useful. Always set an explicit value describing what the option means.

Radio buttons need this even more, since the whole group shares a name and the value is the only thing distinguishing which option was chosen.

Preselecting an option

The checked attribute is boolean, so its presence selects the control and its absence does not. Writing it with a value of false still selects it, because the browser only checks whether the attribute exists.

Radio groups should almost always have one option checked by default. A group with none allows the user to submit without answering, and because radio buttons cannot be deselected once chosen, a user who clicks the wrong one has no way to return to an unanswered state. Where no answer is genuinely valid, include an explicit option saying so.

Choosing between them and a select

Radio buttons show every option at once, which suits a small set where comparison matters. A select dropdown hides the options behind an interaction, which suits longer lists where the user knows what they are looking for.

The rough threshold is around five options. Below that, radio buttons are usually easier to use, particularly on touchscreens where opening a dropdown and scrolling it is more work than tapping a visible choice.

Grouping with fieldset

A set of radio buttons answers a question, and that question needs to be associated with the group. A fieldset containing a legend provides it.

Without one, a screen reader announces each option label with no indication of what is being asked, so the user hears free and pro with no idea that the question was about a plan.

The indeterminate state

A checkbox has a third visual state beyond checked and unchecked, showing a dash rather than a tick. It represents a partial selection, most familiar from a parent checkbox above a list of children where some but not all are selected.

It can only be set from JavaScript, not from an attribute, and it is purely visual: an indeterminate checkbox still submits according to whether it is actually checked. Treating it as a third value that the server will receive is a misunderstanding worth avoiding.

Styling them

Native controls are difficult to style consistently. The modern approach uses the appearance property to strip the default rendering and then styles the control directly, which keeps a real input in the markup with all its keyboard and accessibility behaviour intact.

The older technique hid the input and styled a sibling label, which works but relies on the hidden input remaining focusable. Whichever route you take, ensure the focus state is clearly visible, since a keyboard user has no other way to know which option they are on.