<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.

CategoryFormatting
Content ModelPhrasing content
Allowed ParentsAny element that accepts phrasing content
Content TagYes — requires closing </code> tag
StatusStandard

📝 Syntax

<code>code snippet</code>

▶ Example

Edit the code below and see the live result in the playground:

🌐 Browser Support

Browser ChromeChrome EdgeEdge FirefoxFirefox SafariSafari OperaOpera
<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 &lt; for the less-than sign and &gt; for the greater-than sign. To display <div>, the source must contain &lt;div&gt;; 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.

📚 Related Tutorials

Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏