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

<code>your code here</code>

Attributes

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

Example

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

  <h2>Using the &lt;code&gt; Tag</h2>

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

</body>
</html>

Output

Browser Output

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

Browser Support

Chrome
Chrome
Firefox
Firefox
Edge
Edge
Safari
Safari
Opera
Opera
IE
IE9+
✅Yes✅Yes✅Yes✅Yes✅Yes✅Yes

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

  • For multi-line code, wrap <code> inside a <pre> tag.
  • For semantic clarity, use <kbd>, <samp>, or <var> when appropriate.

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.

Sign In Form

User your email and password to singn in

Don’t have an account, signup here : 

HTML5 & CSS3

Tools and Tutorials

Want a Website

Want a website for your business ?

Please fill out the details below, so we can reach out to you.

Registration Form

Signup to track your record and much more.

We have sent you an email with a registration link. Please click the link to verify your email address, or enter the 6-digit OTP provided in the email.

Didn't receive the OTP. Regenerate OTP Resend