How to select a radio button by default


  • radio button html - Got some radio buttons and need to set as selected by default when the web page is loaded. How can we do that?

html code :

<input type="radio" name="imgsel" value="" />

Solution 1:

XHTML code :

<input type="radio" name="imgsel" value="" checked="checked" />
  • Please note, that the actual value of checked attribute does not actually matter; it's just a convention to assign "checked". Most importantly, strings like "true" or "false" don't have any special meaning.

If we don't aim for XHTML conformance, we can simplify the html code to:

<input type="radio" name="imgsel" value="" checked>

Solutions 2:

  • we can use the html radio checked attribute.
<input type="radio" name="imgsel" value="" checked />
<input type="radio" name="imgsel" value="" checked="checked" />

Solution 3:

html5 radio button using AngularJS - And actually the normal answer won't work. our html will look pretty similar to the normal radio button:

<input type='radio' name='group' ng-model='mValue' value='first' />First
<input type='radio' name='group' ng-model='mValue' value='second' /> Second

Solution 4:

  • In our controller we declared the mValue that is associated with the radio buttons. To have one of these radio buttons preselected, assign the $scope variable associated with the group to the desired

radio button selected :

  • This makes the "second" html radio checked on loading the page

Solution 5:

Add this attribute to the radio button checked code :


Related Searches to How to select a radio button by default