Field types
Every field a collection can have, how it is stored in your Markdown, the options it takes and how the admin shows it.
A collection’s fields describe the frontmatter of its entries. Each field is made with a helper from fields, and the same description draws the admin’s form, checks every save and tells the agent what the field holds.
import { collection, fields } from "@getprimecms/core";
export const posts = collection({
label: "Posts",
directory: "posts",
fields: {
title: fields.text({ required: true, maxLength: 90 }),
date: fields.date({ required: true, default: "today" }),
cover: fields.image({ alt: true }),
},
});
The Markdown body is not a field. It is always there unless a collection sets body: false; see collection options.
Options every field takes
| Option | Type | What it does |
|---|---|---|
label |
string | The name in the admin. Without one, the field’s name is used in sentence case: heroImage reads “Hero image”. |
description |
string | A line under the label. Say where the value shows on the site, or the format you expect. |
required |
boolean | The entry cannot be saved without a value. Required fields show an asterisk. |
An optional field that is cleared is removed from the file, not saved as an empty value.
How the admin lays out fields
Fields appear in the order you list them. Where the form has room, short fields sit two to a row: numbers, switches, dates, choices, single references, and one-line text with no maxLength or a maxLength of 120 or less. Everything else takes the full row. Two fields in a row always line up, even when only one has a description.
For entries with many fields, such as site settings, give the collection sections to group them under headings. See collection options.
Text
fields.text() is one line of text. fields.textarea() is several.
headline: fields.text({ required: true, maxLength: 80 }),
intro: fields.textarea({ description: "Two or three sentences under the headline." }),
headline: Paper made for slow writing
intro: Notebooks sewn by hand, inks mixed in small batches.
| Option | Type | What it does |
|---|---|---|
maxLength |
number | The most characters allowed. |
placeholder |
string | An example shown in the empty input, such as a format. Never a substitute for the label. |
default |
string | The value a new entry starts with. |
Slug
fields.slug() is a URL-safe name: lowercase letters, numbers and single hyphens. It is for handles and keys inside the frontmatter. The entry’s own file name, which is also its slug in URLs, is set in the admin above the fields and needs no field.
name: fields.text({ required: true }),
handle: fields.slug({ from: "name", description: "The product's handle in your shop." }),
name: Field notebook
handle: field-notebook
| Option | Type | What it does |
|---|---|---|
from |
string | A text field in the same collection. While the slug is empty, or still what that field would make, it follows as you type. Once you change the slug yourself, it stays. |
Number
price: fields.number({ required: true, min: 0 }),
order: fields.number({ integer: true, default: 10 }),
price: 28
order: 10
| Option | Type | What it does |
|---|---|---|
integer |
boolean | Whole numbers only. |
min, max |
number | The smallest and largest values allowed. |
default |
number | The value a new entry starts with. |
Boolean
A switch, stored as true or false. Label it for what happens when it is on: “Show on the home page”, not “Hide from the home page”.
featured: fields.boolean({ default: false, description: "Show on the home page." }),
featured: true
| Option | Type | What it does |
|---|---|---|
default |
boolean | The value a new entry starts with. |
Date
A calendar day, stored as YYYY-MM-DD.
published: fields.date({ required: true, default: "today" }),
published: 2026-10-05
| Option | Type | What it does |
|---|---|---|
default |
"today" |
New entries start on the writer’s local date. |
time |
boolean | Also accept a time, as 2026-10-05T14:30:00Z or Jekyll’s 2016-05-19 08:00:00 +0000. The admin shows a date and a time, keeps the separator and zone the file used, and sorts by the moment. |
Use a date field as a collection’s dateField to sort its entries newest first.
Select
One choice from a fixed list. The file stores the value; the admin shows the label.
process: fields.select({
required: true,
options: [
{ label: "Washed", value: "washed" },
{ label: "Natural", value: "natural" },
{ label: "Honey", value: "honey" },
],
}),
process: washed
| Option | Type | What it does |
|---|---|---|
options |
{ label, value }[] |
The choices. Required. |
default |
string | The value a new entry starts with. |
List
A list of short strings, such as tags or tasting notes, edited as chips.
notes: fields.list({ max: 4, label: "Tasting notes" }),
notes:
- Peach
- Jasmine
| Option | Type | What it does |
|---|---|---|
max |
number | The most items allowed. |
default |
string[] | The items a new entry starts with. |
When each item needs more than one value, such as a name and a colour, use a group with multiple: true.
URL
A full address, including https://.
website: fields.url({ description: "Your public address. Used in the RSS feed." }),
website: https://example.com
Image
An image from the media library (PNG, JPEG, WebP, GIF, AVIF, and SVGs already in your media folder), or a path you type.
cover: fields.image({ alt: true }),
logo: fields.image({ alt: true, icon: true }),
gallery: fields.image({ multiple: true, alt: true, max: 6 }),
cover:
src: /media/harbour.jpg
alt: Fishing boats in the harbour at dawn
logo:
src: /media/studio-mark.svg
alt: Studio Veld
gallery:
- src: /media/front.jpg
alt: The front cover
- src: /media/open.jpg
alt: Open to a dot grid page
| Option | Type | What it does |
|---|---|---|
alt |
boolean | Store alt text with the image, as { src, alt }. Without it the field stores the path alone: cover: /media/harbour.jpg. |
multiple |
boolean | A gallery: a list of images you add to, reorder and remove from. |
max |
number | With multiple, the most images allowed. |
icon |
boolean | For icons, logos and avatars. The admin shows a small preview at the image’s own proportions instead of a wide one. Small raster images get the small preview without it. |
Turn on alt for every image a reader sees. Alt text written once in the media library is suggested wherever the image is used again.
File
A PDF, font or zip file from the media library, or a full https:// link to a file stored elsewhere.
download: fields.file({ accept: ["pdf"], description: "The worksheet readers can print." }),
specimen: fields.file({ accept: ["font"] }),
download: /media/exposure-log.pdf
specimen: https://files.example.com/halden-trial.woff2
| Option | Type | What it does |
|---|---|---|
accept |
("pdf" | "font" | "archive")[] |
The kinds of file allowed. Every kind when left out. font covers WOFF2, WOFF, OTF and TTF; archive is zip. |
In the admin, opening a PDF, font or zip from the media library downloads it rather than showing it in a tab.
Reference
The slug of an entry in another collection, such as a post’s author.
author: fields.reference({ collection: "people", required: true }),
guests: fields.reference({ collection: "people", multiple: true }),
author: ada
guests:
- marisol-vega
- ines-lund
| Option | Type | What it does |
|---|---|---|
collection |
string | The collection the entries come from. Required. |
multiple |
boolean | A list of entries instead of one. |
A save checks that a reference is shaped like a slug. primecms check also checks that each one names an entry that exists, inside groups too.
Group
A small record of several fields kept together, such as a chapter’s time and title. With multiple: true it is a list of records you add to, reorder and remove from.
chapters: fields.group({
multiple: true,
description: "Each chapter's start time and title.",
fields: {
time: fields.text({ required: true, description: "Such as 04:12." }),
title: fields.text({ required: true, maxLength: 60 }),
},
}),
chapters:
- time: "00:00"
title: Cold open
- time: "04:12"
title: Handover at nine
| Option | Type | What it does |
|---|---|---|
fields |
object | The record’s fields. Any type except another group, so records stay one level deep. Required. |
multiple |
boolean | A list of records instead of one. |
max |
number | With multiple, the most records allowed. |
The admin names each record by its first text field, so put the most recognisable field first. Keys a record has that the group does not list are kept as they are when the entry is saved.
Choosing between fields and the body
Long writing belongs in the body, where the editor gives you headings, lists, links, tables, quotes and images. Fields are for values the site places on its own: a price, a date, an image beside the title, a line under a heading. If a field would hold several paragraphs, it probably belongs in the body.