> From the [Strife developer docs](https://strife.app/docs/reference/field-reference/fields.color). Every page is listed in [llms.txt](https://strife.app/docs/llms.txt).

# fields.color()

One color from a palette the type defines. Editors pick a named color, and the document stores its hex code, or null.

One color from a fixed palette. Maps to editor `{ name: 'str-color', type: 'color' }`, the same editor Strife Studio calls [Color](https://strife.app/docs/reference/fields/color.md). The palette becomes the editor's `options.items`, the `{ name, value }` rows that [`fields.select()`](https://strife.app/docs/reference/field-reference/fields.select.md) uses.

Editors pick from the palette only: there is no free color picker. Each color has a name, which editors see, and a hex code, which the document stores. A cleared field is `null`. The names stay in the template.

`fields.color()` needs `@strifeapp/strife` 2.5.0 or later.

## Example

```ts
fields.color({
  label: 'Heading color',
  options: [
    { name: 'White', value: '#FFFFFF' },
    { name: 'Yellow', value: '#FFD200' },
  ],
})
// _output: '#FFFFFF' | '#FFD200' | null
```

Stored in the document:

```json
{ "headingColor": "#FFD200" }
```

## Options

| Option         | Type                                | Required | Description                                                                                                         |
| -------------- | ----------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------- |
| `label`        | `string`                            | Yes      | Label shown to editors in Strife Studio.                                                                            |
| `options`      | `{ name: string; value: string }[]` | Yes      | The palette, in the order editors see it. `name` is what editors see; `value` is the hex code the document stores. |
| `propertyName` | `string`                            | No       | Override the stored property name.                                                                                  |

No `localizable` option: one color is shared by every language, and it is never sent for translation.

### The palette

Compiling refuses a palette that Studio couldn't offer:

* It lists at least one color.
* Every color has a `name`.
* Every `value` is a hex code: `#RGB`, `#RGBA`, `#RRGGBB` or `#RRGGBBAA`.
* Each code appears once. Case makes no difference: `#ffd200` and `#FFD200` are the same color.

## Output type

The literal union of `options[].value`, or `null` while no color is picked: `'#FFFFFF' | '#FFD200' | null`. The codes are narrowed without `as const`.

## Changing the palette

Removing a color from the palette changes no document. A document that holds the removed code keeps it until an editor picks another color, and Studio shows the code where the name would be. Your generated types list only the codes in the palette, so a site that maps codes to styles should fall back to a default for a code it doesn't know.

## Writing through the MCP server

Content written through the [MCP server](https://strife.app/docs/tools/mcp-server.md) may give a color's code or its name, in any case: `'#ffd200'` and `'yellow'` both pick Yellow. The document stores the code as the palette writes it. A color that isn't in the palette is refused, and an empty string clears the field.

## See also

* [Color](https://strife.app/docs/reference/fields/color.md): the same editor, from the Strife Studio side and in JSON.
* [`fields.select()`](https://strife.app/docs/reference/field-reference/fields.select.md): one value from a list of options, stored the same way.
