> For AI agents: the complete Sanity documentation index is available at [https://www.sanity.io/docs/llms.txt](https://www.sanity.io/docs/llms.txt).

# String

A schema type for strings and a selectable lists of strings.

![Screenshot from Sanity Studio of a string field](https://cdn.sanity.io/images/3do82whm/next/a6c032005fefd5fdfc0f5e177ea5659819dc1971-4608x2800.png)
*A string field with a title and a description*

Short string. Typically used for titles, names, and labels. If you need a basic multi-line string input, use the [text](https://www.sanity.io/docs/studio/text-type). If you need text with markup and structured data, use [block](https://www.sanity.io/docs/studio/block-type). See the [StringDefinition](https://reference.sanity.io/sanity/index/StringDefinition/) reference for the full type definition.

## Properties

#### Properties

**type** (required)

Required. Value must be set to string.

**name** (required)

Required. The field name. This is the key in the data record.

**title**

Human-readable label for the field.

**hidden**

If set to true, the field is hidden in the studio. You can also set it to a callback function to make it a conditional field.

**readOnly**

If set to true, the field can't be edited in the studio. You can also set it to a callback function to make it a conditional field.

**description**

Short description that tells editors how to use the field.

**initialValue**

The initial value used when creating new values of this type. Can be a literal value, or a resolver function that returns a literal value or a promise that resolves to one.

**deprecated**

Marks a field or document type as deprecated in the studio interface and displays a user-defined message defined by the single required reason property.

If you deploy a GraphQL API schema, this property is translated into the @deprecated directive.

**icon**

Supply a custom icon for this field. For more information, see Icons.

**components**

Lets you provide custom components to override the studio defaults in various contexts. The available keys are diff, field, input, item, and preview.

**placeholder**

Placeholder text shown in the input when it has no value.

## Options ([StringOptions](https://reference.sanity.io/sanity/index/StringOptions/))

#### Properties

**list**

A list of predefined values that the user can choose from. The array can either include string values ['sci-fi', 'western'] or objects [{title: 'Sci-Fi', value: 'sci-fi'}, ...].

Sanity Studio displays string values with the first character capitalized and the rest lowercased: sci-fi displays as Sci-fi, and USA displays as Usa. The stored value doesn't change. To control the displayed label, use object values with a title instead.

**layout**

Controls how the items defined in the list option are presented. If set to 'radio' the list will render radio buttons. If set to 'dropdown' you'll get a dropdown menu instead. Default is dropdown.

**direction**

Controls how radio buttons are lined up. Use direction: 'horizontal|vertical' to render radio buttons in a row or a column. Default is vertical. Will only take effect if the layout option is set to radio.

**search**

Sets a search weight for this field so that it ranks higher when editors search in the studio. Takes {weight: number}. The default weight is 1, or 10 if the field is selected as the preview title and 5 if it is selected as the subtitle. A weight set here overrides both. See Studio search configuration.

### Dropdown empty option

> [!NOTE]
> When `layout: 'dropdown'` (the default layout) is used on a field with `options.list`, the input renders a blank option at the top of the list representing the unset state. Selecting it clears the field's value. This blank option is built into the dropdown input and cannot be removed, renamed, or restyled through schema configuration.

What schema configuration can and cannot change:

- **Cannot remove the blank option:** `required()` validation, `initialValue`, and none of the available `options` fields remove it from the rendered list.
- **Cannot rename the blank option:** its title is hardcoded to an empty string.
- **Can switch to layout: 'radio':** radio layout does not include a blank option. Editors can still unset the field with the **Clear** button, which appears once a value is selected.
- **Can implement a custom input component:** for full control over placeholder text, empty-option behavior, and item rendering.

#### Workarounds

**Use radio layout:** switch from `layout: 'dropdown'` to `layout: 'radio'` to avoid the blank option entirely:

```typescript
import {defineField} from 'sanity'

defineField({
  name: 'status',
  type: 'string',
  options: {
    list: ['draft', 'published', 'archived'],
    layout: 'radio',
  },
})
```

**Custom input component for full control:** for full control over rendering, including placeholder text and conditional logic, implement a custom input. See [Create a visual string selector field input](https://www.sanity.io/docs/developer-guides/create-a-rich-string-selector-field-input).

### Dynamic option lists

> [!TIP]
> The `options.list` property only accepts a static array of strings or `{title, value}` objects. It does not accept a function or callback. When you use `defineField`, TypeScript reports this at compile time. If you need a dynamic list (filtered by another field, fetched at runtime, conditionally shown), implement a custom input component.

Register a custom input on the field, then build the option list inside your component. Use `useFormValue` to read other fields on the current document, or fetch data through `@sanity/client`. For an example of the custom input pattern, see [Create a visual string selector field input](https://www.sanity.io/docs/developer-guides/create-a-rich-string-selector-field-input).

```typescript
import {defineField} from 'sanity'
import {DynamicStatusInput} from './DynamicStatusInput'

defineField({
  name: 'status',
  type: 'string',
  components: {
    input: DynamicStatusInput,
  },
})
```

Dynamic `options.list` support is tracked in [GitHub issue #4095](https://github.com/sanity-io/sanity/issues/4095).

## Validation ([StringRule](https://reference.sanity.io/sanity/index/StringRule/))

#### Properties

**required()**

Ensures that this field exists.

**skip()**

Discards the validation rules set before it in the chain and makes the field optional. Rules chained after it still apply. Requires sanity 5.9.0 or later.

**min(minLength)**

Minimum length of string.

**max(maxLength)**

Maximum length of string.

**length(exactLength)**

Exact length of string.

**uppercase()**

All characters must be uppercase.

**lowercase()**

All characters must be lowercase.

**email()**

Value must be a valid email address.

**regex(pattern[, options])**

String must match the given pattern.

options is an optional object. You can set options.name and options.invert.

Providing a name makes the message more understandable to the user (Does not match "<name>"-pattern).

Set invert to true to allow any value that does not match the pattern.

With invert: true, the message reads Should not match "<name>"-pattern.

You can also pass the name as a string: regex(pattern, name). The three-argument form regex(pattern, name, options) is accepted, but its options argument is ignored. To use invert, pass {name, invert} as the second argument.

**custom(fn)**

Creates a custom validation rule.

**error(message)**

Sets a custom error message for the preceding validation rule.

**warning(message)**

Sets a custom warning message for the preceding validation rule. Warnings do not prevent publishing.

**info(message)**

Sets a custom info message for the preceding validation rule. Info messages are purely informational and do not prevent publishing.

**valueOfField(path)**

Gets the value of a sibling field to use in validation. Useful for creating validation rules that depend on the value of another field.

## Examples

### Field configuration

```typescript
import {defineField} from 'sanity'

defineField({
  title: 'Title',
  name: 'title',
  type: 'string',
  description: 'Make it catchy',
  validation: (Rule) => Rule.max(120).warning(`A title shouldn't be more than 120 characters.`),
})
```

### List of predefined strings

**Schema**

```typescript
import {defineField} from 'sanity'

defineField({
  title: 'Genre',
  name: 'genre',
  type: 'string',
  options: {
    list: [
      {title: 'Sci-Fi', value: 'sci-fi'},
      {title: 'Western', value: 'western'},
    ], // <-- predefined values
    layout: 'radio', // <-- defaults to 'dropdown'
  },
})
```

**Stored document**

```json
{
  "_type": "movie",
  "_id": "23407q-qwerqyt12",
  "genre": "sci-fi",
  ...
}
```

> [!TIP]
> Protip
> Want to make a multi-select for strings? Check out [the Array schema type](https://www.sanity.io/docs/studio/array-type) to see how you can build an array of strings, references, objects, and more. 

For details on how to access the `title` value of a list in your document list preview, see [Previewing from predefined string lists](https://www.sanity.io/docs/studio/previews-list-views).

### Set an initial value for string fields

You can use [initial values](https://www.sanity.io/docs/studio/initial-value-templates) to preset string fields on document creation:

```typescript
import {defineField, defineType} from 'sanity'

export default defineType({
  name: 'post',
  type: 'document',
  title: 'Post',
  initialValue: {
    title: 'The initial title',
  },
  fields: [
    defineField({
      name: 'title',
      type: 'string',
      title: 'Title',
    }),
  ],
})
```



## Related changelog entries

Entries are listed newest first; each link points to the full entry as markdown. Follow one when you need to know what changed, when, or why — for example, to summarize recent updates, explain behavior that differs from older documentation, or check whether a fix has shipped.

- [Sanity Studio v3.26.0: Deprecation Support for Documents and Fields, Comment Reactions ++](https://www.sanity.io/docs/changelog/5a99e214-6088-4d10-a0b7-14ca7c555c01.md) — January 23, 2024
- [Sanity Studio v2.17.0: Conditional Fields](https://www.sanity.io/docs/changelog/10aba481-ece9-4b41-b0e2-6b8e75e375c9.md) — August 26, 2021