HTML <samp> Tag

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 3 Examples
HTML Text

What You’ll Learn

The <samp> tag marks sample output from programs and systems. This guide covers syntax, comparisons with code and kbd, styling, use cases, and best practices for beginners.

01

Sample Output

Program results.

02

vs code

Output not source.

03

vs kbd

Not key input.

04

Tutorials

Docs and blogs.

05

CSS Style

class and style.

06

Semantic

Meaningful markup.

What Is the <samp> Tag?

The <samp> tag is an HTML element designed to represent sample (or output) content. It is particularly useful when showcasing examples of computer code output, terminal text, or other types of sample data.

Valid HTML5 — Sample Output Element

Use samp for what a program prints or returns. Use code for the source code itself.

Common in coding tutorials, API documentation, and tech blogs where you show command-line results or mock system responses inline.

📝 Syntax

Enclose the sample content within opening <samp> and closing </samp> tags:

syntax.html
<samp>Your Sample Output Here</samp>

Syntax Rules

  • Use samp inline inside paragraphs and list items.
  • Wrap actual or example program output, not source code.
  • Use pre for multi-line block output with preserved whitespace.
  • Apply global attributes like class and style for presentation.

⚡ Quick Reference

TopicCode SnippetNotes
Inline output<samp>text</samp>Sample result
Source codeUse codeNot samp
Keyboard keysUse kbdNot samp
Block outputUse preMulti-line
Stylingclass, styleGlobal attrs
Browser supportUniversalAll browsers

⚖️ <samp> vs <code> vs <kbd>

ElementRepresentsExample
<samp>Program outputHello, World!
<code>Source codeconsole.log()
<kbd>Keyboard inputEnter

🧰 Attributes

The <samp> tag has no tag-specific attributes. Use global attributes like class and style to customize the appearance of sample output.

attributes.html
<samp class="highlight" style="color: #0066cc;">
  Your Styled Sample Output Here
</samp>
class CSS

Apply a class for reusable sample output styling.

class="highlight"
style Inline

Inline color, font, or background overrides.

style="color: #0066cc"
title Tooltip

Extra context about the sample output.

title="Terminal output"

Examples Gallery

Display program output and sample data with samp in tutorials and documentation.

👀 Live Preview

Command output shown inline:

In this example, the output of the command is Hello, World!.

📚 Common Use Cases

The <samp> tag represents computer code output and sample data within the context of a document.

Displaying Code Output

The primary purpose of samp is to represent the output of computer code or commands.

displaying-code-output.html
In this example, the output of the command is <samp>Hello, World!</samp>.
Try It Yourself

Sample Data Representation

Use samp when presenting sample data, such as mock user input or system responses.

sample-data-representation.html
<samp>User Input: John Doe</samp>
Try It Yourself

♿ Accessibility

  • Use samp semantically — Distinguish program output from source code and keyboard input.
  • Provide surrounding context — Explain what command or program produced the sample output.
  • Do not rely on monospace alone — The samp element carries semantic meaning beyond font styling.
  • Use pre for long output — Multi-line terminal dumps belong in pre, not inline samp.

🧠 How <samp> Works

1

Author wraps output text

Place sample program results inside samp tags.

Markup
2

Browser renders monospace

Default styles display samp in a monospace font.

Render
3

CSS enhances presentation

Optional class and style improve visual distinction.

Style
=

Clear sample output

Readers see program results distinguished from code and keys.

Browser Support

The <samp> tag is supported in all major browsers, including Internet Explorer.

Baseline · HTML4 / HTML5

Sample output everywhere

All browsers render <samp> with default monospace styling.

100% Core tag support
Google Chrome Fully supported
Full support
Mozilla Firefox Fully supported
Full support
Apple Safari Fully supported
Full support
Microsoft Edge Fully supported
Full support
Internet Explorer Fully supported · EOL
Full support
Opera Fully supported
Full support
<samp> tag 100% supported

Bottom line: Use <samp> confidently for sample output in any browser.

Conclusion

Mastering the <samp> tag empowers web developers to effectively showcase sample output and data within HTML documents. By following best practices and considering browser compatibility, you can enhance the clarity and visual appeal of your content.

💡 Best Practices

✅ Do

  • Use samp for program output and sample data
  • Ensure content accurately represents sample output
  • Apply CSS for better presentation
  • Pair with code when showing input and output

❌ Don’t

  • Use samp for source code snippets
  • Use samp for keyboard key names
  • Put long multi-line output in inline samp
  • Rely on monospace styling without semantic markup

Key Takeaways

Knowledge Unlocked

Six truths every developer should know about <samp>

Bookmark these before you mark sample output.

6
Core concepts
📝 02

Not code

Use code tag.

Distinction
03

Not kbd

Keys use kbd.

Distinction
📚 04

Tutorials

Docs and blogs.

Context
🎨 05

CSS Style

class / style.

CSS
🌐 06

100% Support

All browsers.

Compatibility

❓ Frequently Asked Questions

It marks sample output from programs, commands, or systems.
samp is program output. code is source code.
No tag-specific attributes. Global attributes like class and style apply.
Use pre for multi-line block output. Use samp for inline sample text.
Yes. Full support in every major browser.

Display Sample Output

Practice <samp> for program output and sample data in the Try It editor.

Try code output example →

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.

6 people found this page helpful