HTML CheckBox Label | Checked Value, Group, Disable, onclick, onchange, and Example

HTML CheckBox Label is used to giving a selected option to the user. Where a user can select any one of them. Like a select the gender, then you can give an option to user – Male or Female. Based on the selected option you can get the value from the checkbox.

HTML CheckBox Label Checked Value, Group, Disable, onclick, onchange, and  Example


Use HTML <input> tag with type=”checkbox”, it will show you checkbox.

In this tutorial, you will learn about every thing of HTML CheckBox Label. How to use it, set and get the value from the CheckBox, what if the CheckBox is not checked? Grouping of Checkbox, Is it possible to do Single or multiple selections. Also How to disable and perform onClick event on the CheckBox button in HTML with an examples.

HTML CheckBox Example

A simple example, many places you saw this form to fill your detail. Example registration form of facebook.

Checked CheckBox

Here is an example, how you can do html checkbox checked (pre selected). Just use a checked attribute in the input tag.

HTML checkbox Checked/Unchecked

As you know HTML check box have 2 state, checked and Unchecked. It’s a simply have True or False for it. It required to know the state of HTML checkbox unchecked or checked. Let’s see the example of it how you can get the validate checkbox.

You have to use a HTML CheckBox onclick attribute for that. Don’t forget to add unique id to every element.

You will <script> tag with some function. This is a JavaScript, we will learn about in a diffrent tutorial.

Output: A GIF output of upper example

HTML CheckBox Label Checked Value, Group, Disable, onclick, onchange, and  Example

Get The value from CheckBox

Getting the value of Checkbox either it’s checked or not. You have to define it in a form tag then input with a value of it. See the below example How to get the HTML CheckBox checked value and HTML CheckBox value if not checked.

In the example we are using a button type ( to perfomat action), javascript and if condition statement. If Checkbox is checked the only value of it show in the alert box.

Output: In A GIF

value from HTML CheckBox checked example

HTML CheckBox Group

If you want a Multiple HTML checkboxes, you can do it but here is some conditions. Like in a group if you want select only on value then it’s hard way to do it with a CheckBoxs.

The better ways is do it with Radio Label (button).

  • Grouping Radio buttons
  • Act like Radio
  • Allow unselecting all

Examle 1. HTML checkbox group single selection

For it you need first add java script source in <head> tag.

Then do like below example.

Output: In GIF

HTML checkbox group single selection example output

Example 2. HTML checkbox group multiple selections.

A very simple example, not need to do use java script.


HTML checkbox group multiple selections example output output

Disabled CheckBox

How HTML checkbox disabled? and why? Just Write a “disabled” attribute to not allow input. It is used when your item of selection is generated after some selection like a choice for Veg and non-veg. Then according to choice just disable those checkboxes.

See the below simple example of it. You have doubt on terms- Attribute, elements, and Tag. Then follow this tutorial- HTML Basic | Definition | Tags and attributes | Elements

HTML checkbox onchange 480

HTML checkbox required almost every web application to make the user experience better. If you have any doubt and suggestion then do comment in below.

Note: The All HTML CheckBox Button Examples are tested on Safari browser (Version 12.0.2).
OS: macOS 10.14 Mojave

Code: HTML 5 Version

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.