# Toggle The **\** component provides a clickable element in the check box, button, or switch type. > **NOTE** > > This component is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version. ## Required Permissions None ## Child Components This component can contain child components only when **ToggleType** is set to **Button**. ## APIs Toggle(options: { type: ToggleType, isOn?: boolean }) - Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | type | ToggleType | Yes| Type of the toggle.| | isOn | boolean | No| Whether the toggle is turned on. The value **true** means that the toggle is turned on, and **false** means the opposite.
Default value: **false** | - ToggleType enums | Name| Description| | -------- | -------- | | Checkbox | Check box type.
> **NOTE**
> The default value of the universal attribute [padding](ts-universal-attributes-size.md) is as follows:
{
top: 14 vp,
right: 6 vp,
bottom: 14 vp,
left: 6 vp
} | | Button | Button type. The set string, if any, will be displayed inside the button. | | Switch | Switch type.
> **NOTE**
> The default value of the universal attribute [padding](ts-universal-attributes-size.md) is as follows:
{
top: 12 vp,
right: 12 vp,
bottom: 12 vp,
left: 12 vp
} | ## Attributes | Name| Parameter| Default Value| Description| | -------- | -------- | -------- | -------- | | selectedColor | [ResourceColor](ts-types.md#resourcecolor) | - | Background color of the component when it is turned on.| | switchPointColor | [ResourceColor](ts-types.md#resourcecolor) | - | Color of the circular slider when the component is of the **Switch** type.
> **NOTE**
> This attribute is valid only when **type** is set to **ToggleType.Switch**.| ## Events | Name| Description| | -------- | -------- | | onChange(callback: (isOn: boolean) => void) | Triggered when the toggle status changes.| ## Example ```ts // xxx.ets @Entry @Component struct ToggleExample { build() { Column({ space: 10 }) { Text('type: Switch').fontSize(12).fontColor(0xcccccc).width('90%') Flex({ justifyContent: FlexAlign.SpaceEvenly, alignItems: ItemAlign.Center }) { Toggle({ type: ToggleType.Switch, isOn: false }) .selectedColor(0xed6f21) .switchPointColor(0xe5ffffff) .onChange((isOn: boolean) => { console.info('Component status:' + isOn) }) Toggle({ type: ToggleType.Switch, isOn: true }) .selectedColor(0x39a2db) .switchPointColor(0xe5ffffff) .onChange((isOn: boolean) => { console.info('Component status:' + isOn) }) } Text('type: Checkbox').fontSize(12).fontColor(0xcccccc).width('90%') Flex({ justifyContent: FlexAlign.SpaceEvenly, alignItems: ItemAlign.Center }) { Toggle({ type: ToggleType.Checkbox, isOn: false }) .size({ width: 28, height: 28 }) .selectedColor(0xed6f21) .onChange((isOn: boolean) => { console.info('Component status:' + isOn) }) Toggle({ type: ToggleType.Checkbox, isOn: true }) .size({ width: 28, height: 28 }) .selectedColor(0x39a2db) .onChange((isOn: boolean) => { console.info('Component status:' + isOn) }) } Text('type: Button').fontSize(12).fontColor(0xcccccc).width('90%') Flex({ justifyContent: FlexAlign.SpaceEvenly, alignItems: ItemAlign.Center }) { Toggle({ type: ToggleType.Button, isOn: false }) { Text('status button').padding({ left: 12, right: 12 }) } .selectedColor(0xed6f21) .onChange((isOn: boolean) => { console.info('Component status:' + isOn) }) Toggle({ type: ToggleType.Button, isOn: true }) { Text('status button').padding({ left: 12, right: 12 }) } .selectedColor(0x39a2db) .onChange((isOn: boolean) => { console.info('Component status:' + isOn) }) } }.width('100%').padding(24) } } ``` ![en-us_image_0000001211898522](figures/en-us_image_0000001211898522.gif)