HTML <samp> Tag

Beginner
5 min read
Updated: Nov 2026
4 examples
Live preview

Definition and Usage

The <samp> element marks sample (or quoted) output from a computer program — an error message, console result, or other text the machine would print.

Browsers usually render it in a monospace font. Pair with <pre> for multi-line blocks, nest <kbd> for user-typed parts of a transcript, and use <output> for live results from your page’s JavaScript (MDN).

Baseline · Widely available.

Not deprecated. Core support has been stable across browsers since about July 2015 (and earlier in practice).

Not for live app results.

If JavaScript on your site generates the text, prefer <output>. Keep <samp> for illustrative sample output in articles and docs.

HTML Syntax

syntax.html
<samp> sample output</samp>

Both start and end tags are required. Content is phrasing content. Parent must accept phrasing content.

Attributes

<samp> has no element-specific attributes — only globals. Pick the right computer-text element:

ElementDescriptionTry it
<samp>Sample / quoted program outputTry it
<code>Computer source code (not output)See code tutorial
<kbd>User input (keys or typed commands)Try it
<output>Live result produced by the page (forms / JS)Try it
<pre>Preserve spaces and line breaks for multi-line samplesTry it

Global Attributes

The <samp> tag also supports the Global Attributes in HTML.

Live Preview

Switch between inline sample output, a multi-line block, and a console-style transcript with kbd.

demo style

A real <samp>. Apply a preset, then inspect the sample output.

Preview

When done, the tool prints Scan complete. Found N results.

Inline <samp> for a short quoted result.

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Inline Sample Output

Quote a short program message inside a sentence.

HTML
<p>
  When the process is complete, the utility will output
  <samp>Scan complete. Found <em>N</em> results.</samp>
  You can then proceed to the next step.
</p>
Try It Yourself

How It Works

  1. Write the surrounding sentence in normal text.
  2. Wrap the quoted result in <samp>.
  3. You may nest phrasing tags like <em> inside samp.
  4. Default look: monospace so it reads as machine output.

Example 2 — Multi-Line Sample with pre

Keep line breaks for a boot message or log snippet.

HTML
<p>I got this message:</p>
<pre><samp>Keyboard not found
Press F1 to continue</samp></pre>
Try It Yourself

How It Works

  1. Use <pre> so spaces and newlines stay as written.
  2. Put <samp> inside to mark the text as sample output.
  3. Write each line of the message in the source.
  4. Escape < / & in the HTML source if the sample contains those characters.

Example 3 — Console Transcript with kbd

Nest kbd inside samp when the sample includes what the user typed.

HTML
<pre><samp>$ <kbd>echo Hello</kbd>
Hello</samp></pre>
Try It Yourself

How It Works

  1. Wrap the whole transcript in <samp> (often inside pre).
  2. Mark the typed command with <kbd>.
  3. Leave the program’s reply as plain text inside samp.
  4. Meaning: kbd = input; surrounding samp = sample session output.

Example 4 — Prefer output for Live Results

Sample docs use samp. Live calculation on the page uses output.

HTML
<!-- Illustrative sample in docs -->
<p>Example result: <samp>42</samp></p>

<!-- Live result from the page -->
<form oninput="sum.value = (+a.value) + (+b.value)">
  <input type="number" id="a" name="a" value="20"> +
  <input type="number" id="b" name="b" value="22"> =
  <output name="sum" for="a b">42</output>
</form>
Try It Yourself

How It Works

  1. Docs / tutorials: show what a program would print with <samp>.
  2. Interactive page: put calculated values in <output>.
  3. Do not swap them — wrong element confuses assistive tech and maintainers.
  4. Optional: link output to controls with the for attribute.

Edge Cases & Pitfalls

Most mistakes are picking samp when you meant code, kbd, or output.

semantics

code is source, samp is output

Mark algorithms and snippets with <code>. Mark printed results with <samp>.

live UI

Do not use samp as a live result box

MDN: prefer <output> for values your site generates with script.

layout

Multi-line needs pre

Alone, samp is inline. Wrap with <pre> to keep newlines.

escape

Escape special characters in samples

Write &lt; and &amp; in HTML source when the sample contains those characters.

CSS

User fonts may override yours

You can set font-family on samp, but browser or OS preferences may still win (MDN note).

Browser Support

The <samp> element is core HTML phrasing content in every modern browser. It is not a Node.js, Deno, or Bun API.

✓ Baseline · Widely available

<samp>

Widely available since about July 2015 (and long before). Chrome, Firefox, Safari, Edge, and Opera all support samp with default monospace styling.

98% Global support (approx.)
Google Chrome All
Full support
Mozilla Firefox All
Full support
Apple Safari All
Full support
Microsoft Edge All
Full support
Opera All
Full support
Samsung Internet All
Full support
Internet Explorer All
Supported
<samp> Widely supported

Bottom line: Safe to use everywhere for sample program output. Use code for source, kbd for input, and output for live page results.

Key Takeaways

  • Role: <samp> marks sample / quoted program output (usually monospace).
  • Neighbors: code = source; kbd = input; output = live result.
  • Blocks: wrap multi-line samples in <pre>.
  • Transcripts: nest <kbd> inside <samp> for typed commands.

One line: use <samp> for sample machine output; use output for live page results.

Default CSS Settings

Typical user-agent styling for samp:

default.css
samp {
  font-family: monospace;
}

You can restyle with CSS. User or system font preferences may override your font-family choice (MDN).

Frequently Asked Questions

The samp element marks sample or quoted output from a computer program — for example an error message or console result shown in documentation.
code marks computer code (source). samp marks sample program output. Both often look monospace, but the meaning differs.
kbd marks user input (keys or typed commands). samp marks what the computer printed back. You can nest kbd inside samp for a console transcript.
No. For output generated by your page’s script, use the output element. Use samp for illustrative or quoted sample output in content.
No. It supports only global attributes such as class, id, and lang. Style the look with CSS if needed.
No. samp is Baseline and widely available. It is a standard phrasing element for sample output.

Next: script

Embed or load JavaScript with the HTML script element.

script tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful