HTML <code> Tag

Definition and Usage

<code> The tag is used to define a computer code snippet, whose content is displayed in the browser's default monospace font.

Tip:This tag is not deprecated. However, richer effects can be achieved by using CSS (see the example below).

See also:

Tag Description
<samp> Define sample output of a computer program.
<kbd> Define keyboard input.
<var> Define variables.
<pre> Define preformatted text.

See also:

HTML Tutorial:HTML Text Formatting

HTML DOM Reference Manual:Code Object

Instance

Example 1

Define some text as computer code in the document:

<p>HTML <code>button</code> tag defines a clickable button.</p>
<p>CSS <code>background-color</code> property defines the background color of the element.</p>

Try It Yourself

Example 2

Use CSS to set the style of the <code> element:

<html>
<head>
<style>
code {
  font-family: Consolas,"courier new";
  color: crimson;
  background-color: #f1f1f1;
  padding: 2px;
  font-size: 105%;
}
</style>
</head>
<body>
<p>HTML <code>button</code> tag defines a clickable button.</p>
<p>CSS <code>background-color</code> property defines the background color of the element.</p>
</body>
</html>

Try It Yourself

Global Attributes

<code> The tag also supports Global Attributes in HTML.

event attributes

<code> The tag also supports Event Attributes in HTML.

Default CSS Settings

Most browsers will display the following default values <code> Element:

code {
  font-family: monospace;
}

Try It Yourself

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support