HTML Tags

HTML <code> Tag

The <code> tag is used to display a fragment of computer code in a monospace (fixed-width) font.
It is typically used for inline code, not for large code blocks.

Syntax

html

<code>your code here</code>

Attributes

AttributeDescription
Global AttributesYes (e.g., class, id, style)
Event AttributesYes

Example

html

<!DOCTYPE html>
<html>
<head>
  <title>HTML Code Tag Example</title>
</head>
<body>

  <h2>Using the <code> Tag</h2>

  <p>To display a message in JavaScript, use: 
    <code>alert("Hello World!");</code>
  </p>

</body>
</html>

Output

Browser Output

html

This tag produces visible output.
Please use our Tryit Editor to view the actual result.

Browser Support

Chrome
Edge
Firefox
Safari
Opera
IE9+
YesYesYesYesYesYes

The <code> tag displays text in a monospace font. It does not apply syntax highlighting by itself. Often combined with <pre> for multi-line code blocks.

Notes

Conclusion

The <code> tag is essential for displaying small pieces of code or commands in a readable monospace format. It improves clarity and is widely supported across all browsers.