code
Code shows what people type or copy, such as a command, a flag or a file name, in monospace. By default it sits inside a sentence; it can also stand on its own, as a block.
Set --replicas=0 to stop the service, then check that ctl get volumes lists the volume as detached.
when to use
- Inside a sentence, for what people type or copy: a command such as “ctl get volumes”, a flag such as “--replicas=0”, a file name or a setting.
- As a block, for a command people copy and run, a few lines of configuration, or a command with its output.
when to use something else
- For a key on the keyboard. Use a keycap, such as enter.
- For values in monospace that people read rather than type, such as durations, sizes and hashes in a list or a table cell. Use mono text: monospace, with no frame and no colour. A column of framed cyan cells is noise.
- For emphasis. Cyan pulls the eye, so keep it for code. To make a word stand out in a sentence, use interface text.
anatomy
Inline:
- Frame. A thin border on a darker shade of the canvas, close around the text, with square corners.
- Text. Monospace, in cyan.
Block:
- Frame. A thin border on the same darker shade, with room around the text and no space outside it. It scrolls sideways.
- Text. Monospace, in light grey. Spaces and line breaks are kept as written. Long lines scroll, and never wrap.
variants and states
Inline code sits in running text. It wraps with the sentence, at its spaces, so keep it short.
A block shows several lines exactly as written. It has no maximum height and grows with its content, so show a few lines, not a whole log.
$ ctl rollout status api-7f9c
waiting for rollout to finish: 1 of 3 updated
waiting for rollout to finish: 2 of 3 updated
rollout finished: 3 of 3 updatedA long line scrolls inside the block instead of wrapping.
ctl backup create --volume storage-01 --target https://backup.example.com/v1/archive --keep 14d --verifyBlocks can follow one another.
ctl login https://ops.example.com
ctl get volumesctl release create 2.4.1There is no syntax highlighting, so all the code is in one colour. There are no line numbers, no copy button and no way to wrap long lines either.
behaviour
- Inline code, and a block that fits, aren't a tab stop.
- A block whose lines run past its edge becomes a tab stop of its own while it overflows: tab reaches it, and the arrow keys scroll it.
- The text in both forms can be selected and copied like any other text.
The full keyboard map is on the React page for code.
accessibility
- Most screen readers read the text without saying “code”.
- A block keeps its line breaks, and screen readers read it line by line.
- A block that scrolls has a name of its own, its accessible name, and that name is “code” unless you give it a better one. Name it after what it holds: “install command”.
- The cyan of inline code and the light grey of a block both have plenty of contrast on their background.
- Symbols are read out as they are. The prompt, the “$” a terminal shows before a command, is read as “dollar”. Leave it out of commands people copy.
content
- Show the command exactly as it runs, with real flags. Use made-up names and hosts: “api-7f9c”, “storage-01”, “example.com”.
- A command people copy has no prompt. When you show a command with its output, mark the typed line with “$”, so the two read apart.
- Inline code is one word, or something just as short, such as a flag. A command longer than a few words gets a block.
- Don't put a sentence in code.
do and don't
Set --replicas=0 before the backup.
scale it down before the backupctl backup create --volume storage-01 --keep 14dRun ctl backup create --volume storage-01 --keep 14d --verify and wait.
related
- Kbd: a key on the keyboard, not code.
- Text: mono text, for values people read, without a frame.
- Content & voice: how commands, names and examples are written.
specs
| form | in code | frame | text |
|---|---|---|---|
| Inline | <Code>, the default: a code element |
A 1px --border, a --bg-2 fill, padding 1px 6px, border-radius: 0 |
JetBrains Mono 13px, line height 1.5, --cloud-cyan |
| Block | <Code block>: a pre with a code inside |
A 1px --border, a --bg-2 fill, padding 12px 16px, no margin, border-radius: 0, overflow-x: auto |
JetBrains Mono 13px, line height 1.5, --fg-2; white-space: pre keeps spaces and line breaks, and long lines scroll |
- A block that overflows: while its lines run past its edge, it is a focusable region (
tabindex="0",role="region", named “code”). Pass anaria-label, such as “install command”, to name it better. Keyboard focus: a 2px--focus-ringoutline, 2px outside the frame. - Contrast:
--cloud-cyanon--bg-2is about 6.6:1; block text in--fg-2is about 12:1. - Mono text:
<Text variant="code">, for values people read, without a frame. - Interface text:
<Text variant="ui">, for emphasis in a sentence.