<code>
Published Jun 10, 2021Updated Jul 1, 2022
Contribute to Docs
The <code>
element represents source code contained in the text.
Syntax
<code><!-- Code snippet lives here --></code>
<code>
is a tag that wraps around a block of text. By default it appears inline with the surrounding text, and can be used with a <pre>
tag to create formatted code blocks across multiple lines.
Example
Suppose the document contains a description of what a JavaScript function aims to accomplish, as well as the code for that function:
<html><head> </head><body><!-- Here <code> is being used inline, and the text add() will be shown in a monospace font --><p>The function <code>add()</code> is defined below. It will take two inputs,and return the sum of them as an output.</p><!-- Here <code> is being used with a <pre> tag to allow the formatted code to span multiple lines --><pre><code>function add(x, y) {return x + y;}</code></pre></body></html>
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.