Definition
The <samp>
HTML element is used to represent sample or example output from a computer program, script, or code snippet. It is typically used to display text that represents the expected or simulated output of a program or the content of a file.
Here’s an example of how to use the <samp>
element:
<p>The output is: <samp>Hello, world!</samp></p>
In this example, the text “Hello, world!” is wrapped within the <samp>
element. The <samp>
element is used to indicate that the text represents sample output. By default, the text within the <samp>
element is typically displayed in a monospaced font to visually distinguish it from the surrounding content.
The <samp>
element can be used in conjunction with other elements, such as <code>
, to represent code snippets with both input and output:
<pre><code>
<span class="user-input">print("Enter your name:")</span>
<span class="program-output">name = input()</span>
<span class="program-output">print("Hello, " + name + "!")</span>
</code></pre>
In this example, the <samp>
element is used to represent the program output. By applying different styles or classes, you can distinguish between user input and program output, providing a clearer representation of the code.
It’s important to note that the <samp>
element is primarily used for displaying textual output. If you want to represent code or markup within your document, the <code>
element is more suitable.