Snippet code

A code snippet block is a read-only panel that shows source as source: a monospaced body with syntax colour, the filename in the chrome above it, line numbers down the gutter and a copy button that puts the whole thing on the clipboard. Orvain's Snippet code family is one component in four dresses, light and dark, each either rounded with the code floating on an inset panel, or flush to the card's edge under a taller header.

Most readers never read a snippet. They copy it and find out what it does in their own project, which makes the clipboard the component's real output and the place these blocks usually go wrong: line numbers, prompt characters and a truncating ellipsis belong to the drawing, not to the code, and none of them should survive a copy. Wrapping is the second trap. Code is the rare content where a line break changes meaning, so a long line scrolls sideways, with the bar left visible, so the reader knows there is more.

4 blocks

Code window

Docs and code review on a light page: point at lines, discuss them, see the diff

Flush code

Dense docs and changelogs: the same review snippet with the code running edge to edge

Dark window

Landing pages and dark docs: the snippet reads as an editor you can comment in

Dark flush

Terminal-style review blocks: dark, edge to edge, with the change history in place

01

Using Snippet code

Reach for it when

  • Documentation whose next step is the reader pasting the code into their own file.
  • A changelog showing exactly what a migration changes.
  • An install command on a landing page, where the command is the proof.
  • Support answers that hand over a config file the reader has to keep intact.

Reach for something else when

  • A flag, a function name or a path inside a sentence. Inline code keeps the sentence moving; a panel stops it.
  • Code the reader is meant to change and run. That wants an editor or an embedded sandbox; a snippet is read-only on purpose.
  • A whole file. Nobody reads past a screenful: show the lines that matter and link to the source for the rest.
02

Where it shows up

01

Install instructions

The first block on a quickstart page: one command, a copy button and nothing competing with it. Dark chrome earns its place here, because the command reads as something you paste into a terminal.

02

API examples

A reference page showing the same call in two languages, each with its filename in the chrome, so a reader can tell the server example from the client one without reading a line of it.

03

Migration notes

A release note showing the before and the after as two blocks rather than as prose. Line numbers pay for themselves here, because the paragraph above can point at the line that moved.

04

Support answer

A reply handing over a config file. It gets copied whole, so comments and indentation have to arrive on the clipboard exactly as they were drawn, including the blank line nobody notices.

03

Questions

Should code blocks have line numbers?

Add them when the surrounding text refers to particular lines, or when the block runs long enough that a reader needs somewhere to point. Leave them off for a single command meant to be copied, where they are only noise. Either way keep the numbers out of the clipboard: they belong to the gutter, not to the source.

How should a code block behave on a narrow screen?

All blocks
The Orvain Dispatch

Premium components, free in your inbox.

Join the Orvain Dispatch and get production-ready components, free to keep: React and Vue code plus the Figma frame, yours to ship.

Just components, never spam. You can unsubscribe anytime.