Format Code Now
/

HTML Radio Button Generator

WM-60

List your choices and get a group of radio buttons that share one name, each with a linked label, inside a fieldset with a legend.

Runs in your browser. Nothing is uploaded.

One choice per line, plus optional name: and legend: lines

HTML

How to use it

  1. Add a legend: line to name the question, and an optional name: line for the field name.
  2. Write one choice per line. Start with [x] to select one, or write Label | value to set the value.
  3. Pick the label style and whether each choice gets a div.
  4. Copy the HTML into your form.

How radio groups work

Radio buttons that share the same name form one group, and the browser lets the user select only one of them. Choosing another clears the previous one, and the arrow keys move through the group once it has focus. The form sends the name with the value of the selected button; if none is selected, nothing is sent for the group. A button with no value attribute sends the text on, so the tool always sets a value, built from the label or taken from the text after a vertical bar.

Default choice and required

Mark one choice with [x] to have it selected on load, which is a good idea when one answer is by far the most common. Only one line may have it; the tool refuses two. Required on any one radio in a group applies to the whole group, so the tool puts it on the first button when you tick Required. The user then has to pick something before the form submits. Without a default and without required, an unanswered group is simply absent from the data.

Labels, legend and ids

Each radio needs its own label, so the click target is larger and a screen reader can read the choice. The legend names the group: without it, a person using a screen reader hears the options with no question. The tool numbers the ids from the name, such as shipping-1 and shipping-2, because ids must be unique on the page. Choices with the same value are refused, since the server could not tell them apart.

Error messages and what to do

MessageWhat it meansFix
Only one radio button in a group can be ticked: remove the extra [x].More than one line starts with [x].Keep [x] on one line only.

Questions people ask

How do I group radio buttons in HTML?

Give them all the same name attribute. Only one in the group can be selected. Wrap them in a fieldset with a legend so the group has an accessible name.

How do I select a radio button by default?

Add the checked attribute to one input. Start that line with [x] in this tool. Only one radio per group can start selected. Users can still pick another option, and the original default is restored if the form is reset.

What does a radio button send when nothing is selected?

Nothing. The group is missing from the submitted data. Add required, or choose a default, if you need an answer. Browsers do not send a value for a group with no selection, which is why a default or a required check helps.

Should radio buttons or a select be used?

Radio buttons show every choice at once and suit up to about five options. A select saves space for long lists. Use radios when users should compare the choices.

Why do I need a different id for each radio?

An id must be unique in the page, and each label points at its input by id. The tool numbers them for you, such as topic-1 and topic-2.

About this tool

Every line becomes one radio button with a label. Radio buttons that share a name form a group in which only one can be chosen, so all lines get the same name. Start a line with [x] to select it by default; only one line can have it. Write Label | value to set the submitted value, otherwise it is made from the label. The Required option puts required on the first button, which applies to the whole group. If nothing is chosen, the browser sends nothing for the group. A group of two or more choices needs a legend line. Text and attribute values are escaped.

Format Code Now: free, no ads, no accounts. Your input stays in your browser.