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?: {name?: string, group?: string }) 16 17Since API version 9, this API is supported in ArkTS widgets. 18 19**Parameters** 20 21| Name | Type| Mandatory | Description| 22| --------| --------| ------ | -------- | 23| name | string | No| Name of the check box.| 24| group | string | No| Group name of the check box.<br>**NOTE**<br>If not used with the **\<CheckboxGroup>** component, this parameter is invalid.| 25 26## Attributes 27 28In addition to the [universal attributes](ts-universal-attributes-size.md), the following attributes are supported. 29 30 31| Name | Type| Description| 32| ------------- | ------- | -------- | 33| 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.| 34| selectedColor | [ResourceColor](ts-types.md#resourcecolor) | Color of the check box when it is selected.<br>Since API version 9, this API is supported in ArkTS widgets.| 35| unselectedColor<sup>10+</sup> | [ResourceColor](ts-types.md#resourcecolor) | Border color of the check box when it is not selected.| 36| mark<sup>10+</sup> | [MarkStyle](#markstyle10) | Internal icon style of the check box.| 37 38## Events 39 40In addition to the [universal events](ts-universal-events-click.md), the following attributes are supported. 41 42| Name | Description | 43| -------------------------------------------- | ------------------------------------------------------------ | 44| 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.| 45 46## MarkStyle<sup>10+</sup> 47 48| Name | Type | Mandatory| Default Value | Description | 49| ----------- | ------------------------------------------ | ---- | ----------- | ------------------------------------------------------------ | 50| strokeColor | [ResourceColor](ts-types.md#resourcecolor) | No | Color.White | Color of the internal mark. | 51| 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.| 52| 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.| 53 54## Example 55 56### Example 1 57 58```ts 59// xxx.ets 60@Entry 61@Component 62struct CheckboxExample { 63 64 build() { 65 Row() { 66 Checkbox({name: 'checkbox1', group: 'checkboxGroup'}) 67 .select(true) 68 .selectedColor(0xed6f21) 69 .onChange((value: boolean) => { 70 console.info('Checkbox1 change is'+ value) 71 }) 72 Checkbox({name: 'checkbox2', group: 'checkboxGroup'}) 73 .select(false) 74 .selectedColor(0x39a2db) 75 .onChange((value: boolean) => { 76 console.info('Checkbox2 change is'+ value) 77 }) 78 } 79 } 80} 81``` 82 83 84 85 86### Example 2 87 88```ts 89// xxx.ets 90@Entry 91@Component 92struct Index { 93 94 build() { 95 Row() { 96 Column() { 97 Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { 98 Checkbox({ name: 'checkbox1', group: 'checkboxGroup' }) 99 .selectedColor(0x39a2db) 100 .onChange((value: boolean) => { 101 console.info('Checkbox1 change is'+ value) 102 }) 103 .mark({ 104 strokeColor:Color.Black, 105 size: 50, 106 strokeWidth: 5 107 }) 108 .unselectedColor(Color.Red) 109 .width(30) 110 .height(30) 111 Text('Checkbox1').fontSize(20) 112 } 113 Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { 114 Checkbox({ name: 'checkbox2', group: 'checkboxGroup' }) 115 .selectedColor(0x39a2db) 116 .onChange((value: boolean) => { 117 console.info('Checkbox2 change is' + value) 118 }) 119 .width(30) 120 .height(30) 121 Text('Checkbox2').fontSize(20) 122 } 123 } 124 .width('100%') 125 } 126 .height('100%') 127 } 128} 129``` 130 131 132 133