Trusted answers to developer questions

How to insert a checkbox in HTML?

Free System Design Interview Course

Many candidates are rejected or down-leveled due to poor performance in their System Design Interview. Stand out in System Design Interviews and get hired in 2024 with this popular free course.

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

RELATED TAGS

html
checkbox
input
Copyright ©2024 Educative, Inc. All rights reserved
Did you find this helpful?