Languages
[Edit]
EN

HTML - radio input

0 points
Created by:
Palpys
734

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 radio input 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>

References

Alternative titles

  1. HTML - input type radio
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

HTML - input element types

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join