HTML <code> tag

The <code> tag is used to define enclosed text as a computer code. The texts within the <code> element is monospace font-family.

Type: Inline Element

Example of <code> tag

<code> x + y = 10 </code>

Supported Browsers

Tag Chrome Internet Explorer Firefox Safari Opera Mini
<code> Yes Yes Yes Yes Yes

Full code example

<!DOCTYPE html>
<html>
<head>
</head>
<body>
<code>
  x = 10,
  y = 20,
  x + y = 30.
</code>
</body>
</html>
Run The code »

Output on the browser

x = 10, y = 20, x + y = 30.

By default, <code> tag do not preserve any line space or line break. Enclose them within the <pre> element to preserve it.

<pre>
  <code>
     -------
  </code>
</pre>

More reference

<code> tag is a phrase tag. An HTML phrase tag is an inline tag that defines important meaning to the text rather than just changing appearance.

Default CSS properties of <code> tag

code
{
  font-family: monospace;
  font-size: 1em;
  font-style: normal;
  background-color: transparent;
  padding: 0;
  border-radius: 0;
}
    

Some related HTML phrase tags

Tag Note
<em> It defines emphasized texts.
<kbd> It defines user input, such as keyboard input or, sometimes voice commands.
<samp> It defines an output from the system.
<strong> It defines strong texts.
<var> It defines a variable.