Search code examples
htmlforms

How to make clicking on the text in a radio input selects the corresponding button?


Basically, just the text can be clicked to have the same effect as clicking the button in a form that has the input type as radio.

For example:

<input type="radio">(Random input)

That but instead of having to press the button, you just need to press the text (in this case "Random input")

This might be a stupid question but I am just starting to learn HTML


Solution

  • I add code below.

    -html

    <label>
      <input type="radio" name="group1" value="Milk">
      Milk
    </label>
    

    label tag means that the browser'll treat everything in it as one element.

    I think this answer will help you enoughly.