Home HTML Tags <samp> HTML <samp> Tag Definition
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.
Syntax
HTML Syntax <samp> sample output </samp>
Both start and end tags are required. Content is phrasing content. Parent must accept phrasing content.
Reference
Attributes <samp> has no element-specific attributes — only globals. Pick the right computer-text element:
Element Description Try it <samp>Sample / quoted program output Try 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 samples Try it
Try it
Live Preview Switch between inline sample output, a multi-line block, and a console-style transcript with kbd.
Code
HTML Examples Short, copy-ready snippets. Use Try It Yourself for a live editor.
1. Inline sample 2. With pre 3. Nested kbd 4. vs output Example 1 — Inline Sample Output Quote a short program message inside a sentence.
<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> When the process is complete, the utility will output Scan complete. Found N results. You can then proceed to the next step.
How It Works Write the surrounding sentence in normal text.Wrap the quoted result in <samp>.You may nest phrasing tags like <em> inside samp.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.
<p>I got this message:</p>
<pre><samp>Keyboard not found
Press F1 to continue</samp></pre> I got this message:
Keyboard not found
Press F1 to continue How It Works Use <pre> so spaces and newlines stay as written.Put <samp> inside to mark the text as sample output.Write each line of the message in the source.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.
<pre><samp>$ <kbd>echo Hello</kbd>
Hello</samp></pre> How It Works Wrap the whole transcript in <samp> (often inside pre).Mark the typed command with <kbd>.Leave the program’s reply as plain text inside samp.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.
<!-- 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> Example result: 42
samp = quoted sample; output = live page result.
How It Works Docs / tutorials: show what a program would print with <samp>.Interactive page: put calculated values in <output>.Do not swap them — wrong element confuses assistive tech and maintainers.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 outputMark 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 < and & 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).
Compatibility
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.
Remember
Key Takeaways One line: use <samp> for sample machine output; use output for live page results.
UA style
Default CSS Settings Typical user-agent styling for samp:
samp {
font-family: monospace;
} You can restyle with CSS. User or system font preferences may override your font-family choice (MDN).
Frequently Asked Questions What is the HTML samp tag used for? The samp element marks sample or quoted output from a computer program — for example an error message or console result shown in documentation.
How is samp different from code? code marks computer code (source). samp marks sample program output. Both often look monospace, but the meaning differs.
How is samp different from kbd? 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.
Should I use samp for live JavaScript results? No. For output generated by your page’s script, use the output element. Use samp for illustrative or quoted sample output in content.
Does samp have special attributes? No. It supports only global attributes such as class, id, and lang. Style the look with CSS if needed.
Is the samp tag deprecated? No. samp is Baseline and widely available. It is a standard phrasing element for sample output.
About the author Developer, cloud engineer, and technical writer
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
Helpful Share Copy link Suggestion