Tutorial Article
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 Attributes Attribute Description Global Attributes Yes (e.g., class, id, style) Event Attributes Yes Example Output Browser Output This tag produces visible output.Please use our Tryit Editor […]
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
| Attribute | Description |
|---|---|
| Global Attributes | Yes (e.g., class, id, style) |
| Event Attributes | Yes |
Example
<!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
This tag produces visible output.
Please use our Tryit Editor to view the actual result.
Browser Support
Chrome | Firefox | Edge | Safari | Opera | 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.