summaryrefslogtreecommitdiff
path: root/devdocs/html/element%2Fsamp.html
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
committerCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
commit754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch)
treef1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/html/element%2Fsamp.html
new repository
Diffstat (limited to 'devdocs/html/element%2Fsamp.html')
-rw-r--r--devdocs/html/element%2Fsamp.html119
1 files changed, 119 insertions, 0 deletions
diff --git a/devdocs/html/element%2Fsamp.html b/devdocs/html/element%2Fsamp.html
new file mode 100644
index 00000000..c63e916b
--- /dev/null
+++ b/devdocs/html/element%2Fsamp.html
@@ -0,0 +1,119 @@
+<header><h1>&lt;samp&gt;: The Sample Output element</h1></header><div class="section-content"><p>The <code>&lt;samp&gt;</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>&lt;samp&gt;</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>&lt;output&gt;</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">&lt;</span>p</span><span class="token punctuation">&gt;</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">&lt;</span>samp</span><span class="token punctuation">&gt;</span></span>Scan complete. Found <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>em</span><span class="token punctuation">&gt;</span></span>N<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>em</span><span class="token punctuation">&gt;</span></span> results.<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>samp</span><span class="token punctuation">&gt;</span></span> You can then proceed to
+ the next step.
+<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</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>&lt;kbd&gt;</code></a> element within a <code>&lt;samp&gt;</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">&lt;</span>pre</span><span class="token punctuation">&gt;</span></span>
+<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>samp</span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</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">&gt;</span></span>mike@interwebz:~$<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>kbd</span><span class="token punctuation">&gt;</span></span>md5 -s "Hello world"<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>kbd</span><span class="token punctuation">&gt;</span></span>
+MD5 ("Hello world") = 3e25960a79dbc69b674cd4ec67a72c62
+
+<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</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">&gt;</span></span>mike@interwebz:~$<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</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">&gt;</span></span>█<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>samp</span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>pre</span><span class="token punctuation">&gt;</span></span>
+</pre>
+</div> <p>Note the use of <a href="span"><code>&lt;span&gt;</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>&lt;kbd&gt;</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 &gt; 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>&lt;kbd&gt;</code></a>, <a href="code"><code>&lt;code&gt;</code></a>, <a href="pre"><code>&lt;pre&gt;</code></a>
+</li> <li>The <a href="output"><code>&lt;output&gt;</code></a> element: a container for script-generated output</li> </ul></div><div class="_attribution">
+ <p class="_attribution-p">
+ &copy; 2005&ndash;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>