HTML <code> Tag

The <code> tag is a phrase tag and is used to put text which represents computer code. It is useful to display functions, programming codes or variables.

It is shown in the browser's default monospace font as default.

Recommendation: The <code> tag is not deprecated yet, but it is possible to achieve richer effects with CSS @font-face property.

Syntax

The <code> tag comes in pairs. The content must be written between opening (<code>) and closing (</code>) tags.

Example

<!DOCTYPE html>
<html>
   <body>
      <p>Normal text. </p>
      <code>This part is code.</code>
      <p>And this is another normal text.</p>
   </body>
</html>

Result

See the list of all phrase tags below:

Tag Descriptions
<em> Renders as emphasized text.
<strong> Defines an important text.
<dfn> Defines the definition term.
<code> Defines a computer code piece.
<samp> Defines a sample output from a programming code.
<kbd> Defines the keyboard input.
<var> Defines a variable.

The <code> tag also supports the Global Attributes.