How to insert a checkbox in HTML?

The checkbox is a type of input tag in HTML. Checkboxes are used for instances where a user may want to select multiple options for example, in cases where you can check all the options that apply to your case.

Note: A checkbox is used when the option is either yes or no.

Syntax

The syntax to insert a checkbox is:

<input type = "checkbox"> 

The checkbox is shown as a square box which on click is filled in.

Checkboxes allow users to select one or more options amongst a limited number of choices.

In the below code “I have an apple” is already selected. This is done by the boolean attribute checked. It specifies that an <input> element is pre-selected (checked) when the page loads.

The syntax of pre-selecting the checkbox using the checked attribute is as follows:

input type = "checkbox" checked> Already selected checkbox
Copyright ©2024 Educative, Inc. All rights reserved