<code>
A piece of code inside text; shown in a monospace font.
Syntax
<code>console.log()</code>Examples
A function name and a tag name inside a paragraph:
<p>Call <code>alert()</code> to show a message.</p>
<p>Wrap paragraphs in the <code><p></code> tag.</p>Styling with CSS:
<style>
code { background: #eee; padding: 2px 4px; border-radius: 4px; }
</style>
<p>Use <code>git status</code> to see changes.</p>Notes
Replace < and > inside code with < and >, otherwise the browser treats them as tags. Multi-line code is wrapped in <pre><code>…</code></pre>.
See also
- <pre> — Text that keeps all spaces and line breaks.
- <kbd>, <samp>, <var> — Keyboard input (`<kbd>`), program output (`<samp>`) and a variable in a formula (`<var>`).
In the tutorial
- Text formatting — Inline tags for text — strong and em, mark, del and ins, sub and sup, code, kbd and pre, abbr and q.