<code>: The CODE Element
Last updated: 2026-10-13
<code>The CODE Element
Marks a fragment of computer code, rendered in a monospace font by default.
| Category | Formatting |
|---|---|
| Content Model | Phrasing content |
| Allowed Parents | Any element that accepts phrasing content |
| Content Tag | Yes — requires closing </code> tag |
| Status | Standard |
📝 Syntax
<code>code snippet</code>
▶ Example
Edit the code below and see the live result in the playground:
🌐 Browser Support
| Browser | |||||
|---|---|---|---|---|---|
| <code> | ✓ v1 | ✓ v12 | ✓ v1 | ✓ v1 | ✓ v1 |
| Supported in all major browsers | |||||
Tip: For multi-line code, wrap <code> inside <pre> to preserve line breaks and indentation.
❓ FAQ
QWhat is the difference between code and pre?
A
<code> marks inline code that flows with the text; <pre> preserves line breaks and spaces from the source and suits whole code blocks. They are often combined: <pre><code>…</code></pre> displays multi-line code, with pre handling layout and code handling semantics.QHow do I display angle brackets inside code?
AYou must escape them as HTML entities: write
< for the less-than sign and > for the greater-than sign. To display <div>, the source must contain <div>; otherwise the browser will parse the bracketed content as real tags.QDoes the code tag need a font set?
ABrowsers display
<code> content in a monospace font by default, so usually no manual setting is needed. To unify the style, specify font-family via CSS with a complete monospace fallback stack that works across operating systems.