---
title: Style the site
description: Give the generated pages your site's colors with a stylesheet, or its header, footer, and home opening with a shell and an opening fragment.
slug: /guides/style-the-site
order: 4
visibility: public
redirects_from: [/shell]
---

# Style the site

Prompt:

> Make the generated docs use our site's header, footer, and colors.

Also works: "Change the docs' colors to match our brand." "Put our opening section on the docs home page."

Choose between a stylesheet and a shell, or use both ([step 1](#1-choose-between-a-stylesheet-and-a-shell)). A CSS file with `--stylesheet` sets your colors ([step 2](#2-supply-a-site-stylesheet)), and an HTML document with `--shell` sets your header and footer ([step 3](#3-supply-a-shell)). For an opening section on the home page, pass an HTML fragment with `--home-opening` ([step 4](#4-supply-a-home-opening)).

## What your tool does

- Asks whether the pages should use your site's header and footer or only its colors, when the request does not say.
- For the colors alone, writes a CSS file that redefines the tool's custom properties on `.docs-shell` and passes it with `--stylesheet`.
- For the header and the footer, writes a complete HTML document containing the two markers and passes it with `--shell`.
- For a home opening, writes an HTML fragment and passes it with `--home-opening`.
- Builds, and reports the success line, which lists the shell, the opening, and the stylesheet the build used.

## What you need

- If you want your site's own header and footer: their HTML, and the web address of your site's stylesheet.
- If you want your own colors instead: the values to use, following the property list on [Output](/tzdocs/reference/output/#the-styling-surface).

## Before your AI starts

Your AI coding agent checks these things before it starts.

- The tool installed and a corpus that builds ([Getting started](/tzdocs/getting-started/)).

## Steps

### 1. Choose between a stylesheet and a shell

Without a shell, the tool renders every page into its [default layout](/tzdocs/concepts/glossary/#default-layout), with the navigation on the left and the article beside it. A site stylesheet changes the colors and the navigation's width, and needs no shell. A shell replaces the default layout with your site's own HTML document. A home opening adds a fragment to the home page alone.

The options combine. With a shell, `--stylesheet` still works, and the build writes both stylesheet links at the shell's `<!--tzdoc:head-->` marker (step 3).

### 2. Supply a site stylesheet

Write a CSS file that redefines the tool's color properties on the `.docs-shell` element. A value set on `:root`, `html`, or `body` does not reach the pages, because the tool's own declaration on `.docs-shell` wins. A redefinition outside a media query replaces both the light and the dark default. To give the two color schemes different values, write your own media query.

The tool's test suite builds with this exact file and keeps it equal to the example on [Output](/tzdocs/reference/output/#the-styling-surface), which lists every property and selector:

```css
.docs-shell {
  --docs-bg: #0b1020;
  --docs-text: #e6edf6;
  --docs-link: #7cc4ff;
  --docs-pre-bg: #05080f;
}
.docs-main pre code .docs-line-hl {
  background: rgba(124, 196, 255, 0.12);
}
```

Pass the file with `--stylesheet`. The build copies it into the tree as `site.css`, with LF line endings, and links it after the tool's `docs.css` on every page. At equal specificity, its rules win.

```text
tzdocs build --source docs --out site --stylesheet theme.css
```

The tree's `site.css` sits at the tree root. If the tree is served at your site's root, its `site.css` has the address `/site.css`, so do not serve another file there.

The same file retunes the [callouts](/tzdocs/guides/callouts-and-diagrams/). Each type's color, for its bar and its title, is a property on `.docs-shell`: `--docs-callout-note`, `--docs-callout-tip`, `--docs-callout-important`, `--docs-callout-warning`, and `--docs-callout-caution`.

```css
.docs-shell {
  --docs-callout-note: #1d4ed8;
  --docs-callout-warning: #b45309;
}
```

It also sets the navigation column's width. The column is `17rem` wide unless the file redefines `--docs-nav-width` on `.docs-shell`. Widen it when your page titles wrap onto two lines.

```css
.docs-shell {
  --docs-nav-width: 20rem;
}
```

With `--next-previous`, each page ends with the pager, a `nav` classed `docs-pager` whose links are classed `docs-pager-prev` and `docs-pager-next`. It takes its colors from `--docs-link`, `--docs-muted`, and `--docs-border`. To change its spacing, write a rule at the tool's own selector, such as `.docs-main .docs-pager`. A corpus of one page has no pager.

### 3. Supply a shell

A shell is a complete HTML document of your site's own, containing the two markers. At the head marker, the build writes only the page's own head elements: its title, its description, its share tags, and the stylesheet links ([Output](/tzdocs/reference/output/#the-page-head)). A page that draws a diagram also gets the `mermaid.min.js` script tag there. So put the `charset` and `viewport` lines in the shell's head yourself, as the default layout does. Put the share tags every page has in common there too, such as your site's name and its share image.

```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/styles.css">
<!--tzdoc:head-->
</head>
<body>
<header>… the site's header …</header>
<div class="site-docs">
<!--tzdoc:page-->
</div>
<footer>… the site's footer …</footer>
</body>
</html>
```

Pass the shell with `--shell`.

```text
tzdocs build --source docs --out site --shell shell.html
```

The build renders every page into the shell. At `<!--tzdoc:head-->` it writes the title, the description, the share tags, and the relative stylesheet links: the tool's `docs.css` and, if the build was given one, `site.css` after it. On a page that draws a diagram, a deferred script tag for `mermaid.min.js` follows them.

At `<!--tzdoc:page-->` it writes the `docs-shell` wrapper containing the navigation and article. Pages with at least two rendered second- or third-level headings also get the On this page list. Its rail follows the article column; its collapsed form sits inside that column. In both forms, a list of more than 20 entries puts each second-level heading that has headings under it, with those headings, in a closed `details` element, which a site stylesheet can style. The outline below uses ellipses for generated content. The copy control and navigation script follow the wrapper.

```html
<div class="docs-shell">
<nav class="docs-nav" aria-label="Documentation">…</nav>
<main class="docs-main">
… the article …
</main>
<nav class="docs-toc" aria-label="On this page">…</nav>
</div>
<script>… the copy control and the navigation jump …</script>
```

The `docs-shell` wrapper is an inline-size container. Place the page marker in an element with a width independent of its content, such as a normal block element. A wrapper sized by its content, such as an inline block or a flex item that does not grow, can shrink the docs shell.

On a screen 800 pixels wide or less, the navigation stands above the article. When a reader follows a navigation link there, the script brings the new page's `h1` to the top. If your shell has a fixed header, give `h1`, `h2` and `h3` a `scroll-margin-top` of the header's height plus 1rem. This keeps headings visible after navigation jumps and links from the list.

```css
.site-docs .docs-main h1,
.site-docs .docs-main h2,
.site-docs .docs-main h3 {
  scroll-margin-top: calc(64px + 1rem);
}
```

The tool does not change the shell's own links, so keep them correct yourself. A stylesheet link placed before the head marker loses to both tool stylesheets at equal specificity. A link placed after the marker wins over them.

Under a shell, the tool's body rules do not apply, because they target the default layout's body class, `tzdoc-page`. Your site's font family therefore applies to the pages. The line height of 1.6 still applies, because the tool sets it on the `docs-shell` wrapper. Redirect stubs are not pages and take no shell.

The tool's `docs.css` leaves the article's list indent to the browser's default. A site stylesheet that resets `padding` on every element removes that indent, and the bullets then hang to the left of the article's text. Restore the indent in your own stylesheet.

```css
.site-docs .docs-main ul,
.site-docs .docs-main ol {
  padding-left: 1.5rem;
}
```

A shell's stylesheet redefines the colors the same way, with its wrapper's class in front so that its own selector wins.

```css
.site-docs .docs-shell {
  --docs-bg: var(--surface);
  --docs-text: var(--text);
  --docs-link: var(--accent);
  --docs-pre-bg: var(--surface-strong);
  --docs-tok-keyword: #f97583;
}
```

### 4. Supply a home opening

A home opening is an HTML fragment, with no doctype and no stylesheet link. The build places it at the head of the home page's article column, above the page's own content and beside the navigation. Every other page is unchanged. An opening works with or without a shell. Pass it with `--home-opening`.

```text
tzdocs build --source docs --out site --shell shell.html --home-opening home_opening.html
```

### 5. Place a fixed header above the pages

To keep your site's header in view, make it `position: fixed`. Then give the element around the page marker top padding equal to the header's height. The navigation stays in view while the article scrolls, so set its `top` to the header's height and subtract that height from its maximum height. On a window 800 pixels wide or narrower the navigation does not stay in view, so the media rule removes the height limit there. The navigation then starts below the header on every page and stays below it as the page scrolls.

On a wide docs shell, the On this page rail stays beside the article. Set its `top` to the header's height plus 1rem. For the padding shown here, subtract the header's height and 4rem from its maximum height. Increase that subtraction if extra top spacing would put the rail below the window's bottom.

Give `h1`, `h2` and `h3` a `scroll-margin-top` of the header's height plus 1rem. This leaves linked headings visible below the header.

```css
header {
  position: fixed;
  top: 0;
  height: 64px;
}
.site-docs {
  padding-top: 64px;
}
.docs-nav {
  top: 64px;
  max-height: calc(100vh - 64px);
}
.docs-toc {
  top: calc(64px + 1rem);
  max-height: calc(100vh - 64px - 4rem);
}
.site-docs .docs-main h1,
.site-docs .docs-main h2,
.site-docs .docs-main h3 {
  scroll-margin-top: calc(64px + 1rem);
}
@media (max-width: 800px) {
  .docs-nav {
    max-height: none;
  }
}
```

## Expected result

The success line lists the files the build used. It has this form: `built 13 pages into site with the shell shell.html, the home opening home_opening.html, the site stylesheet theme.css`.

Every page's head contains the title, the description, the share tags, and the two stylesheet links in order. Every page's body contains your site's header and footer around the `docs-shell` element, and the home page has the opening above its article. `site.css` sits at the tree root with LF line endings.

## Refusals

The build refuses on each of these before writing anything, with exit code 1. [Refusals and findings](/tzdocs/reference/refusals/) gives the exact text.

| Message | Cause | Remedy |
| --- | --- | --- |
| `the shell lacks the marker <!--tzdoc:head-->`, `the shell lacks the marker <!--tzdoc:page-->` | The shell file has no such comment. | Add the marker where the build should write the head elements or the page. |
| `the shell file is absent at <path>` | `--shell` points to a file that does not exist. | Correct the path. |
| `the home opening file is absent at <path>` | `--home-opening` points to a file that does not exist. | Correct the path. |
| `the site stylesheet file is absent at <path>` | `--stylesheet` points to a file that does not exist. | Correct the path. |
| `output contains an input source or asset — <path>` | The shell, the opening, or the stylesheet sits inside the output folder. | Keep the supplied files outside the output folder. |

A `--shell`, `--home-opening`, or `--stylesheet` flag with no file after it, or given twice, is a usage error. The tool prints the reason and the usage lines and exits with code 2 ([Refusals and findings](/tzdocs/reference/refusals/#usage-errors)).

## Related

- [Output](/tzdocs/reference/output/#the-styling-surface) lists the properties, the classes, the attributes, and the selectors a stylesheet targets.
- [Highlight a code block](/tzdocs/guides/code-blocks/) explains the figure the token properties color.
