Table of Content
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?
<p>Output: <samp>File saved successfully</samp></p>How do you style the <samp> tag with CSS?
<style>
samp {
color: blue;
font-weight: bold;
}
</style>
<p>Result: <samp>Success</samp></p>
What is the difference between <samp> and <code> tags?
<p>Command: <code>print("Hi")</code></p>
<p>Output: <samp>Hi</samp></p>
Can <samp> be nested inside other HTML tags?
<p>Message: <samp>Access Granted</samp></p>Similar Reads
Text on a page often moves from left to right. Some languages move from right to left. HTML gives control…
This article shows you how to open a link in a new tab. Read the code and follow the examples…
HTML is the main content for every web page. It helps you structure text, links, and media. You can build…
HTML global attributes work on most elements. They do not depend on the tag name. You can use them with…
HTML select tag and option tags let users pick values in a form. You use them to create dropdowns. The…
HTML link attributes tell the browser how a link works. They set where the link goes, how it opens, and…
The HTML a tag allows you to create links that move users from one page or resource to another. Understand…
The <code> tag in HTML shows short code, command names, or output. Use it to display text that the browser…
HTML Boolean attributes control the behavior of elements and do not need a value. These attributes simplify logic and reduce…
The nav tag defines a navigation block in HTML. It holds main links to other parts of your site. Search…