EN
HTML - radio input
0
points
In this article, we would like to show you how to create and use radio input elementin HTML.
Quick solution:
// ONLINE-RUNNER:browser;
<label>
<input type="radio" name="group-name" value="value-1" checked />
<span>Value 1</span>
</label>
<!-- or using id-for attributes relation: -->
<input type="radio" name="group-name" value="value-2" id="two" />
<label for="two" >Value 2</label>
Note:
With the
name
attribute we can assign radioinput
elements to the groups. Only one radio button at the time can be selected in each group.
Practical example
In this example, we create radio input using the input
element's type="radio"
attribute.
// ONLINE-RUNNER:browser;
<!doctype html>
<html>
<body>
<div>Select color:</div>
<label>
<input type="radio" name="color" value="red" checked />
<span>Red</span>
</label>
<label>
<input type="radio" name="color" value="blue" />
<span>Blue</span>
</label>
</body>
</html>