Studio

Schemas and forms

Schemas are the main mechanism for describing your content and how to interact with it in the Studio.

You write schemas in plain JavaScript (or TypeScript) objects that let you describe your content model in Sanity Studio. The Studio creates the forms and inputs needed to create and edit your content and stores it as structured content in your dataset in the schema-less Content Lake database.

A faster start with @sanity/presets

Anatomy of schemas

Content model or schema: A conceptual overview, often expressed as a diagram, of the document types in a Studio and the schema types or attributes they contain.

Document types: A collection of schema types used to build a standalone piece of content. Documents typically consist of multiple fields, have a revision history, can be drafted and published, and can have queryable references between them.

Gotcha

Form: The order and structure of the schema types used for a document.

Schema types: Catch-all for attributes used on a form to make a document and maps to schema.types in the config API. Sometimes we use “field types” to talk about the same concept.

Schemas are content models

Loading...

When we talk about a schema or the content model, we are referring to all the document types created for a studio. All document types are made of schema/field types. In short form:

Schema → document types → schema/field types

Where schemas are declared

Schemas are declared in the root configuration for your Sanity Studio project, typically found in a file named sanity.config.ts (or sanity.config.js for JavaScript projects).

You can declare your schemas inline in the configuration as an array of JavaScript objects, but the more common practice is to put your schemas in external files and import them into the schema.types array.

The default Studio setup when you create a new project in the CLI will include a folder at the root level called schemaTypes with a single file called index.ts. This file exports an array, which, depending on whether you started from a template or with a clean project, might be empty or might already contain some schemas.

Example schema

Let's look at an example schema for a person document type. We'll add a string field for the name of the person and an image field for a portrait.

We then import our schema into our main schema file (./schemaTypes/index.ts) and add it to the schema array.

The Studio will now let you create a new "Person" and provide the form inputs needed to equip your person with a name and a portrait.

Loading...

Your Studio comes with a range of default schema types, such as the ones we just used to create this document, and these types can be combined to create an endless number of data structures.

Next steps

Now that you've defined a document type, learn how to shape and refine your content model with these guides.

Was this page helpful?