Description

The HTML element <samp> is used to define a sample code, which typically represents a sample code from computer programs, scripts, etc.,

By default, the browsers display its content in a monospaced font, like Courier New.

However, CSS can be used to override its default styles.

The below table summarizes its usage.

Usage Details
Placement It is displayed as an Inline element.
Contents It can contain Inline elements and text.
Tags Both the opening and closing tags are required.
Versions HTML 2, 3.2, 4, 4.01, 5

Syntax

Here is the basic syntax of the <samp> element.

<samp>...</samp>

Examples

Run this on IDE

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Example - HTML Element samp</title>
</head>
<body>
    <h1>Sample computer output</h1>
    <p>Message from my computer:</p>
    <p><samp>HTTP 404 - File not found.<br>Press F1 to continue</samp></p>
</body>
</html>

Attributes

The following table shows the list of supported and unsupported attributes for the <samp> element.

Attribute Type Details
Element-Specific Attributes The tag <samp> doesn't have any element-specific attributes.
Global Attributes Like all other HTML tags, the tag <samp> supports the HTML Global Attributes.
Event Attributes The tag <samp> also supports the HTML Event Attributes.

Browser Compatibility

The tag <samp> is supported in all modern browsers.

  • Google Chrome 1+
  • Internet Explorer or Edge 2+
  • Firefox 1+
  • Apple Safari 1+
  • Opera 4+

Related Links