Skip to main content

How do you make the simplest radio button in HTML?

The simplest radio button in HTML is created using the element <input type="radio">.

It lets the user pick one option out of several, for example gender, payment method or category.


1. The simplest example

html
<input type="radio">

A small circle appears on the page, which can be marked with a dot.


2. With a caption (via

So that the user understands what the radio button is for, a description text is added:

html
<label> <input type="radio"> Male </label>

Now clicking the text also activates the radio button.


3. A group of radio buttons

For several buttons to work as a single choice (only one active), they must all have the same name attribute, but different value values.

Example:

html
<form> <label><input type="radio" name="gender" value="male"> Male</label><br> <label><input type="radio" name="gender" value="female"> Female</label><br> <label><input type="radio" name="gender" value="other"> Other</label><br> <button type="submit">Submit</button> </form>

How it works:

  • Only one of the three options can be chosen.

  • On form submission the browser sends, for example:

    javascript
    gender=female

4. Commonly used attributes

AttributeWhat it doesExample
nameGroups radio buttons into one groupname="gender"
valueValue sent to the servervalue="male"
checkedMakes the button selected by defaultchecked
disabledDisables the button (cannot be chosen)disabled
requiredRequires a choice before submittingrequired

Example with a selected option:

html
<input type="radio" name="gender" value="male" checked> Male

5. Difference from checkbox

ElementBehavior
CheckboxSeveral options can be chosen
RadioOnly one option in a group can be chosen

Summary:

PropertyDescription
Tag<input type="radio">
PurposeSwitch (choosing one of several options)
GroupingVia the same name
Sending dataThe chosen value is sent
Often used with<label> for a caption

In simple terms: <input type="radio"> is a round button for choosing one option. The minimal code:

html
<input type="radio">

And with a caption and choice logic:

html
<label><input type="radio" name="gender" value="male"> Male</label>

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.