1# Checkbox 2 3The **\<Checkbox>** component is used to enable or disable an option. 4 5> **NOTE** 6> 7> This component is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version. 8 9## Child Components 10 11Not supported 12 13## APIs 14 15Checkbox(options?: CheckboxOptions) 16 17Creates a check box. 18 19**Widget capability**: Since API version 9, this feature is supported in ArkTS widgets. 20 21**System capability**: SystemCapability.ArkUI.ArkUI.Full 22 23**Parameters** 24 25| Name | Type | Mandatory| Description | 26| ------- | ------------------------------------------- | ---- | ------------------ | 27| options | [CheckboxOptions](#checkboxoptions) | No | Check box parameters.| 28 29## CheckboxOptions 30 31| Name | Type| Mandatory | Description| 32| --------| --------| ------ | -------- | 33| name | [Length](ts-types.md#length) | No| Name of the check box.| 34| group | [Length](ts-types.md#length) | No| Group name of the check box (that is, the name of the check box group to which the check box belongs).<br>**NOTE**<br>For the settings to take effect, this parameter must be used with the [CheckboxGroup](ts-basic-components-checkboxgroup.md) component.| 35 36## Attributes 37 38In addition to the [universal attributes](ts-universal-attributes-size.md), the following attributes are supported. 39 40 41| Name | Type| Description| 42| ------------- | ------- | -------- | 43| select | boolean | Whether the check box is selected.<br>Default value: **false**<br>Since API version 9, this API is supported in ArkTS widgets.<br>Since API version 10, this attribute supports [$$](../../quick-start/arkts-two-way-sync.md) for two-way binding of variables.| 44| selectedColor | [ResourceColor](ts-types.md#resourcecolor) | Color of the check box when it is selected.<br>Default value: **$r('sys.color.ohos_id_color_text_primary_activated')**<br>An invalid value is handled as the default value.<br>Since API version 9, this API is supported in ArkTS widgets.| 45| unselectedColor<sup>10+</sup> | [ResourceColor](ts-types.md#resourcecolor) | Border color of the check box when it is not selected.| 46| mark<sup>10+</sup> | [MarkStyle](#markstyle10) | Internal icon style of the check box.| 47 48## Events 49 50In addition to the [universal events](ts-universal-events-click.md), the following attributes are supported. 51 52| Name | Description | 53| -------------------------------------------- | ------------------------------------------------------------ | 54| onChange(callback: (value: boolean) => void) | Triggered when the selected status of the check box changes.<br>- The value **true** means that the check box is selected.<br>- The value **false** means that the check box is not selected.<br>Since API version 9, this API is supported in ArkTS widgets.| 55 56## MarkStyle<sup>10+</sup> 57 58| Name | Type | Mandatory| Default Value | Description | 59| ----------- | ------------------------------------------ | ---- | ----------- | ------------------------------------------------------------ | 60| strokeColor | [ResourceColor](ts-types.md#resourcecolor) | No | Color.White | Color of the internal mark. | 61| size | number \| string | No | - | Size of the internal mark, in vp. The default size is the same as the width of the check box.<br>This parameter cannot be set in percentage. If it is set to an invalid value, the default value is used.| 62| strokeWidth | number \| string | No | 2 | Stroke width of the internal mark, in vp. This parameter cannot be set in percentage. If it is set to an invalid value, the default value is used.| 63 64## Example 65 66### Example 1 67 68```ts 69// xxx.ets 70@Entry 71@Component 72struct CheckboxExample { 73 74 build() { 75 Row() { 76 Checkbox({name: 'checkbox1', group: 'checkboxGroup'}) 77 .select(true) 78 .selectedColor(0xed6f21) 79 .onChange((value: boolean) => { 80 console.info('Checkbox1 change is'+ value) 81 }) 82 Checkbox({name: 'checkbox2', group: 'checkboxGroup'}) 83 .select(false) 84 .selectedColor(0x39a2db) 85 .onChange((value: boolean) => { 86 console.info('Checkbox2 change is'+ value) 87 }) 88 } 89 } 90} 91``` 92 93 94 95 96### Example 2 97 98```ts 99// xxx.ets 100@Entry 101@Component 102struct Index { 103 104 build() { 105 Row() { 106 Column() { 107 Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { 108 Checkbox({ name: 'checkbox1', group: 'checkboxGroup' }) 109 .selectedColor(0x39a2db) 110 .onChange((value: boolean) => { 111 console.info('Checkbox1 change is'+ value) 112 }) 113 .mark({ 114 strokeColor:Color.Black, 115 size: 50, 116 strokeWidth: 5 117 }) 118 .unselectedColor(Color.Red) 119 .width(30) 120 .height(30) 121 Text('Checkbox1').fontSize(20) 122 } 123 Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { 124 Checkbox({ name: 'checkbox2', group: 'checkboxGroup' }) 125 .selectedColor(0x39a2db) 126 .onChange((value: boolean) => { 127 console.info('Checkbox2 change is' + value) 128 }) 129 .width(30) 130 .height(30) 131 Text('Checkbox2').fontSize(20) 132 } 133 } 134 .width('100%') 135 } 136 .height('100%') 137 } 138} 139``` 140 141 142 143