Skip to content

<code> - The Inline Code Element

Inline HTML 2.0

The inline code element represents a fragment of computer code, such as a variable name, function name, or short code snippet displayed within running text.

Result
<code>code fragment</code>

The <code> element is typically rendered in a monospace font to distinguish it from regular text.

Result
Result
Result
Result
Result
Result
Result

For longer code blocks, combine <code> with <pre>:

Result
<!-- General computer code -->
<p>The <code>Array.map()</code> method creates a new array.</p>

Customize the appearance with CSS:

Result
Result
Result
Result

Screen readers typically don’t announce <code> differently, but the monospace font provides visual distinction for sighted users.

Make sure the purpose of the code is clear:

<p>Use <code>npm install</code>.</p>

Always escape HTML special characters in code examples:

<!-- Correct -->
<code>&lt;div class="container"&gt;</code>
<!-- Wrong (will be interpreted as HTML) -->
<code><div class="container"></code>
<!-- Use <code> for inline code -->
<p>The <code>return</code> statement exits the function.</p>
BrowserVersionNotes
Chrome1+Full support
Firefox1+Full support
Safari1+Full support
Edge12+Full support
IE3+Full support

The <code> element has been supported since the earliest browsers.