Terminal-oriented documentation often prefixes command lines with a $ to echo the shell prompt you see in an interactive session. The convention reads as this line belongs on the command line, but it breaks down the moment someone copies the line verbatim: $ is not a command, and running the pasted text fails. Anyone who has ever pasted the dollar sign knows the documentation actually meant to run the command alone, without the marker.

That gap is minor as such problems go—every discipline carries implicit context it never states outright—but it can still be handled better than telling readers they simply have to know.

Moving the dollar sign into CSS

Documentation markup typically looks like this:

<p>Install package like:</p>

<pre><code class="command">brew install package</code></pre>

The fix is to inject the $ as a pseudo-element instead of writing it as literal text:

code.command::before {
  content: "$ ";
}

Besides trimming a character from the HTML, this makes the marker unselectable—that is how pseudo-elements behave. A reader who double-clicks the line or selects it in full won't drag a stray $ into the clipboard and corrupt the copy-paste.

Repository-hosted docs such as GitHub README files aren't in the same position: you can't add a stylesheet to control how they render. In those settings, the convention has to be stated explicitly rather than styled away.

Markup and shell-prompt considerations

  • Syntax highlighting is arguably wasted on shell examples; interactive shells don't color commands as you type them.
  • Eric Meyer proposed the <kbd> element (Keyboard Input), which fits here better than the long-favored <code>.
  • Tim Chase suggested keeping the prompt inside a <span> in the HTML so it can be styled separately, including with user-select: none;.
  • Justin Searls has a dotfiles trick that discards an accidentally pasted $ and executes only the text after it.
  • Jackson Bates stresses caution about exactly what you paste into a terminal.
  • The $ also marks unprivileged commands, while # marks root-level ones—partly because a pasted root command is ignored as a comment.