<samp>

The program is running — what will it respond? An element for displaying the program's output to the user.

Time to read: less than 5 min

Briefly

The <samp> tag is used to format the output of data that is shown to the user as a result of program execution. The content of this element is interpreted by devices as plain text.

Example

        
          
          <p>  After all active sessions are completed, a message will appear on the screen:  <samp>The computer can now be turned off.</samp></p>
          <p>
  After all active sessions are completed, a message will appear on the screen:
  <samp>The computer can now be turned off.</samp>
</p>

        
        
          
        
      
Open demo in the new window

How to Write

Inside the <samp> tag, information that the user can obtain during interaction with the program is placed:

  • output of information about the progress of the program;
  • errors, warnings, and hints from developer tools or the operating system;
  • prompts for data entry.

In browsers, the text inside <samp> is displayed in a monospace font by default.

If you need to show the user the result of the program's work in real-time, it's better to use the tag <output>, for example:

  • information that the user enters or modifies in a form;
  • output of calculations based on data provided by the user (calculator, horoscope, etc.).

Attributes

All global attributes apply to the <samp> tag.

Combination with <var>, <kbd> and <code>

When formatting data output, <samp> is often combined with the tags <var>, <kbd> and <code>:

        
          
          <div>  <p>    During the execution of the program, you will be prompted to specify the distance:  </p>  <p>    <samp>      Enter a value for the variable <var>Distance</var>:    </samp>  </p></div><div>  <p>    The following command will output the result of adding    two numbers to the browser console:  </p>  <pre>  <code>console.log(2.3 + 2.4)</code>  <samp>4.699999999999999</samp></pre></div><div>  <p>    An incorrectly entered command will not be executed and an error will be displayed in the console:  </p>  <samp>    <span class="console-name">user@machine:~$</span> <kbd>ckear</kbd>    <br>    ckear: The term 'ckear' is not recognized as the name of a cmdlet, function,    script file, or executable program.    <br>    <span class="console-name">user@machine:~$</span>    <span class="console-cursor">_</span>  </samp></div>
          <div>
  <p>
    During the execution of the program, you will be prompted to specify the distance:
  </p>
  <p>
    <samp>
      Enter a value for the variable <var>Distance</var>:
    </samp>
  </p>
</div>

<div>
  <p>
    The following command will output the result of adding
    two numbers to the browser console:
  </p>
  <pre>
  <code>console.log(2.3 + 2.4)</code>
  <samp>4.699999999999999</samp></pre>
</div>

<div>
  <p>
    An incorrectly entered command will not be executed and an error will be displayed in the console:
  </p>
  <samp>
    <span class="console-name">user@machine:~$</span> <kbd>ckear</kbd>
    <br>
    ckear: The term 'ckear' is not recognized as the name of a cmdlet, function,
    script file, or executable program.
    <br>
    <span class="console-name">user@machine:~$</span>
    <span class="console-cursor">_</span>
  </samp>
</div>

        
        
          
        
      
Open demo in the new window