HTML Page Structure

HTML Elements
HTML Attributes


HTML Checkbox Tag

You know that you can use radio button when you want the user to select only one option from a set of options/alternatives. In the same way, if you want that the user can chose one or more options, you can use "checkbox" using the <input> tag making it's type equals to "checkbox".

It has three required attributes type, name and value. There are two optional attributes also and those are id and checked.

Syntax

<form>
	<input type="checkbox">
</form>

Example

<!DOCTYPE html>
<html>
<head>
<title>My HTML Checkbox Input Tag Example</title>
</head>
<body>
<form>
      What is/are your favourite color/s?
      <p>
        <input type="checkbox" name = "color" value="r"/>Red
     </p>
      <p>
        <input type="checkbox" name = "color" value="y"/>Yellow
      </p>
	  <p>
        <input type="checkbox" name = "color" value="g"/>Green
      </p>
	  <p>
        <input type="checkbox" name = "color" value="b"/>Blue
      </p>
</form>
</body>
</html>

This will produce following result

What is/are your favourite color/s?

Red

Yellow

Green

Blue