html5: Significance of attribute named required in checkbox/radio

naveen picture naveen · Feb 4, 2011 · Viewed 20.6k times · Source

On form submission, how could you possibly mark a checkbox/radiobutton as required?

Source of inspiration: Pekka's answer to a question

Answer

Emily picture Emily · Feb 5, 2011

Required checkboxes are not unusual. Practically every registration form uses some form of the "I have read and accept the User Agreement" checkbox.

If you have Opera handy try out the code below. The form won't submit unless the checkbox is checked.

<!doctype html>
<html>

<head>
  <title>html5</title>
</head>

<body>
  <h1>html5 test</h1>
  <form action="/">
    <input type="checkbox" required="required" id="cb" name="cb">
    <label for="cb">required checkbox</label>
    <input type="submit">
  </form>
</body>

</html>