htmlradio-button

How do you make the radio button text to be clickable too?


I have this radio button (and some other after this one):

<input type="radio" name="group1" value="Milk"> Milk<br>

But if I want to activate the radio button, I have to click it, clicking the word "Milk" which is to the right of the button, doesn't activate it. How can I do that?, all the examples I found about radio buttons so far, have the same issue.


Solution

  • Here you want to use the label tag.

    Something like:

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

    Labels tell the browser that everything contained within should be treated as one element (in terms of text. They are not divs)

    Take a look at this for an example: http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_label