---
title: Hidden Field
description: Store hidden values in Sveltia CMS that users cannot view or edit.
sidebar:
  label: Hidden
---

The Hidden field type is used to store values that should not be visible or editable by users in the entry form. It is typically used for metadata or system-generated values.

## User Interface

None. A hidden field does not render any UI components in the entry form.

## Data Type

Any value assigned programmatically or via default settings.

## Data Validation

No specific data validation is applied to the Hidden field, as its value is not user-editable.

## Options

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

### Required Options

#### `widget`

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

Must be set to `hidden`.

#### `default`

- **Type**: `any`
- **Default**: `""`

The default value for the hidden 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. Any data type is accepted (string, number, boolean, object, array, etc.) as long as it can be serialized to the collection’s data format (YAML, JSON, TOML, etc.).

TOML does not support `null` values, so avoid using `null` as the default value when the collection’s data format is set to TOML.

A string `default` value supports the following template tags, which are filled in when a new entry draft is created:

- `{{locale}}`: The current locale code when [i18n support](/docs/i18n) is enabled, e.g. `en` or `fr`. The tag requires i18n support for the collection or file; otherwise, a configuration error is reported, since there is no locale to fill it with.
- `{{datetime}}`: The current date/time in [ISO 8601 format](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#date_time_string_format).
- `{{uuid}}`, `{{uuid_short}}` and `{{uuid_shorter}}`: A random UUID or its shorter version, just like the [slug template tags](/docs/collections/entries/slugs#slug-template-tags).
- `{{author-email}}`, `{{author-login}}` and `{{author-name}}`: The signed-in user’s email, login name and display name, respectively, just like [commit message tags](/docs/backends#commit-messages). These tags don’t work with the [local development workflow](/docs/workflows/local) because the user is not authenticated via a Git backend.

The default value is also applied again in the following cases:

- When an entry is duplicated, or a [List](/docs/fields/list) item holding the field is duplicated or pasted, the field gets its default value again, with any tags filled in anew, so the copy doesn’t share a UUID or a date with its original.
- When a locale is enabled for an existing entry, a translatable field (`i18n: true`) whose default contains a tag gets the tags filled in for the new locale, e.g. `{{locale}}` becomes the new locale code. If the default has no tag, the value is copied from the default locale like any other field’s.

[String transformations](/docs/string-transformations) can be applied in this option. Any other tag, such as `{{title}}` or `{{slug}}`, is replaced with an empty string. The slug isn’t known until the entry is saved, so to store a path containing it, use the [`permalink_field` option](/docs/collections/entries/previews#permalinks). To keep a template tag for your static site generator, [escape it](/docs/string-transformations#escaping-template-tags) with a backslash. See the [example below](#passing-a-template-to-a-static-site-generator).

## Examples

### Embedding UUID in a Hidden Field

This example shows how to create a hidden field that automatically generates and stores a UUID for each entry. This can be useful for uniquely identifying entries.

```yaml YAML
- name: unique_id
  label: Unique ID
  widget: hidden
  default: '{{uuid}}'
```

```toml TOML
[[fields]]
name = "unique_id"
label = "Unique ID"
widget = "hidden"
default = "{{uuid}}"
```

```json JSON
{
  "name": "unique_id",
  "label": "Unique ID",
  "widget": "hidden",
  "default": "{{uuid}}"
}
```

```js JavaScript
{
  name: 'unique_id',
  label: 'Unique ID',
  widget: 'hidden',
  default: '{{uuid}}',
}
```

### Embedding the Author’s Name in a Hidden Field [#embedding-the-author-s-name-in-a-hidden-field]

This example shows how to create a hidden field that automatically captures the name of the user creating the entry.

```yaml YAML
- name: author_name
  label: Author Name
  widget: hidden
  default: '{{author-name}}'
```

```toml TOML
[[fields]]
name = "author_name"
label = "Author Name"
widget = "hidden"
default = "{{author-name}}"
```

```json JSON
{
  "name": "author_name",
  "label": "Author Name",
  "widget": "hidden",
  "default": "{{author-name}}"
}
```

```js JavaScript
{
  name: 'author_name',
  label: 'Author Name',
  widget: 'hidden',
  default: '{{author-name}}',
}
```

### Passing a Template to a Static Site Generator

This example shows how to store an [Eleventy permalink](https://www.11ty.dev/docs/permalinks/) template that Eleventy fills in at build time. The backslash before the curly braces keeps Sveltia CMS from processing the template tag, and is removed from the saved value, which is `portfolio/{{ title | slugify }}/index.html`.

```yaml YAML
- name: permalink
  label: Permalink
  widget: hidden
  default: 'portfolio/\{{ title | slugify }}/index.html'
```

```toml TOML
[[fields]]
name = "permalink"
label = "Permalink"
widget = "hidden"
default = "portfolio/\\{{ title | slugify }}/index.html"
```

```json JSON
{
  "name": "permalink",
  "label": "Permalink",
  "widget": "hidden",
  "default": "portfolio/\\{{ title | slugify }}/index.html"
}
```

```js JavaScript
{
  name: 'permalink',
  label: 'Permalink',
  widget: 'hidden',
  default: 'portfolio/\\{{ title | slugify }}/index.html',
}
```

:::tip

If you want the path to use the slug generated by the CMS, you can use the [`permalink_field` collection option](/docs/collections/entries/previews#permalinks) instead of a Hidden field. It fills the `permalink` property from the `preview_path` option each time an entry is saved, so the site is built at the same path the CMS links to. Remove the `permalink` field from the `fields` option in that case, because the CMS leaves the property alone when a field of the same name is defined.

:::
