The checked attribute

The checked attribute makes a checkbox checkbox or a radio button radio checked by default.

Is an attribute without a value.

Example . Checkboxes

In the following example, two checkboxes are created: the first one will be checked (since it is given the checked attribute), and the second one will not:

html<input type="checkbox" checked>
<input type="checkbox">

Результат:

Example . Radio switches

Let's make two radio switches - the first one will be checked (since we'll give it the checked attribute), and the second one won't:

html<input type="radio" name="radio" checked>
<input type="radio" name="radio">

Результат:

See also

  • pseudo-class checked,
    which sets styles for the marked elements
  • attribute selected,
    which makes the select item checked