# Snippet

> A copyable shell command with a prompt that stays out of the copy.

- Status: beta
- Group: structure
- Page: https://www.digitaltableteur.com/design-system/components/snippet
- Contract: https://www.digitaltableteur.com/contracts/v1/Snippet.contract.json

## When to use

Snippet holds a command the reader will paste into a terminal. Pass the bare command: the prompt is drawn for you and never copied. Several commands render one per line and copy together.

## When not to use

- Do not use for multi-line source code or command output; use CodeBlock.

## Look-alikes

- Code: Do not use for a multi-line block or a command meant to be copied; use CodeBlock or Snippet.
- CodeBlock: Do not put source files or output in a Snippet; use CodeBlock.

## Props

| Prop | Type | Default | Description | Required |
| --- | --- | --- | --- | --- |
| `command` | `string \| readonly string[]` | none | The command, or several commands shown one per line. Write the command only: the prompt is chrome and never part of the text. | Yes |
| `prompt` | `boolean` | `true` | Show the `$` prompt before each command. Copy always leaves it out. | No |
| `theme` | `"default" \| "inverted"` | `default` | `inverted` renders the snippet in the dark theme on any page, for terminal emphasis. In the high-contrast themes it follows the page so contrast stays at the high-contrast level. | No |
| `copyable` | `boolean` | `true` | Show the copy button. | No |
| `copyLabel` | `string` | "Copy code" (translated) | Accessible name for the copy button. | No |
| `onCopy` | `(text: string) => void` | none | Called with the copied text (commands joined by newlines). | No |

## Variants

- Available themes: `default`, `inverted` (default `default`).

## Invalid combinations

The contract records no invalid combinations.

## Keyboard

| Key | Behaviour |
| --- | --- |
| Tab | Reaches the copy button. |
| Enter or Space | Copies the commands without the prompt. |

## Rules

Every item under When not to use is a MUST NOT. MUST and SHOULD follow RFC 2119.

| Level | Rule | How it is checked |
| --- | --- | --- |
| MUST | ARIA: The $ prompt is aria-hidden chrome; screen readers hear only the command. | Not yet verified: no evidence record. WCAG 4.1.2. |
| MUST | ARIA: Each command is a code element; the copy button is named "Copy code" by default. | Not yet verified: no evidence record. WCAG 4.1.2. |
| MUST | Required stories produce no axe violations at the configured severity. | Automated by `npm run test:stories:matrix:ci`. WCAG 2.5.8. |
| MUST | The accessibility tree (role, name, state) matches the committed snapshot for every required story. | Automated by `npm run test:stories:matrix:ci`. WCAG 1.3.1, 4.1.2. |
| MUST | The component remains legible and operable under a real browser forced-colors: active pass. | Automated by `npm run test:stories:hc`. |
| MUST | Every documented keyboard interaction works as specified. | Not yet verified: no evidence record. WCAG 2.1.1, 2.1.2. |
| MUST | A human completed an end-to-end accessibility review of this component. | Manual review, last on 2026-10-25. |
| SHOULD | Write the command only; the component draws the $ prompt. | Not stated in the contract. |
| SHOULD | Use inverted for terminal emphasis on a light page. | Not stated in the contract. |
| SHOULD NOT | Do not type $ into command; it would copy and render twice. | Not stated in the contract. |
| SHOULD NOT | Do not put source files or output in a Snippet; use CodeBlock. | Not stated in the contract. |

## Install and import

- Install: `npm install @digitaltableteur/react` (version 0.9.1, restricted access on npm).
- Import: `import { Snippet } from "@digitaltableteur/react";`
- Entry point: `@digitaltableteur/react/content` exports it too.
- Styles: import `@digitaltableteur/react/style.css` once at the app boundary.
- Also available as the custom element `<dt-snippet>`; see the custom elements manifest.

## Links

- Machine-readable contract (Design System Contract 1.0): https://www.digitaltableteur.com/contracts/v1/Snippet.contract.json
- Markdown version of this page: https://www.digitaltableteur.com/design-system/components/snippet.md
- Component index as JSON: https://www.digitaltableteur.com/design-system/components.json
- All components: https://www.digitaltableteur.com/design-system/components
- Source: The implementation lives in a private repository. This page, its Markdown twin and the contract are generated from it at build time and are the public source of truth.
