Published Jun 10, 2021Updated Jul 1, 2022
Contribute to Docs

The <code> element represents source code contained in the text.


<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.


Suppose the document contains a description of what a JavaScript function aims to accomplish, as well as the code for that function:

<head> </head>
<!-- Here <code> is being used inline, and the text add() will be shown in a monospace font -->
The function <code>add()</code> is defined below. It will take two inputs,
and return the sum of them as an output.
<!-- Here <code> is being used with a <pre> tag to allow the formatted code to span multiple lines -->
<code>function add(x, y) {
return x + y;

All contributors

Looking to contribute?

Learn HTML on Codecademy