HTML samp Tag: How to Show Sample Program Output

HTML samp Tag

The HTML samp tag shows the result of a computer program or command. It helps readers know which text came from a system or code output.

Understand the samp Tag in HTML

The <samp> tag in HTML marks text as a sample output from a program, script, or system.

Here is the basic tag:

<samp>sample output text</samp>

It does not need extra attributes, but you can style it with CSS.

Web browsers show text inside the samp tag with a monospace font by default. This font helps readers tell program output apart from normal text.

Here is a quick example:

<p>Output: <samp>Hello World</samp></p>

This code shows the words Hello World in a monospace font. It tells the user that this text came from a program.

You can place <samp> inside paragraphs or table cells. It can also work with list items or inside preformatted text for code documentation.

How to Style the HTML samp Tag with CSS

You can use CSS to change the font, color, or size of the samp text. Here is a simple way to change its look:

<style>
samp {
  color: red;
  font-size: 16px;
  font-weight: bold;
}
</style>

This code makes the text in <samp> appear with custom styles.

Examples

Show Calculation Result from a Script:

<p>Calculation Result: <samp>42</samp></p>

The text 42 is marked as program output. You can use this way when you need to show results from scripts or math functions.

Style <samp> to Match Dark Mode Terminal:

<style>
samp {
  background-color: black;
  color: lime;
  padding: 4px;
}
</style>
<p>Output: <samp>File Uploaded</samp></p>

The CSS styles make the output look like a terminal screen in this example.

Combine <sam> with preformatted Text:

<pre>Server Response: <samp>200 OK</samp></pre>

The pre tag keeps the exact format, and samp marks the output.

Wrapping Up

In this article, you learned the purpose of the HTML<samp> tag and how to use it with CSS.

Here is a quick recap:

  • The samp tag shows sample program output.
  • Browsers show it in a monospace font by default.
  • You can style it with CSS for better presentation.
  • It works well inside many elements.

FAQs

What is the purpose of the <samp> tag in HTML?

The <samp> tag in HTML shows sample program output. It helps display how a command or code execution result will appear. Example:
<p>Output: <samp>File saved successfully</samp></p>

How do you style the <samp> tag with CSS?

You can style the <samp> tag like any other inline element. Set font, color, or background using CSS. Example:
<style>
samp {
  color: blue;
  font-weight: bold;
}
</style>
<p>Result: <samp>Success</samp></p>

What is the difference between <samp> and <code> tags?

The <samp> tag shows output from a program. The <code> tag shows code itself. Example:
<p>Command: <code>print("Hi")</code></p>
<p>Output: <samp>Hi</samp></p>

Can <samp> be nested inside other HTML tags?

Yes, you can nest the <samp> tag inside paragraphs or divs. It will still display sample output as intended. Example:
<p>Message: <samp>Access Granted</samp></p>

Similar Reads

HTML iframe Tag: How to Embed Content with Examples

The iframe tag embeds another HTML page inside the current page. It loads content from a separate source. Understand the…

HTML Link Attributes Guide for Beginners

HTML link attributes tell the browser how a link works. They set where the link goes, how it opens, and…

HTML bdi Tag: Control Text Direction in HTML

The HTML bdi tag marks text that has an unknown or mixed direction. It makes sure that this part does…

HTML meter Tag: Measurements with Examples

Purpose and use cases: The HTML meter tag shows a scalar value within a known range. You can use it…

HTML title Tag: How to Set Web Page Titles

The title tag in HTML shows the page name in the browser tab and helps search engines know the topic.…

HTML Footer Tag for Document Footers

The <footer> tag defines a footer section in HTML. It creates a clear endpoint for a page or section. Browsers…

HTML Class Attribute: Use in CSS and JavaScript

The HTML class attribute helps group elements. It helps you update the page style without changing the structure of HTML.…

HTML bdo Tag – Control Text Direction

Text on a page often moves from left to right. Some languages move from right to left. HTML gives control…

HTML Deprecated Tags and Modern Alternatives List

HTML tags that no longer work stay in the deprecated list. This article explains them and shows the modern replacements.…

HTML output Tag: How to Display Calculation Results

The <output> tag in HTML shows results inside a form. It helps display values from user actions or scripts. You…

Previous Article

PHP array_fill Function: Fill Array with Same Value

Next Article

PHP array_unshift: How to Add Values to the Start of an Array

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *


Subscribe to Get Updates

Get the latest updates on Coding, Database, and Algorithms straight to your inbox.
No spam. Unsubscribe anytime.