blob: c63e916b89bf8a9be6d996522655debc33de8908 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
<header><h1><samp>: The Sample Output element</h1></header><div class="section-content"><p>The <code><samp></code> <a href="../index">HTML</a> element is used to enclose inline text which represents sample (or quoted) output from a computer program. Its contents are typically rendered using the browser's default monospaced font (such as <a href="https://en.wikipedia.org/wiki/Courier_(typeface)" target="_blank">Courier</a> or Lucida Console).</p></div>
<h2 id="try_it">Try it</h2>
<div class="section-content"><iframe class="interactive is-tabbed-shorter-height" height="200" src="https://interactive-examples.mdn.mozilla.net/pages/tabbed/samp.html" title="MDN Web Docs Interactive Example" loading="lazy"></iframe></div>
<h2 id="attributes">Attributes</h2>
<div class="section-content"><p>This element only includes the <a href="../global_attributes">global attributes</a>.</p></div>
<h2 id="usage_notes">Usage notes</h2>
<div class="section-content">
<p>You can use a CSS rule to override the browser's default font face for the <code><samp></code> element; however, it's possible that the browser's preferences may take precedence over any CSS you specify.</p> <p>The CSS to override the default font face would look like this:</p> <div class="code-example">
<p class="example-header"><span class="language-name">css</span></p>
<pre data-signature="Uxw6ThaSsf8ELJtNXLp/NodTL+pg+/PyYbpDm+BUX0s=" data-language="css"><span class="token selector">samp</span> <span class="token punctuation">{</span>
<span class="token property">font-family</span><span class="token punctuation">:</span> <span class="token string">"Courier"</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</pre>
</div> <div class="notecard note" id="sect1"> <p><strong>Note:</strong> If you need an element which will serve as a container for output generated by your website or app's JavaScript code, you should instead use the <a href="output"><code><output></code></a> element.</p> </div>
</div>
<h2 id="examples">Examples</h2>
<h3 id="basic_example">Basic example</h3>
<div class="section-content">
<p>In this simple example, a paragraph includes an example of the output of a program.</p> <div class="code-example">
<p class="example-header"><span class="language-name">html</span></p>
<pre data-signature="XiIjkvkBVMlSUxZu3prSx0AVs4qF37gU/KvgxN5Y9/Q=" data-language="html"><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>p</span><span class="token punctuation">></span></span>
When the process is complete, the utility will output the text
<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>samp</span><span class="token punctuation">></span></span>Scan complete. Found <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>em</span><span class="token punctuation">></span></span>N<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>em</span><span class="token punctuation">></span></span> results.<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>samp</span><span class="token punctuation">></span></span> You can then proceed to
the next step.
<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>p</span><span class="token punctuation">></span></span>
</pre>
</div> <h4 id="result">Result</h4>
<div class="code-example" id="sect2">
<iframe class="sample-code-frame" title="Basic example sample" id="frame_basic_example" width="650" height="100" src="https://live.mdnplay.dev/en-US/docs/Web/HTML/Element/samp/runner.html?id=basic_example" loading="lazy"></iframe>
</div>
</div>
<h3 id="sample_output_including_user_input">Sample output including user input</h3>
<div class="section-content">
<p>You can nest the <a href="kbd"><code><kbd></code></a> element within a <code><samp></code> block to present an example that includes text entered by the user. For example, consider this text presenting a transcript of a Linux (or macOS) console session:</p> <h4 id="html">HTML</h4> <div class="code-example">
<p class="example-header"><span class="language-name">html</span></p>
<pre data-signature="7h9Kd8DXpiv0gW4ouR5I4lqxiLlAQhryp2oj5TmkcQI=" data-language="html"><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>pre</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>samp</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>span</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>prompt<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>mike@interwebz:~$<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>span</span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>kbd</span><span class="token punctuation">></span></span>md5 -s "Hello world"<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>kbd</span><span class="token punctuation">></span></span>
MD5 ("Hello world") = 3e25960a79dbc69b674cd4ec67a72c62
<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>span</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>prompt<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>mike@interwebz:~$<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>span</span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>span</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>cursor<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>█<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>span</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation"></</span>samp</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation"></</span>pre</span><span class="token punctuation">></span></span>
</pre>
</div> <p>Note the use of <a href="span"><code><span></code></a> to allow customization of the appearance of specific portions of the sample text such as the shell prompts and the cursor. Note also the use of <code><kbd></code> to represent the command the user entered at the prompt in the sample text.</p> <h4 id="css">CSS</h4> <p>The CSS that achieves the appearance we want is:</p> <div class="code-example">
<p class="example-header"><span class="language-name">css</span></p>
<pre data-signature="FJYp9Hh/WyPQU8y6IFO1AgNTQsNF00LXnOuQB/rkqwg=" data-language="css"><span class="token selector">.prompt</span> <span class="token punctuation">{</span>
<span class="token property">color</span><span class="token punctuation">:</span> #b00<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token selector">samp > kbd</span> <span class="token punctuation">{</span>
<span class="token property">font-weight</span><span class="token punctuation">:</span> bold<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token selector">.cursor</span> <span class="token punctuation">{</span>
<span class="token property">color</span><span class="token punctuation">:</span> #00b<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</pre>
</div> <p>This gives the prompt and cursor fairly subtle colorization and emboldens the keyboard input within the sample text.</p> <h4 id="result_2">Result</h4> <p>The resulting output is this:</p>
<div class="code-example" id="sect3">
<iframe class="sample-code-frame" title="Sample output including user input sample" id="frame_sample_output_including_user_input" width="650" height="120" src="https://live.mdnplay.dev/en-US/docs/Web/HTML/Element/samp/runner.html?id=sample_output_including_user_input" loading="lazy"></iframe>
</div>
</div>
<h2 id="technical_summary">Technical summary</h2>
<div class="section-content"><figure class="table-container"><div class="_table"><table class="properties"> <tbody> <tr> <th scope="row"><a href="../content_categories">Content categories</a></th> <td> <a href="../content_categories#flow_content">Flow content</a>, <a href="../content_categories#phrasing_content">phrasing content</a>, palpable content. </td> </tr> <tr> <th scope="row">Permitted content</th> <td>
<a href="../content_categories#phrasing_content">Phrasing content</a>.</td> </tr> <tr> <th scope="row">Tag omission</th> <td>None, both the starting and ending tag are mandatory.</td> </tr> <tr> <th scope="row">Permitted parents</th> <td> Any element that accepts <a href="../content_categories#phrasing_content">phrasing content</a>. </td> </tr> <tr> <th scope="row">Implicit ARIA role</th> <td><code><a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/generic_role">generic</a></code></td> </tr> <tr> <th scope="row">Permitted ARIA roles</th> <td>Any</td> </tr> <tr> <th scope="row">DOM interface</th> <td><a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement"><code>HTMLElement</code></a></td> </tr> </tbody> </table></div></figure></div>
<h2 id="specifications">Specifications</h2>
<div class="_table"><table class="standard-table">
<thead><tr><th scope="col">Specification</th></tr></thead>
<tbody><tr><td><a href="https://html.spec.whatwg.org/multipage/text-level-semantics.html#the-samp-element">HTML Standard <br><small># the-samp-element</small></a></td></tr></tbody>
</table></div>
<h2 id="browser_compatibility">Browser compatibility</h2>
<div class="_table"><table>
<thead>
<tr id="bct-browser-type">
<th></th>
<th colspan="6">Desktop</th>
<th colspan="6">Mobile</th>
</tr>
<tr id="bct-browsers">
<th></th>
<th>Chrome</th>
<th>Edge</th>
<th>Firefox</th>
<th>Internet Explorer</th>
<th>Opera</th>
<th>Safari</th>
<th>WebView Android</th>
<th>Chrome Android</th>
<th>Firefox for Android</th>
<th>Opera Android</th>
<th>Safari on IOS</th>
<th>Samsung Internet</th>
</tr>
</thead>
<tbody><tr>
<th><code>samp</code></th>
<td class="bc-supports-yes">1</td>
<td class="bc-supports-yes">12</td>
<td class="bc-supports-yes">1</td>
<td class="bc-supports-yes">Yes</td>
<td class="bc-supports-yes">15</td>
<td class="bc-supports-yes">≤4</td>
<td class="bc-supports-yes">4.4</td>
<td class="bc-supports-yes">18</td>
<td class="bc-supports-yes">4</td>
<td class="bc-supports-yes">14</td>
<td class="bc-supports-yes">≤3.2</td>
<td class="bc-supports-yes">1.0</td>
</tr></tbody>
</table></div>
<h2 id="see_also">See also</h2>
<div class="section-content"><ul> <li>Related elements: <a href="kbd"><code><kbd></code></a>, <a href="code"><code><code></code></a>, <a href="pre"><code><pre></code></a>
</li> <li>The <a href="output"><code><output></code></a> element: a container for script-generated output</li> </ul></div><div class="_attribution">
<p class="_attribution-p">
© 2005–2023 MDN contributors.<br>Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.<br>
<a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/samp" class="_attribution-link">https://developer.mozilla.org/en-US/docs/Web/HTML/Element/samp</a>
</p>
</div>
|