Widely availableSupported across all major browsers. Safe to use in production.

Overview

The <code> element displays its contents as a fragment of computer code.

Browser support

Feature Desktop Mobile
Chrome
Edge
Firefox
Safari
Chrome Android
Safari iOS
1
12
1
≤4
18
≤3.2
1+Supported (version) Not supported Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)

Syntax

HTML
<p><code>console.log()</code> You can generate debug output.</p>
<pre><code>function greet(name) {
  return `Hello, ${name}!`;
}</code></pre>

Live demo

inlineco-d

Code element in textmiddle to co-d fill.functionname or variablename. Display to.

PreviewFullscreen

co-dblock

Pre and code combinationmultiple row. co-d display.

PreviewFullscreen

command line display

ta-minalcommand co-delement in displaypattern.

PreviewFullscreen

Use cases

  • Using <code>

    The <code> element displays its contents as a fragment of computer code.

Cautions

  • May not be supported in older browsers.

Accessibility

  • Verify how this element is announced by screen readers.

Powered by web-features