ons-checkbox

A checkbox element. The component will automatically render as a Material Design checkbox on Android devices. Most attributes that can be used for a normal <input type="checkbox"> element can also be used on the <ons-checkbox> element.

Tutorial

Checkboxes

Checkboxes are defined using the <ons-checkbox> element. The element works almost exactly as when you use a normal <input type="checkbox"> element.

<ons-checkbox value="something" checked></ons-checkbox>

Inner input element

For normal input elements is possible to define a <label> tab with the for attribute to link it to an input element.

Unfortunately this does not work with custom elements like <ons-label> so in order to do it we need to set the id attribute of the inner input element. This is done using the input-id attribute.

<label for="username">Username</label>
<ons-input input-id="username"></ons-input>

This work with any input in Onsen UI such as checkboxes, radios, etc.

See also

Attributes

Attributes are added directly to the element. You can do this in HTML or JS.

HTML: <ons-checkbox someAttribute="true" anotherAttribute><ons-checkbox>
JS: document.querySelector('ons-checkbox').setAttribute('someAttribute', 'true')

Name Type Description
input-id String Specify the “id” attribute of the inner <input> element. This is useful when using <label for="..."> elements. Optional.

Properties

Properties are accessed on the element through JS, and should be get and set directly. For example: document.querySelector('ons-checkbox').value.

Name Description
value The current value of the checkbox.
checked Whether the checkbox is checked or not.
disabled Whether the checkbox is disabled or not.

Preset Modifiers

Modifiers are set in the modifier attribute. To use more than one, separate them by spaces. For example:
<ons-checkbox modifier="material noborder"><ons-checkbox>.

Name Description
material Displays a Material Design checkbox.
noborder iOS borderless checkbox.

Need Help?

If you have any questions, use our Community Forum or talk to us on Discord chat. The Onsen UI team and your peers in the community will work together to help solve your issues.

For bug reports and feature requests use our GitHub Issues page.