samp
The HTML <samp> element marks sample output from a computer program, command, or system. It distinguishes what the computer responds with from what the user types.
What you will learn
- What kind of output
samprepresents - How to distinguish it from
kbdandcode - How to show output examples with enough context
Basic example
<p>Run the command and you will see:
<samp>Build complete</samp>
</p>
The text inside samp is a sample response produced by a system. It is not an instruction for the user to type.
kbd, code, and samp are different
kbd- Input the user should enter or a key the user should press.
code- A fragment of a program or code-like syntax.
samp- Output produced by a program, command, or system.
<p>Type <kbd>help</kbd>.</p>
<p>The terminal prints <samp>Available commands: build, test</samp>.</p>
<p>The function is written as <code>showHelp()</code>.</p>
Use it for examples, not live status
samp communicates the meaning of sample output in documentation. For a live status message in an application, use an appropriate live-region pattern and update behavior intentionally; a semantic inline element alone does not announce dynamic changes.
Keep output understandable
Explain what action produced the output and whether the example is exact or abbreviated. If output spans multiple lines, a pre block can preserve formatting, with samp marking the output inside it when useful.
Common mistakes
- Using
sampfor commands the reader is supposed to type. - Using it for source code rather than
code. - Relying only on the default monospace style to explain the meaning.
- Showing output without telling readers how it was produced.