HTML input type checkbox Tutorial

In this section, we will learn what the HTML <input type = “checkbox”> element is and how to use it.

Checkbox in HTML: What is input type checkbox in HTML?

We use HTML <input type = “checkbox”> element when we want to add a checkbox field to our document.

There are many different use cases for the checkbox element in a document.

For example, there might be a form on a webpage that asks you to pick one or more mobile phone brands! Well, using the checkbox element, we can add a list of brands to our document and users only need to check any of those brands they want!

HTML input type checkbox Syntax:

<input type = “checkbox” value = “value”>

HTML input type checkbox Values

When working with an input of type checkbox, it’s important to set a value for the `value` attribute as well!

This is because checkbox elements don’t take values directly from users!

So we put a predefined value for each checkbox and when or if that checkbox is clicked, the value of the `value` attribute for that clicked checkbox will be submitted to a server along with the other form data.

Example: using <input type=”checkbox”> in HTML

See the Pen using <input type="checkbox"> in HTML by Omid Dehghan (@odehghan) on CodePen.


Top Technologies