Description

The <code> tag represents a fragment of computer code — for example, a snippet of HTML or CSS, or some other programming language code.

The following table summarizes the usages context and the version history of this tag.

Placement:Inline
Content:Inline and text
Start/ End Tag:Start tag: required, End tag: required
Version:HTML 2, 3.2, 4, 4.01, 5

Note: By default, most of the browsers displays the content of <code> element in a monospace (fixed-width) font, such as "Courier", but this style can be overridden using the CSS font-family property.

Syntax

The basic syntax of the <code> tag is given with:

HTML/XHTML: <code> ... </code>

The example below shows the <code> tag in action.

<p>Regular text. <code>computer code</code> Regular text.</p>

Tip: Since spacing is important when presenting the computer codes, the <pre> element is most frequently used as a container for <code> elements because it preserves whitespace and line breaks.

Tag-Specific Attributes

The <code> tag doesn't have any specific attribute.

Global Attributes

Like all other HTML tags, the <code> tag supports the glocodeal Attributes in HTML5.

Event Attributes

The <code> tag also supports the event Attributes in HTML5.

Browser Compatibility

Element
<code>YesYesYesYesYes