How to Add Radio Button in HTML
In this article, we will learn almost everything about HTML Radio Button and also learn how you can Add Radio in HTML.
What is HTML Radio Button
<input type="radio"> element is used to create a radio button in HTML.
"radio" is a form control that allows the user to select only one option from a set of predefined options. Radio buttons are often used in forms to get user’s input, such as selecting a single option from a list of options.
Here is an example of an HTML form that uses radio buttons. And you will also find out how you can add radio button in html.
<!DOCTYPE html> <html> <head> </head> <body> <form> <label> <input type="radio" name="gender" value="male"> Male </label> </br> <label> <input type="radio" name="gender" value="female"> Female </label> <label> </br> <input type="radio" name="gender" value="other"> Other </label> </form> </body> </html>
In the above code the
type attribute of an
<input> element is set to
"radio" to create a radio button. The
name attribute is used to group related radio buttons together, so that only one can be selected from the group. Each radio button in the group should have the same
name attribute value. The
value attribute specifies the value that is submitted to the server when the radio button is selected.
It is important to always provide a label for each radio button to give users a clear and accessible description of the purpose of the radio button. Labels can be associated with radio buttons using the
<label> tag and the
for attribute. We will learn more about it in our HTML <label> Element.
SHARE THIS POST!