---
title: "Checkbox & Toggle"
description: "Add Checkbox and Toggle controls to your custom blocks for WordPress using the Lazy Blocks plugin."
url: "https://www.lazyblocks.com/docs/blocks-controls/checkbox-toggle/"
lastUpdated: 2026-09-09
source: "blocks-controls/checkbox-toggle.mdx"
---
# Checkbox & Toggle

Checkbox and Toggle both store a boolean. Checkbox has a Multiple mode on top of that, which turns it into a group of boxes and stores an array of the ticked choices. Toggle has no such mode.

## Control Settings

### Checkbox

- **Alongside Text** (`alongside_text`) - the label printed beside the box, hidden while Multiple is on
- **Checked by default** (`checked`) - the state a newly inserted block starts in, off by default
- **Multiple** (`multiple`) - off by default. Replaces the single box with one box per choice, hides Alongside Text and the default checkbox, and puts Choices and Output Format in their place
- **Choices** (`choices`) - a `Label` and a `Value` for each box, dragged into order by the handle and added with **+ Add Choice**. With Multiple on and no choices, the control renders nothing in the block editor
- **Output Format** (`output_format`) - what a ticked box contributes to the saved array. `Value` is the default, `Label` stores the label in place of the value, and `Both (Array)` stores the two together

### Toggle

- **Alongside Text** (`alongside_text`) - the label printed beside the toggle
- **Checked** (`checked`) - the state a newly inserted block starts in, off by default

Toggle has those two settings and nothing else. There is no Multiple, no Choices and no Output Format, so a group of options needs the Checkbox control, [Select](https://www.lazyblocks.com/docs/blocks-controls/select/) or [Radio](https://www.lazyblocks.com/docs/blocks-controls/radio/).

## Usage

### Single Checkbox/Toggle

```php title="PHP" /$attributes['control_name']/
<?php if ( $attributes['control_name'] ) : ?>
  <p>The value is True</p>
<?php else: ?>
  <p>The value is False</p>
<?php endif; ?>
```

```hbs title="Handlebars" /{{#if control_name}}/
{{#if control_name}}
  <p>The value is True</p>
{{else}}
  <p>The value is False</p>
{{/if}}
```

### Multiple Checkboxes

```php title="PHP with Value format" /$attributes['control_name']/
<?php
// Returns array of selected values
foreach ( $attributes['control_name'] as $value ) {
    echo '<p>' . esc_html( $value ) . '</p>';
}
?>
```

```php title="PHP with Label format" /$attributes['control_name']/
<?php
// Returns array of selected labels
foreach ( $attributes['control_name'] as $label ) {
    echo '<p>' . esc_html( $label ) . '</p>';
}
?>
```

```php title="PHP with Both format" /$attributes['control_name']/
<?php
// Returns array of arrays with value and label
foreach ( $attributes['control_name'] as $choice ) {
    echo '<p>Value: ' . esc_html( $choice['value'] ) . '</p>';
    echo '<p>Label: ' . esc_html( $choice['label'] ) . '</p>';
}
?>
```

```hbs title="Handlebars with Value format" /control_name/
{{#each control_name}}
  <p>{{this}}</p>
{{/each}}
```

```hbs title="Handlebars with Label format" /control_name/
{{#each control_name}}
  <p>{{this}}</p>
{{/each}}
```

```hbs title="Handlebars with Both format" /control_name/
{{#each control_name}}
  <p>Value: {{this.value}}</p>
  <p>Label: {{this.label}}</p>
{{/each}}
```

### Post Meta

```php title="Single Checkbox" /get_lzb_meta( 'control_meta_name' )/
<?php if ( get_lzb_meta( 'control_meta_name' ) ) : ?>
  <p>The value is True</p>
<?php else: ?>
  <p>The value is False</p>
<?php endif; ?>
```

```php title="Multiple Checkboxes" /get_lzb_meta( 'control_meta_name' )/
<?php
$selected_choices = get_lzb_meta( 'control_meta_name' );

// Output depends on selected Output Format
foreach ( $selected_choices as $choice ) {
    echo '<p>' . esc_html( $choice ) . '</p>';
}
?>
```

With Multiple on, the Checkbox control returns an array of the ticked choices. The format of the array items depends on the Output Format setting.

## Documentation Index
> Fetch the complete documentation index at: https://www.lazyblocks.com/llms.txt
> Fetch every page in a single file at: https://www.lazyblocks.com/llms-full.txt
