56 of 133 menu

The checkbox

A checkbox checkbox is an element (check mark or tick) of an HTML form that can have two states: checked and unchecked.

The checkbox is created using the input tag with the type attribute set to checkbox. The checkbox looks like this:

A checked checkbox will send the content of the attribute value to the server. If the checkbox does not have the attribute value, it will send the string "on". If the checkbox is not checked, nothing will be sent to the server regardless of the presence of the attribute value.

Example

Let's make two checkboxes: let the first one be checked (since it's given the checked attribute), and the second one not:

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

:

Example . Disabled checkbox

Let's look at the disabled checkbox with the attribute disabled. When you click on it, its state will not change:

<input type="checkbox" disabled>

:

Example . Locked and checked checkbox

Now let's disable the checkbox in the checked state with the disabled attribute and give it the checked attribute:

<input type="checkbox" disabled checked>

:

See also

  • radio switches,
    with which you can make a choice
  • attribute checked,
    which makes the checkbox checked
  • pseudo-class checked,
    which sets styles for checked checkboxes
  • attribute disabled,
    which blocks form elements
  • tag label,
    which sets the hint for the checkbox
enru