---
title: UUID Field
description: Generate read-only universally unique identifiers in Sveltia CMS automatically.
sidebar:
  label: UUID
---

The UUID field type provides a read-only field that automatically generates and displays a Universally Unique Identifier (UUID). It’s useful for uniquely identifying entries within the CMS.

## User Interface

### Editor

Read-only display of a [UUID](https://developer.mozilla.org/en-US/docs/Glossary/UUID) (Universally Unique Identifier) value. The UUID is automatically generated when a new entry is created and can’t be modified by default, because the [`readonly`](/docs/fields#readonly) option defaults to `true` for this field type. Set it to `false` to make the value editable.

A duplicated entry gets a new UUID, and so does a duplicated List item. With [i18n](/docs/i18n):

- A field with the `i18n: duplicate` option, or one inside a List or Object field with that option, has the same UUID in every locale.
- A field with `i18n: true` gets a different UUID for each locale, including a locale enabled later for an existing entry.

### Preview

A read-only view of the UUID value.

## Data Type

A string representing a UUID in the standard 36-character format (e.g. `df733d7e-d2f7-4e4f-8f27-803046b64040`). Alphabetic characters are in lowercase.

If `use_b32_encoding` is set to true, the UUID will be represented in a 26-character lowercase [Base32](https://en.wikipedia.org/wiki/Base32) format (e.g. `c5t6kx3m6n7g4y2z2a5b7c3d4e`).

## Data Validation

No specific data validation is applied to the UUID field, as its value is automatically generated.

## Options

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

### Required Options

#### `widget`

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

Must be set to `uuid`.

### Optional Options

#### `default`

- **Type**: `string`
- **Default**: A newly generated UUID

The default value for the field. If not provided, a new UUID will be generated when the entry is created.

#### `prefix`

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

A string prefix to prepend to the generated UUID. Useful for adding context or categorization to the UUID.

#### `read_only` [#read-only]

- **Type**: `boolean`
- **Default**: `true`

Whether to make the field read-only. Set it to `false` to let users change the generated value. This option is compatible with Decap CMS. The [`readonly`](/docs/fields#readonly) common field option, which also defaults to `true` for the UUID field type, works the same way and takes precedence if both are set.

#### `use_b32_encoding` [#use-b32-encoding]

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

Whether to use Base32 encoding for the UUID. If set to `true`, the UUID will be represented in a 26-character lowercase Base32 format instead of the standard 36-character format.

## Examples

### Basic UUID Field

This example demonstrates a basic UUID field that generates a standard UUID.

```yaml YAML
- name: product_id
  label: Product ID
  widget: uuid
```

```toml TOML
[[fields]]
name = "product_id"
label = "Product ID"
widget = "uuid"
```

```json JSON
{
  "name": "product_id",
  "label": "Product ID",
  "widget": "uuid"
}
```

```js JavaScript
{
  name: 'product_id',
  label: 'Product ID',
  widget: 'uuid',
}
```

Output example:

```yaml YAML
product_id: df733d7e-d2f7-4e4f-8f27-803046b64040
```

```toml TOML
product_id = "df733d7e-d2f7-4e4f-8f27-803046b64040"
```

```json JSON
{
  "product_id": "df733d7e-d2f7-4e4f-8f27-803046b64040"
}
```

### UUID Field with Prefix and Base32 Encoding

This example demonstrates a UUID field that includes a prefix and uses Base32 encoding.

```yaml YAML
- name: order_id
  label: Order ID
  widget: uuid
  prefix: ORD-
  use_b32_encoding: true
```

```toml TOML
[[fields]]
name = "order_id"
label = "Order ID"
widget = "uuid"
prefix = "ORD-"
use_b32_encoding = true
```

```json JSON
{
  "name": "order_id",
  "label": "Order ID",
  "widget": "uuid",
  "prefix": "ORD-",
  "use_b32_encoding": true
}
```

```js JavaScript
{
  name: 'order_id',
  label: 'Order ID',
  widget: 'uuid',
  prefix: 'ORD-',
  use_b32_encoding: true,
}
```

Output example:

```yaml YAML
order_id: ORD-c5t6kx3m6n7g4y2z2a5b7c3d4e
```

```toml TOML
order_id = "ORD-c5t6kx3m6n7g4y2z2a5b7c3d4e"
```

```json JSON
{
  "order_id": "ORD-c5t6kx3m6n7g4y2z2a5b7c3d4e"
}
```
