Radio button in HTML
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:
<input type="radio" name="ans"...>
Radio buttons with the same name property are grouped together, forming a radio group.
Below is an example:
<!-- 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 asbutton,checkbox,fileetc.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.
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.
2. Disabled radio button
No radio button is disabled when the form is loaded.
Free Resources