---
title: Boolean Field
description: Select true/false values in Sveltia CMS using an intuitive toggle switch.
sidebar:
  label: Boolean
---

The Boolean field type allows users to select a true/false value using a toggle switch interface.

## User Interface

### Editor

A toggle switch. It can be turned on or off by clicking or tapping it, like a checkbox.

Additional text can be displayed before or after the switch using the `before_input` and `after_input` options.

### Preview

The preview shows the boolean value as `true` or `false`.

## Data Type

A boolean. If the `required` option is set to `false` and the field is left empty, the value will be `false`.

An existing entry may store the value as a string or a number instead, as files written for a YAML 1.1 parser like Jekyll’s often do. Sveltia CMS reads such a value the way that parser does, ignoring case:

- `yes`, `on`, `y` and `1`, as well as `true`, are read as `true`.
- `no`, `off`, `n` and `0`, as well as `false`, are read as `false`.

The value is then saved as a real boolean. Any other value is replaced with the [default value](#default).

## Data Validation

No special validation is performed for Boolean fields as the value will always be either `true` or `false`.

## Options

In addition to the [common field options](/docs/fields#common-options), the Boolean field supports the following options:

### Required Options

#### `widget`

- **Type**: `string`
- **Default**: `string`

Must be set to `boolean`.

### Optional Options

#### `default`

- **Type**: `boolean`
- **Default**: `false`

The default value for the field. It’s used when creating a new entry, and when opening an existing entry that doesn’t have the field, such as one written before the field was added to the configuration.

#### `before_input` [#before-input]

- **Type**: `string`
- **Default**: `""`

Text to display before the toggle switch. It’s placed at the `false` position.

#### `after_input` [#after-input]

- **Type**: `string`
- **Default**: `""`

Text to display after the toggle switch. It’s placed at the `true` position.

## Examples

### Basic Boolean Field

Configuration example:

```yaml YAML
- name: draft
  label: Draft
  widget: boolean
  default: true
```

```toml TOML
[[fields]]
name = "draft"
label = "Draft"
widget = "boolean"
default = true
```

```json JSON
{
  "name": "draft",
  "label": "Draft",
  "widget": "boolean",
  "default": true
}
```

```js JavaScript
{
  name: "draft",
  label: "Draft",
  widget: "boolean",
  default: true,
}
```

Output example:

```yaml YAML
draft: true
```

```toml TOML
draft = true
```

```json JSON
{
  "draft": true
}
```
