# Writing pages with no CSS

A page built this way links one stylesheet and writes no CSS. Everything it looks like comes from the elements it uses, a few documented attributes, and the [tokens](https://domestic-ui.odonckers.dev/tokens/index.md) a theme sets. **Our choice:** a closed vocabulary rather than utility classes, so a page says what each part is, not how it should look, and a checker can tell when a page leaves the system.

## The rules

1. Link `css/domestic.css` once, in `<head>`. Optionally link a theme from `css/themes/` after it and set `data-theme` on `<html>`.
2. Write no `<style>` element and no `style` attribute, except to set a layout primitive's documented custom property (`--stack-gap`, `--grid-min`, `--cluster-justify`, …) or a semantic `--dui-*` token.
3. Use the native element that already has the meaning: `<button>`, `<a href>`, `<dialog>`, `<details>`, `<label>`, `<fieldset>`, `<table>`, `<search>`, `<time>`. The [first rule of ARIA](https://www.w3.org/TR/using-aria/#rule1) applies: no `role` where an element exists.
4. Use only the attributes, words and classes in the [vocabulary](#the-vocabulary) below. A word that is not listed does nothing, so it is a mistake, not a style.
5. Give each page the landmarks in the skeletons below: a skip link, one `<header>`, a labelled `<nav>`, one `<main id>` and a `<footer>`, and exactly one `<h1>` ([WCAG 2.4.1](https://www.w3.org/WAI/WCAG22/Understanding/bypass-blocks.html), [1.3.1](https://www.w3.org/WAI/WCAG22/Understanding/info-and-relationships.html)).
6. Label every control with a `<label for>` or a wrapping `<label>`, and name every landmark and region you have more than one of with `aria-label` or `aria-labelledby` ([WCAG 4.1.2](https://www.w3.org/WAI/WCAG22/Understanding/name-role-value.html)).
7. Load `web-components/<name>.js` as a module for each `dui-*` element on the page. Without it the markup still works as plain HTML ([progressive enhancement](https://developer.mozilla.org/en-US/docs/Glossary/Progressive_Enhancement)).
8. Check the page from a clone of this repository: `node scripts/check-markup.mjs page.html` fails on a `<style>`, an undocumented attribute, word or class, an inline style that sets anything else, and a `dui-*` element whose module is not loaded. Then check it with [axe](https://github.com/dequelabs/axe-core) and at 320px wide ([WCAG 1.4.10](https://www.w3.org/WAI/WCAG22/Understanding/reflow.html)).

Compose before you invent. Most interface "components" are arrangements of elements that already look finished together, such as a sign-in card (a `data-card` holding a form), a [stat row](https://domestic-ui.odonckers.dev/patterns/stat-row.md) (a `.grid` of small cards) or a confirm dialog (a `data-dialog` with a `<footer>` of buttons). This is rung 3 of the [decision ladder](https://github.com/odonckers/domestic-ui/blob/main/docs/ARCHITECTURE.md#3-the-decision-ladder). When a page needs something no composition can say, that is a gap in domestic-ui. [Open an issue](https://github.com/odonckers/domestic-ui/issues/new) instead of adding CSS to the page. The vocabulary is part of the [public API](https://github.com/odonckers/domestic-ui/blob/main/docs/ARCHITECTURE.md#4-public-api-and-naming).

## An application page

The frame of every app screen: the [app shell](https://domestic-ui.odonckers.dev/patterns/app-shell.md) with its sidebar, then a [page header](https://domestic-ui.odonckers.dev/components/organisms/page-header.md) and the content. Swap the [dashboard](https://domestic-ui.odonckers.dev/patterns/dashboard.md) for a [data table](https://domestic-ui.odonckers.dev/patterns/data-table.md), [large form](https://domestic-ui.odonckers.dev/patterns/large-forms.md) or [list-detail](https://domestic-ui.odonckers.dev/patterns/list-detail.md). The [plain HTML demo](https://github.com/odonckers/domestic-ui/tree/main/demos/vanilla) has full dashboard, settings and orders screens written the same way.

[`examples/pages/app-page.html`](https://github.com/odonckers/domestic-ui/blob/main/examples/pages/app-page.html):

```html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Overview · Northwind</title>
    <meta name="description" content="The skeleton of an application page: app shell, sidebar navigation, page header and content, with no CSS of its own.">
    <link rel="stylesheet" href="../../css/domestic.css">
  </head>
  <body>
    <a class="visually-hidden" href="#main">Skip to main content</a>

    <dui-app-shell data-app-shell>
      <header>
        <button type="button" aria-controls="app-nav" aria-expanded="true" hidden>
          <svg data-icon viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true" focusable="false"><path d="M4 6h16M4 12h16M4 18h16"></path></svg>
          Menu
        </button>
        <a href="app-page.html" data-link="quiet"><strong>Northwind</strong></a>
        <dui-menu>
          <button type="button" popovertarget="user-menu">Maria Santos</button>
          <div id="user-menu" popover data-popover>
            <a href="#profile">Profile</a>
            <a href="#preferences">Preferences</a>
            <hr>
            <button type="button">Sign out</button>
          </div>
        </dui-menu>
      </header>

      <nav id="app-nav" aria-label="Main" data-nav>
        <ul>
          <li><a href="app-page.html" aria-current="page">Overview</a></li>
          <li><a href="#orders">Orders</a></li>
          <li><a href="#customers">Customers</a></li>
          <li>
            <details>
              <summary>Settings</summary>
              <ul>
                <li><a href="#settings-general">General</a></li>
                <li><a href="#settings-billing">Billing</a></li>
              </ul>
            </details>
          </li>
        </ul>
      </nav>

      <main id="main" class="stack">
        <header data-page-header>
          <h1>Overview</h1>
          <p>How the warehouse is doing this week.</p>
          <div class="cluster">
            <a href="#new-order" data-button="primary">New order</a>
            <button type="button" data-button="secondary">Export</button>
          </div>
        </header>

        <div data-dashboard>
          <section aria-labelledby="open-orders-title">
            <h2 id="open-orders-title">Open orders</h2>
            <p>18</p>
            <p data-text="small muted">4 more than last week</p>
          </section>
          <section aria-labelledby="shipped-title">
            <h2 id="shipped-title">Shipped this week</h2>
            <p>126</p>
            <p data-text="small muted">Since Monday</p>
          </section>
          <section aria-labelledby="late-title">
            <h2 id="late-title">Late</h2>
            <p>2</p>
            <p><span data-badge="danger">Needs attention</span></p>
          </section>
          <section data-dashboard-tile="full" aria-labelledby="recent-title">
            <h2 id="recent-title">Recent orders</h2>
            <section data-scroll="inline" aria-labelledby="recent-caption" tabindex="0">
              <table data-table>
                <caption id="recent-caption">The five newest orders</caption>
                <thead>
                  <tr>
                    <th scope="col">Order</th>
                    <th scope="col">Customer</th>
                    <th scope="col">Status</th>
                    <th scope="col" data-table-cell="number">Total</th>
                  </tr>
                </thead>
                <tbody>
                  <tr>
                    <th scope="row"><a href="#nw-2051">NW-2051</a></th>
                    <td>Maple Street Bakery</td>
                    <td><span data-badge="warning">Open</span></td>
                    <td data-table-cell="number">$216.00</td>
                  </tr>
                  <tr>
                    <th scope="row"><a href="#nw-2050">NW-2050</a></th>
                    <td>Harbor Lane Café</td>
                    <td><span data-badge="accent">Packed</span></td>
                    <td data-table-cell="number">$126.00</td>
                  </tr>
                  <tr>
                    <th scope="row"><a href="#nw-2049">NW-2049</a></th>
                    <td>Riverside Dental</td>
                    <td><span data-badge="success">Delivered</span></td>
                    <td data-table-cell="number">$185.00</td>
                  </tr>
                  <tr>
                    <th scope="row"><a href="#nw-2048">NW-2048</a></th>
                    <td>Summit Climbing Gym</td>
                    <td><span data-badge>Shipped</span></td>
                    <td data-table-cell="number">$255.00</td>
                  </tr>
                  <tr>
                    <th scope="row"><a href="#nw-2047">NW-2047</a></th>
                    <td>Pine &amp; Co. Interiors</td>
                    <td><span data-badge="danger">Late</span></td>
                    <td data-table-cell="number">$345.00</td>
                  </tr>
                </tbody>
              </table>
            </section>
          </section>
        </div>
      </main>

      <footer>
        <p data-text="small muted">Northwind is an example app. MIT licensed.</p>
      </footer>
    </dui-app-shell>

    <script type="module" src="../../web-components/dui-app-shell.js"></script>
    <script type="module" src="../../web-components/dui-menu.js"></script>
  </body>
</html>
```

## A content page

A page that is not an app: a site header with the brand and a `<nav>`, the content in `<main>`, small print in `<footer>`. The [plain document page layout](https://domestic-ui.odonckers.dev/layouts/page.md) gives these landmarks one centered column, so nothing touches the window edge.

[`examples/pages/content-page.html`](https://github.com/odonckers/domestic-ui/blob/main/examples/pages/content-page.html):

```html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Shipping guide · Northwind</title>
    <meta name="description" content="The skeleton of a content page: site header, an article and a footer, laid out from its landmarks with no CSS of its own.">
    <link rel="stylesheet" href="../../css/domestic.css">
  </head>
  <body>
    <!-- dui:snippet name="Document page" page="layouts/page" -->
    <a class="visually-hidden" href="#main">Skip to main content</a>

    <header>
      <a href="#home" data-link="quiet"><strong>Northwind</strong></a>
      <nav aria-label="Main" data-nav="horizontal">
        <ul>
          <li><a href="#features">Features</a></li>
          <li><a href="#pricing">Pricing</a></li>
          <li><a href="#guides" aria-current="page">Guides</a></li>
          <li><a href="#sign-in">Sign in</a></li>
        </ul>
      </nav>
    </header>

    <main id="main">
      <article>
        <h1>Shipping your first order</h1>
        <p data-text="lead">From a new order to a parcel on its way, in four steps.</p>

        <h2>Pick and pack</h2>
        <p>Open the order, check each line against the shelf, and scan the items into the parcel. Northwind warns you when a count does not match.</p>

        <h2>Choose a carrier</h2>
        <p>Rates from your connected carriers appear side by side. The cheapest one that meets the promised date is selected for you.</p>
        <div class="grid">
          <article data-card>
            <h3>Standard</h3>
            <p>Three to five working days. Tracking included.</p>
          </article>
          <article data-card>
            <h3>Express</h3>
            <p>Next working day when packed before 3 PM.</p>
          </article>
          <article data-card>
            <h3>Collect</h3>
            <p>The customer picks the parcel up from your warehouse.</p>
          </article>
        </div>

        <h2>Print and ship</h2>
        <p>Print the label and packing slip together, then mark the order as shipped. The customer gets the tracking link by email.</p>
        <p class="cluster">
          <a href="#new-order" data-button="primary">Create an order</a>
          <a href="#guides" data-button="secondary">All guides</a>
        </p>
      </article>
    </main>

    <footer>
      <p data-text="small">Northwind is an example company. MIT licensed.</p>
    </footer>
    <!-- /dui:snippet -->
  </body>
</html>
```

## A landing page

A content page made of bands: each `<section data-band>` in `<main>` runs the full window width with its content kept in the column. `data-band="hero"` opens the page with a hero-size title, and `data-surface="inverse"` turns a band dark for a call to action.

[`examples/pages/landing-page.html`](https://github.com/odonckers/domestic-ui/blob/main/examples/pages/landing-page.html):

```html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Northwind · Ship orders from one place</title>
    <meta name="description" content="The skeleton of a landing page: a hero band, full-width sections and a dark call to action, laid out with no CSS of its own.">
    <link rel="stylesheet" href="../../css/domestic.css">
  </head>
  <body>
    <!-- dui:snippet name="Landing page" page="layouts/page" -->
    <a class="visually-hidden" href="#main">Skip to main content</a>

    <header>
      <a href="#home" data-link="quiet"><strong>Northwind</strong></a>
      <nav aria-label="Main" data-nav="horizontal">
        <ul>
          <li><a href="#features" aria-current="page">Features</a></li>
          <li><a href="#pricing">Pricing</a></li>
          <li><a href="#guides">Guides</a></li>
          <li><a href="#sign-in">Sign in</a></li>
        </ul>
      </nav>
    </header>

    <main id="main">
      <section data-band="hero" aria-labelledby="hero-title">
        <h1 id="hero-title">Ship every order from one place</h1>
        <p data-text="lead">Northwind picks the carrier, prints the label and tells the customer, so your team only packs.</p>
        <p class="cluster">
          <a href="#sign-up" data-button="primary">Start free</a>
          <a href="#demo" data-button="secondary">Book a demo</a>
        </p>
      </section>

      <section data-band aria-labelledby="features-title">
        <h2 id="features-title">Built for small warehouses</h2>
        <div class="grid">
          <article data-card>
            <h3>Rates side by side</h3>
            <p>Every connected carrier, priced for each parcel.</p>
          </article>
          <article data-card>
            <h3>One label run</h3>
            <p>Labels and packing slips print together.</p>
          </article>
          <article data-card>
            <h3>Tracking by email</h3>
            <p>Customers get the link the moment you ship.</p>
          </article>
        </div>
      </section>

      <section data-band data-surface="inverse" aria-labelledby="cta-title">
        <h2 id="cta-title">Ready for your first parcel?</h2>
        <p>Set up takes ten minutes. No card needed.</p>
        <p class="cluster">
          <a href="#sign-up" data-button="primary">Start free</a>
        </p>
      </section>
    </main>

    <footer>
      <p data-text="small">Northwind is an example company. MIT licensed.</p>
    </footer>
    <!-- /dui:snippet -->
  </body>
</html>
```

## A sign-in page

A `<main>` whose only child is one [card](https://domestic-ui.odonckers.dev/patterns/card.md) is a narrow page, centered on both axes when there is no site header: sign-in, sign-up and error pages.

[`examples/pages/sign-in.html`](https://github.com/odonckers/domestic-ui/blob/main/examples/pages/sign-in.html):

```html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Sign in · Northwind</title>
    <meta name="description" content="A sign-in page: one card centered on the page, laid out from its landmarks with no CSS of its own.">
    <link rel="stylesheet" href="../../css/domestic.css">
  </head>
  <body>
    <!-- dui:snippet name="Sign-in page" page="layouts/page" -->
    <main id="main">
      <article data-card aria-labelledby="sign-in-title">
        <h1 id="sign-in-title">Sign in to Northwind</h1>
        <p data-text="muted">Welcome back. Enter your details to continue.</p>
        <form class="stack" method="post" action="#sign-in">
          <div data-field>
            <label for="sign-in-email">Email</label>
            <input type="email" id="sign-in-email" name="email" autocomplete="email" required>
          </div>
          <div data-field>
            <label for="sign-in-password">Password</label>
            <input type="password" id="sign-in-password" name="password" autocomplete="current-password" required>
          </div>
          <label><input type="checkbox" name="remember"> Remember me on this device</label>
          <button type="submit" data-button="primary">Sign in</button>
        </form>
        <footer>
          <p data-text="small"><a href="#reset">Forgot your password?</a></p>
          <p data-text="small">New to Northwind? <a href="#sign-up">Create an account</a></p>
        </footer>
      </article>
    </main>
    <!-- /dui:snippet -->
  </body>
</html>
```

## The vocabulary

Every attribute, word, class, custom element and custom property a page may use, read from the API comments in `css/` (the same list the checker uses). Each attribute links to its docs page. Native attributes (`aria-current`, `aria-sort`, `open`, `popover`, `closedby`) are not listed because they are HTML.

Attributes (words combine, space-separated, where it makes sense: `data-button="primary small"`):

- `data-action-bar`: bare ([docs](https://domestic-ui.odonckers.dev/layouts/action-bar.md))
- `data-alert`: `danger`, `info`, `success`, `warning` ([docs](https://domestic-ui.odonckers.dev/patterns/alerts.md))
- `data-app-shell`: bare, or `contained`, `page` ([docs](https://domestic-ui.odonckers.dev/patterns/app-shell.md))
- `data-badge`: bare, or `accent`, `danger`, `neutral`, `outline`, `primary`, `success`, `warning` ([docs](https://domestic-ui.odonckers.dev/components/atoms/badge.md))
- `data-band`: bare, or `hero` ([docs](https://domestic-ui.odonckers.dev/layouts/page.md))
- `data-breadcrumb`: bare ([docs](https://domestic-ui.odonckers.dev/patterns/breadcrumb.md))
- `data-button`: bare, or `danger`, `icon`, `large`, `primary`, `quiet`, `secondary`, `small` ([docs](https://domestic-ui.odonckers.dev/components/atoms/button.md))
- `data-card`: bare, or `link` ([docs](https://domestic-ui.odonckers.dev/patterns/card.md))
- `data-color-scheme`: bare, or `dark`, `light` ([docs](https://domestic-ui.odonckers.dev/principles/theming.md))
- `data-contrast`: bare, or `more` ([docs](https://domestic-ui.odonckers.dev/principles/theming.md))
- `data-dashboard`: bare ([docs](https://domestic-ui.odonckers.dev/patterns/dashboard.md))
- `data-dashboard-tile`: `full`, `wide` ([docs](https://domestic-ui.odonckers.dev/patterns/dashboard.md))
- `data-density`: `comfortable`, `compact` ([docs](https://domestic-ui.odonckers.dev/principles/theming.md))
- `data-dialog`: bare, or `drawer`, `end`, `start` ([docs](https://domestic-ui.odonckers.dev/patterns/dialog.md))
- `data-disclosure`: `accordion`, `plain` ([docs](https://domestic-ui.odonckers.dev/patterns/disclosure.md))
- `data-field`: bare ([docs](https://domestic-ui.odonckers.dev/components/atoms/field.md))
- `data-field-error`: bare ([docs](https://domestic-ui.odonckers.dev/components/atoms/field.md))
- `data-field-hint`: bare ([docs](https://domestic-ui.odonckers.dev/components/atoms/field.md))
- `data-filter-bar`: bare ([docs](https://domestic-ui.odonckers.dev/patterns/filter-bar.md))
- `data-form-sections`: bare ([docs](https://domestic-ui.odonckers.dev/patterns/large-forms.md))
- `data-icon`: bare, or `mirror` ([docs](https://domestic-ui.odonckers.dev/components/atoms/icon.md))
- `data-link`: `nav`, `quiet` ([docs](https://domestic-ui.odonckers.dev/components/atoms/link.md))
- `data-list-detail`: bare ([docs](https://domestic-ui.odonckers.dev/patterns/list-detail.md))
- `data-motion`: bare, or `none`, `reduced` ([docs](https://domestic-ui.odonckers.dev/principles/theming.md))
- `data-nav`: bare, or `horizontal`, `vertical` ([docs](https://domestic-ui.odonckers.dev/patterns/nav.md))
- `data-page-header`: bare ([docs](https://domestic-ui.odonckers.dev/components/organisms/page-header.md))
- `data-pagination`: bare ([docs](https://domestic-ui.odonckers.dev/patterns/pagination.md))
- `data-popover`: bare, or `block-start`, `inline-end`, `inline-start` ([docs](https://domestic-ui.odonckers.dev/patterns/popover.md))
- `data-prose`: bare ([docs](https://domestic-ui.odonckers.dev/principles/theming.md))
- `data-scroll`: `block`, `inline` ([docs](https://domestic-ui.odonckers.dev/layouts/scroll.md))
- `data-split`: bare, or `1:1`, `1:2`, `2:1` ([docs](https://domestic-ui.odonckers.dev/patterns/split.md))
- `data-surface`: `inverse` ([docs](https://domestic-ui.odonckers.dev/principles/theming.md))
- `data-table`: bare, or `sticky` ([docs](https://domestic-ui.odonckers.dev/patterns/data-table.md))
- `data-table-cell`: `number`, `sortable` ([docs](https://domestic-ui.odonckers.dev/patterns/data-table.md))
- `data-text`: `lead`, `muted`, `small` ([docs](https://domestic-ui.odonckers.dev/components/atoms/text.md))
- `data-theme`: `calm`, `compact`, `neutral`, `soft` ([docs](https://domestic-ui.odonckers.dev/principles/themes.md))

Classes: `cluster`, `grid`, `stack`, `visually-hidden`.

Custom elements (load `web-components/<name>.js` as a module): `dui-app-shell`, `dui-combobox`, `dui-menu`, `dui-table`, `dui-tabs`, `dui-toaster`, `dui-toolbar`, `dui-tooltip`.

Knobs, the only custom properties a `style` attribute should set besides semantic `--dui-*` tokens: `--cluster-align`, `--cluster-gap`, `--cluster-justify`, `--dui-contrast`, `--dui-size-pane`, `--dui-size-sidebar`, `--dui-size-sidebar-aux`, `--grid-gap`, `--grid-min`, `--stack-gap`.

## Which pattern for which job

| You need | Use |
| --- | --- |
| The frame of an app: bar, sidebar, content | [App shell](https://domestic-ui.odonckers.dev/patterns/app-shell.md) |
| A title, description and actions at the top of a screen | [Page header](https://domestic-ui.odonckers.dev/components/organisms/page-header.md) |
| Summary numbers and panels that reflow | [Dashboard](https://domestic-ui.odonckers.dev/patterns/dashboard.md) |
| A row of headline numbers | [Stat row](https://domestic-ui.odonckers.dev/patterns/stat-row.md) |
| A list or table with nothing in it yet | [Empty state](https://domestic-ui.odonckers.dev/patterns/empty-state.md) |
| Team members with their roles | [People list](https://domestic-ui.odonckers.dev/patterns/people-list.md) |
| Recent events, newest first | [Notifications list](https://domestic-ui.odonckers.dev/patterns/notifications-list.md) |
| The signed-in person's links and sign out | [Account menu](https://domestic-ui.odonckers.dev/patterns/account-menu.md) |
| A grid of teasers, each with one link | [Card](https://domestic-ui.odonckers.dev/patterns/card.md) in a [`.grid`](https://domestic-ui.odonckers.dev/layouts/grid.md) |
| Rows of records, sorting, selection | [Data table](https://domestic-ui.odonckers.dev/patterns/data-table.md) with `<dui-table>` |
| Narrowing a list or table | [Filter bar](https://domestic-ui.odonckers.dev/patterns/filter-bar.md) |
| A long form in groups, with Save at the bottom | [Large forms](https://domestic-ui.odonckers.dev/patterns/large-forms.md) and the [action bar](https://domestic-ui.odonckers.dev/layouts/action-bar.md) |
| Settings, or a list beside the selected item | [List-detail](https://domestic-ui.odonckers.dev/patterns/list-detail.md) |
| Views of one thing, one at a time | [Tabs](https://domestic-ui.odonckers.dev/patterns/tabs.md), only when the views are peers; otherwise links |
| A confirmation or a short task on top of the page | [Dialog](https://domestic-ui.odonckers.dev/patterns/dialog.md) |
| Actions behind one button | [Menu button](https://domestic-ui.odonckers.dev/patterns/menu-button.md) |
| A status message | [Alerts](https://domestic-ui.odonckers.dev/patterns/alerts.md): inline, live or a toast |
| Show more or less | [Disclosure](https://domestic-ui.odonckers.dev/patterns/disclosure.md) |
