Skip to content

Headless CMS setup guide for HTML/CSS/JS developers without frameworks

6repliesLast updated: Nov 13, 2026

Hey guys, I just want to get something off my chest. I think it's pretty hard to get a guide on how to use the headless CMS for people who only know HTML CSS and vanilla JS. Maybe it's me who is just not skilled enough for this but I think many topics are not explained well. For instance I didn't get a clear guide on how to setup a very basic headless CMS for my portfolio and how I would connect it. I either found overkilling guides which would be too much setup for my case or It's that I need to setup with react, gatsby, nextjs or the like.
Again, maybe it's only because I'm too unskilled to get it, I don't know.
AI Update

You don't need React or a framework to use Sanity. Sanity Studio is the editing app, and it needs Node.js to set up. Your portfolio can stay plain HTML, CSS and JavaScript and get its content with fetch() from the HTTP Query API, which returns JSON. A page in the browser also needs its address added to the project's CORS origins, which is the step people most often miss.

1. Create the Studio (one time, needs Node.js)

The installation docs call for Node.js v22.12 or newer:

npm create sanity@latest -- --dataset production --template clean --output-path studio
cd studio
npm run dev

Open http://localhost:3333 and sign in with the same account you used in the CLI (quickstart).

2. Add a "project" schema

The clean template starts with no document types, so define one in schemaTypes/projectType.ts:

import {defineField, defineType} from 'sanity'

export const projectType = defineType({
  name: 'project',
  title: 'Project',
  type: 'document',
  fields: [
    defineField({name: 'title', type: 'string'}),
    defineField({name: 'description', type: 'text'}),
    defineField({name: 'image', type: 'image'}),
  ],
})

Register it in schemaTypes/index.ts with export const schemaTypes = [projectType]. The Studio reloads and shows "Project" (schema lesson). Add a few projects and publish them.

To host the Studio at your-name.sanity.studio, run npx sanity@latest deploy (deploy reference).

3. Allow your website's origin (CORS)

By default only localhost:3333 and your deployed Studio host are allowed. For your site to read a public dataset from the browser, add its origin (CORS docs):

4. Fetch content with plain JavaScript

URLs have the form https://<projectId>.apicdn.sanity.io/v<YYYY-MM-DD>/data/query/<dataset>?query=.... The API CDN host (apicdn) is cached and fine for public reads. The version is a date; use today's date (HTTP API reference). The response JSON has your data in result.

<!DOCTYPE html>
<html>
<body>
  <h1>My Projects</h1>
  <div id="projects"></div>
  <script>
    const projectId = 'YOUR_PROJECT_ID' // shown in sanity.io/manage
    const dataset = 'production'
    const query = `*[_type == "project"] | order(_createdAt desc){
      title, description, "imageUrl": image.asset->url
    }`
    const url = `https://${projectId}.apicdn.sanity.io/v2025-02-19/data/query/${dataset}?query=${encodeURIComponent(query)}`

    fetch(url)
      .then((res) => res.json())
      .then(({result}) => {
        const container = document.getElementById('projects')
        result.forEach((project) => {
          const div = document.createElement('div')
          const h2 = document.createElement('h2')
          h2.textContent = project.title
          const p = document.createElement('p')
          p.textContent = project.description || ''
          div.append(h2, p)
          if (project.imageUrl) {
            const img = document.createElement('img')
            img.src = `${project.imageUrl}?w=800&fit=max&auto=format`
            img.alt = project.title || ''
            div.append(img)
          }
          container.append(div)
        })
      })
      .catch((err) => console.error(err))
  </script>
</body>
</html>

Images

Don't take apart the asset _ref by hand. Ask for the URL in the query with image.asset->url and add parameters such as ?w=800, &fit=max (never upscale) or ?auto=format. Loading unoptimized originals can cause usage overages (presenting images). If you later add a build step, @sanity/image-url builds these URLs for you and handles crop and hotspot.

Things to know

Show original thread
6 replies

Was this answer helpful?

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Related contributions