Trusted answers to developer questions

Radio button in HTML

Get Started With Data Science

Learn the fundamentals of Data Science with this free course. Future-proof your career by adding Data Science skills to your toolkit — or prepare to land a job in AI, Machine Learning, or Data Analysis.

In HTML, a radio button is used to select one of many given choices. Radio buttons are shown in radio groups to show a set of related options, only one of which can be selected.

A radio button in HTML can be defined using the <input> tag.

Syntax

The general syntax of defining a radio button is:

Press + to interact
<input type="radio" name="ans"...>

Radio buttons with the same name property are grouped together, forming a radio group.

Below is an example:

Press + to interact
<!-- Creating radio buttons -->
<input type="radio" name = ".." value=".."> Label1 </br>
<input type="radio" name = ".." value=".."> Label2 </br>
<input type="radio" name = ".." value=".."> Label3 </br>
  • type: Input tag type attribute. This has to be “radio” when creating a radio button, but can also be other input types such as button, checkbox, file etc.
  • name: Specifies the name of an input element. Radio buttons with the same name form a radio group.
  • value: The value against a radio button that, if checked, is sent to the server.
svg viewer

Note: The <input> tag only creates a radio button. You have to insert the label yourself.


Radio button attributes

All of the <input> tag attributes can be used as radio buttons attributes such as checked, disabled, autofocus etc.


Examples

Here are some examples using input attributes for radio buttons:

1. Checked radio button

Maybe radio button is already checked when the form is loaded.

  • HTML

2. Disabled radio button

No radio button is disabled when the form is loaded.

  • HTML

RELATED TAGS

web
button
radio
html
web development
Copyright ©2024 Educative, Inc. All rights reserved
Did you find this helpful?