> A guide to [@fabiocv/ui](https://ui.fabio.cv/). Every guide is listed at https://ui.fabio.cv/llms.txt.

# Color

One ground, two quiet surfaces, a separator, four inks, one accent and the syntax colours of code.

## Rules

- Use `Colors` in UI code. It follows the theme, so a component rarely asks which one it is in. Plain CSS reads the same roles as variables, such as `var(--color-surface)`.
- Use `PaperTokens` only where a CSS variable cannot work, such as a canvas. Its colours are one theme's value, such as `--color-light-surface`, and do not follow the theme. `--color-dark-separator` and `--color-dark-code-text` refer to another token, so take the one they name. An Open Graph renderer may not read `oklch()`: give it the hex in these tables.
- Separate hierarchy with ink and weight. Never add a colour for emphasis.
- Surfaces step the same way in both themes. Surface subtle sits two steps off the page, Surface sunken one step darker and Separator one more. A step is `3.5` lightness points in both themes, wide enough for Surface sunken to show on a hover highlight, so dark Separator lands on the page.
- A surface on Surface subtle is one step darker, never lighter. A highlighted menu item takes Surface sunken.
- The accent is the same in light and dark. Set text on it in `--color-light-foreground`, in both themes.
- Text needs at least 4.5:1 against its surface. A date on a hover highlight takes Foreground secondary. Disabled items and code line numbers are the exceptions. Disabled controls are exempt and take Foreground disabled. Line numbers are a reference, not content, and sit at `3:1`.
- Foreground muted reaches 4.5:1 on Surface subtle too, as a menu's group labels are set in it there.
- Code sits on Surface sunken and takes `CodeColors`, the one place where hue carries meaning. Each syntax role keeps its hue and chroma in both themes, and Attribute takes the accent's hue. Light sets all four at `46%` lightness, so none reads louder.
- Show focus with `focusRing` from [`@fabiocv/ui/focus-ring`](https://ui.fabio.cv/focus-ring/index.md): a `2px` outline in `currentColor`, inside the element's edge, revealed from its inner edge out.
- A project's images and mockups keep their own colours. Do not turn them into tokens.

## Roles

| Role                 | Use for                                                                                                      | On fabio.cv                       | Code                         | CSS variable                   |
| -------------------- | ------------------------------------------------------------------------------------------------------------ | --------------------------------- | ---------------------------- | ------------------------------ |
| Surface              | The page background, and a drawer's sheet in light                                                           |                                   | `Colors.Surface`             | `--color-surface`              |
| Surface subtle       | Menus, toggle tracks, a switch's track while off, hover highlights on the page, and a drawer's sheet in dark | Thumbnail placeholders            | `Colors.SurfaceSubtle`       | `--color-surface-subtle`       |
| Surface sunken       | Highlighted menu items, pressed toggles and hover highlights on Surface subtle                               | The page scrollbar                | `Colors.SurfaceSunken`       | `--color-surface-sunken`       |
| Separator            | The line between groups in a menu, pressed toggles with a clear track, and the hovered square in a tag       |                                   | `Colors.Separator`           | `--color-separator`            |
| Foreground           | Names, the hovered item of a menu or toggle, and a switch's track while on                                   | The name and the portrait         | `Colors.Foreground`          | `--color-foreground`           |
| Foreground secondary | Body copy, the labels of controls, and icons                                                                 | Writing titles and hovered dates  | `Colors.ForegroundSecondary` | `--color-foreground-secondary` |
| Foreground muted     | Section headings, dates, menu group labels and the tooltip's ground                                          | The headline and the client logos | `Colors.ForegroundMuted`     | `--color-foreground-muted`     |
| Foreground disabled  | Disabled buttons, menu items, toggles and switches                                                           | The code scrollbar                | `Colors.ForegroundDisabled`  | `--color-foreground-disabled`  |
| Accent               | Nothing in the components                                                                                    | The Open Graph card's ground      | `Colors.Accent`              | `--color-accent`               |

On fabio.cv, the portrait is smoke in Foreground on the page in dark. In light it inverts the page, so the face stays white: Foreground is its tile and Surface its smoke.

## Light

| Token                                | Value                      | Hex       | On surface | On subtle |
| ------------------------------------ | -------------------------- | --------- | ---------- | --------- |
| `--color-light-surface`              | `oklch(100% 0 0)`          | `#FFFFFF` |            |           |
| `--color-light-surface-subtle`       | `oklch(93% 0 0)`           | `#E8E8E8` |            |           |
| `--color-light-surface-sunken`       | `oklch(89.5% 0 0)`         | `#DCDCDC` |            |           |
| `--color-light-separator`            | `oklch(86% 0 0)`           | `#D1D1D1` |            |           |
| `--color-light-foreground`           | `oklch(22.7% 0.006 271.2)` | `#1B1C1F` | 17.0:1     | 13.9:1    |
| `--color-light-foreground-secondary` | `oklch(41.8% 0.014 274.6)` | `#4A4C54` | 8.5:1      | 7.0:1     |
| `--color-light-foreground-muted`     | `oklch(52% 0.044 267.6)`   | `#5E6883` | 5.5:1      | 4.5:1     |
| `--color-light-foreground-disabled`  | `oklch(72% 0.01 270)`      | `#A2A4AB` | 2.5:1      | 2.0:1     |

## Dark

| Token                               | Value                       | Hex       | On surface | On subtle |
| ----------------------------------- | --------------------------- | --------- | ---------- | --------- |
| `--color-dark-surface`              | `oklch(17.5% 0 0)`          | `#101010` |            |           |
| `--color-dark-surface-subtle`       | `oklch(24.5% 0 0)`          | `#202020` |            |           |
| `--color-dark-surface-sunken`       | `oklch(21% 0 0)`            | `#181818` |            |           |
| `--color-dark-separator`            | `var(--color-dark-surface)` | `#101010` |            |           |
| `--color-dark-foreground`           | `oklch(92.3% 0.004 286.3)`  | `#E5E5E8` | 15.1:1     | 12.9:1    |
| `--color-dark-foreground-secondary` | `oklch(78.2% 0.016 281.9)`  | `#B6B7C2` | 9.5:1      | 8.1:1     |
| `--color-dark-foreground-muted`     | `oklch(67.3% 0.028 276.2)`  | `#9195A8` | 6.4:1      | 5.5:1     |
| `--color-dark-foreground-disabled`  | `oklch(48% 0.01 280)`       | `#5C5D63` | 2.9:1      | 2.5:1     |

## Accent

| Token            | Value     | Foreground on it |
| ---------------- | --------- | ---------------- |
| `--color-accent` | `#A8D8F0` | 11.1:1           |

## Code

| Role        | Use for                                     | Code                    | CSS variable         |
| ----------- | ------------------------------------------- | ----------------------- | -------------------- |
| Text        | Plain text, names, punctuation and comments | `CodeColors.Text`       | `--code-text`        |
| Line number | The number beside each line                 | `CodeColors.LineNumber` | `--code-line-number` |
| Tag         | Elements, components, types and functions   | `CodeColors.Tag`        | `--code-tag`         |
| Attribute   | Props and properties, such as `size`        | `CodeColors.Attribute`  | `--code-attribute`   |
| String      | Strings and patterns, such as `"default"`   | `CodeColors.String`     | `--code-string`      |
| Keyword     | Keywords, booleans, `null` and numbers      | `CodeColors.Keyword`    | `--code-keyword`     |

| Token                            | Value                                | Hex       | On sunken |
| -------------------------------- | ------------------------------------ | --------- | --------- |
| `--color-light-code-text`        | `oklch(49% 0.04 268)`                | `#576078` | 4.6:1     |
| `--color-light-code-line-number` | `oklch(59% 0.02 270)`                | `#787D8A` | 3.0:1     |
| `--color-light-code-tag`         | `oklch(46% 0.185 145.3)`             | `#007000` | 4.6:1     |
| `--color-light-code-attribute`   | `oklch(46% 0.088 229.9)`             | `#0B607F` | 5.1:1     |
| `--color-light-code-string`      | `oklch(46% 0.191 32.2)`              | `#A90000` | 5.7:1     |
| `--color-light-code-keyword`     | `oklch(46% 0.2 317.2)`               | `#821D9F` | 5.8:1     |
| `--color-dark-code-text`         | `var(--color-dark-foreground-muted)` | `#9195A8` | 6.0:1     |
| `--color-dark-code-line-number`  | `oklch(51% 0.02 276)`                | `#636572` | 3.1:1     |
| `--color-dark-code-tag`          | `oklch(84.4% 0.185 145.3)`           | `#72EB7C` | 11.7:1    |
| `--color-dark-code-attribute`    | `oklch(85.7% 0.088 229.9)`           | `#92DBFF` | 11.7:1    |
| `--color-dark-code-string`       | `oklch(71.2% 0.191 32.2)`            | `#FF6A4F` | 6.3:1     |
| `--color-dark-code-keyword`      | `oklch(76.9% 0.2 317.2)`             | `#E685FF` | 7.7:1     |

Several values reach past sRGB into Display P3. Their hex is clipped to sRGB.

See it at https://ui.fabio.cv/color/.
