Français

<code>

Display source code in text

  • HTML
  • accessibility
  • semantics

<code> — Source code

The <code> element represents a fragment of computer code: a function name, variable, command, or program excerpt. For multi-line code blocks, combine <pre><code>.

When to use it

You want to insert a function name, a terminal command, or a language keyword in the middle of a sentence. For a full code block, nest <code> inside <pre>.

What you gain

Accessibility: NVDA, JAWS, VoiceOver, and TalkBack do not change voice for <code> by default. The value is structural: the monospace rendering helps visually, and the markup lets extraction tools distinguish code from regular text.

Code example

<p>Use the <code>Array.prototype.map()</code> method to transform each element.</p>
 
<pre><code>function greet(name) {
  return `Hello, ${name}!`;
}</code></pre>

Further reading