samp element
If you don't know what an element is or how you must use it, I recommend you read the "HTML tags and attributes" tutorial that you can find in the HTML tutorials section.
Table of contents
Description
The samp
element represents a sample or output from a program or script. This element is usually placed inside pre
to take advantage of its characteristics: spaces and line breaks in the code are respected and rendered in the document.
Examples
In this example, the author talks about his experience with a program. The message returned by the computer is wrapped inside the samp
element.
<p>When I entered the command, the computer answered <samp>Error: command not found</samp>. I'm at a loss here...</p>
When I entered the command, the computer answered Error: command not found. I'm at a loss here...
In the second example, the samp
element is used together with pre
, to take advantage of its characteristics: spaces and line breaks in the code are respected and rendered in the document. This way, the text of the output can be pasted exactly as it was retrieved from the program. Additionally, the fixed-width characters of pre
help in maintaining the tabulation of data.
<p>The results I got are shown below:</p>
<pre><samp>
Filesystem Size Used Avail Use% Mounted on
none 4,0K 0 4,0K 0% /sys/fs/cgroup
udev 990M 4,0K 990M 1% /dev
tmpfs 201M 1,2M 199M 1% /run
none 5,0M 0 5,0M 0% /run/lock
none 1001M 80K 1001M 1% /run/shm
none 100M 24K 100M 1% /run/user</samp></pre>
The results I got are shown below:
Filesystem Size Used Avail Use% Mounted on none 4,0K 0 4,0K 0% /sys/fs/cgroup udev 990M 4,0K 990M 1% /dev tmpfs 201M 1,2M 199M 1% /run none 5,0M 0 5,0M 0% /run/lock none 1001M 80K 1001M 1% /run/shm none 100M 24K 100M 1% /run/user
In the third example, the samp
element is being used inside kbd
, to mark up the menus in a computer program the user should access.
<p>To create a new document go to <kbd><samp>File</samp> → <samp>New</samp></kbd>.</p>
To create a new document go to File → New.
Now, an example with the samp
element containing a piece of text previously input by the user. The latter is represented by the kbd
element.
<pre><samp>Enter your search query: <kbd>balance.txt</kbd>
Searching...
No files where found that match your search query</samp></pre>
Enter your search query: balance.txt Searching... No files where found that match your search query
Attributes
Global attributes
For information about global attributes refer to this list of global attributes in HTML5.
Events
Global events
For information about global events refer to this list of global events in HTML5.