Site building guide

Table of Contents

How a website is put together in the CMS, and the conventions that keep a site clean, editable and consistent. Read this before creating objects through the API. The AI prompt playbook turns these rules into ready-to-paste instructions for an AI agent.

The content model

The CMS publishes XHTML5 pages assembled from components. Every published page has this anatomy:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>Title</title>
    <link rel="icon" type="image/vnd.microsoft.icon" href="/favicon.ico" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="description" content="Description" />
    <meta name="keywords" content="Keywords" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  </head>
  <body>
    <header></header>
    <main></main>
    <footer></footer>
  </body>
</html>

You never write that document yourself. You create its parts:

Object Supplies Notes
Header The children of <header> Reusable across pages. Usually one per site.
Footer The children of <footer> Reusable across pages. Usually one per site.
CSS A stylesheet Linked from pages by id. A page can link several.
JS A script Linked from pages by id. Several load in alphabetical order of name.
Page The children of <main>, plus properties Properties: title, description, keywords, header, footer, CSS, JS, table of contents, footnotes.
Error page The children of <main> for 401, 403, 404, 500 Fixed set; same properties as a page except name and description.
Form A form rendered from a schema Placed in content as <cms-form id="…"></cms-form>.
Redirect A path that forwards to a page Use when a page is dropped. Renaming a page adds one automatically.

Header, footer and page content must not include the <header>, <footer> or <main> tags themselves, only their children. The CMS adds the wrapping element.

Order of creation

Create headers, footers, CSS and JS before pages, so each page is created with its final properties and never needs a second page_save.

Page name Public URL
index /
about /about.html
animal/index /animal/
animal/cow /animal/cow.html

Organizing CSS

HTML conventions

CSS conventions

@media screen and (min-width: 0px) and (max-width: 62.4375rem)
{
  html, body { font-size: 17px; }
  body:has(#pad-menu-toggle:checked) { overflow: hidden; }

  body > header > nav > ul > li:last-child { border-bottom: none; }

  /* Staggered fade-in for each open-menu item */
  body > header > nav:has(#pad-menu-toggle:checked) > ul > li
  {
    animation: nav-item-in 0.35s ease both;
    overflow-y: auto;
  }
}

Responsive layout

Designs must work on small phones, small and large tablets, typical desktops and very large screens.

Fonts

Use a standard font stack, or any font listed in /js/fonts.json on the site, such as Inter, Roboto, Lato, Merriweather, Playfair Display, IBM Plex Mono or Source Code Pro. Just name the family in font-family; the CMS loads built-in fonts itself, so add no @font-face or import.

JavaScript conventions

Keep JavaScript minimal; prefer CSS. Code written for the CMS follows a house style:

function parsePort(text)
{
  const port = Number(text);
  if (Number.isInteger(port))
  {
    if (port > 0 && port < 65536)
    {
      return port;
    }
    else
    {
      throw new RangeError('Port out of range: ' + text);
    }
  }
  else
  {
    throw new TypeError('Not a port number: ' + text);
  }
}

Assets

People upload assets through the admin's File Management (see Files and images); the API does not. When preparing a site, place files in matching local folders for upload. All file names are case-sensitive, and subdirectories are allowed.

Local folder Public path Contents
images/ /images/… Every image the site uses.
images/favicon.ico /images/favicon.ico The favicon. It must be a real .ico file with exactly this name; it is also served at /favicon.ico. People can make one in the admin; see Giving your site an icon.
docs/ /docs/… Downloadable documents such as PDFs.
downloads/ /downloads/… Archives and installers, such as ZIP files.
audio/ /audio/… Audio, embedded with <oembed url="/audio/…" />.
video/ /video/… Video, embedded with <oembed url="/video/…" />.

Each folder accepts only its own file types: images (JPEG, PNG, WebP, AVIF, GIF, SVG, ICO, BMP, TIFF) up to 16 MB; documents (PDF, Word, Excel, PowerPoint, text, Markdown, CSV) up to 16 MB; downloads (ZIP and other archives, installers) up to 64 MB; audio up to 32 MB; and video up to 256 MB.

Uploaded files go live at once, without publishing, while pages wait until a person publishes them. Prepare images for the web before they are uploaded: cropped to the shape the layout uses, no larger than they are displayed, WebP for photos, and width and height on every <img>. When a file is replaced by one with a different name, the old file should stay until the pages using the new name are published; see Speeding up pages by using smaller images. A favicon can be made in the admin's image tools from a square PNG or an SVG logo.

Metadata and structured data

Accessibility

Target WCAG 2.2 Level AA:

Built-in features

Site search

If the site has enough content to search, add an element with the id cms-search-button, usually in the shared header, and give it display: none by default. The CMS injects a script that reveals it when search is available. Results open in a dialog with the id cms-search-dialog containing an iframe with the id cms-search-frame; style both.

<div id="cms-search-button">&nbsp;</div>

Table of contents

With the page's generate_toc option on, the CMS builds a table of contents from the page's <h2>–<h6> headings and inserts it after the first <h1> (or at the top of the page if there is none). Each heading gets an id of the form cms-heading-<text>. Turn it on for long, structured pages, not for sectioned landing pages, and style it:

<div id="cms-table-of-contents">
  <details>
    <summary>Table of Contents</summary>
    <ul>
      <li><a href="#cms-heading-introduction">Introduction</a></li>
      <li>
        <a href="#cms-heading-whyavoid">Why Avoid</a>
        <ul>
          <li><a href="#cms-heading-harmfulpractices">Harmful Practices</a></li>
        </ul>
      </li>
    </ul>
  </details>
</div>

Heading ids and links to sections. The table of contents links to each heading by its id:

Footnotes

With generate_footnotes on, every <span> or <a> with the class cms-footnote is moved to a numbered list at the bottom of the page and replaced by a numbered link. Each footnote gets a backlink with the class cms-footnote-backlink. Style both.

<p>The building opened in 1931.<span class="cms-footnote">City records, volume 12.</span></p>

Forms and email addresses

Error pages

The 401, 403, 404 and 500 pages come with plain placeholder content. Give them the site's header, footer and styles, and make the 404 page helpful: a friendly message, a link home, and links to the main sections.

Workflow

  1. Build and check the site locally first: assemble each page from its header, main and footer, and look at it at several screen widths.
  2. Upload in dependency order: headers, footers, CSS, JS, then pages, error pages and redirects.
  3. Everything lands in staging. A person reviews and publishes it in the admin; until then the public site shows nothing new.
  4. Run the links_broken API action and fix every internal link it reports.