totn HTML

HTML: <code> tag

This HTML tutorial explains how to use the HTML element called the <code> tag with syntax and examples.

Description

The HTML <code> tag defines a fragment of computer code in the HTML document. Browsers traditionally render the text found within the <code> tag in monospace font. This tag is also commonly referred to as the <code> element.

Syntax

In HTML, the syntax for the <code> tag is:

<body>
<code>Computer code goes here</code>
</body>

Sample Output


Attributes

Only the Global Attributes apply to the <code> tag. There are no attributes that are specific to the <code> tag.

Note

  • The HTML <code> element is found within the <body> tag.
  • The text within the <code> tag is displayed in the browser's default monospace font.

Browser Compatibility

The <code> tag has basic support with the following browsers:

  • Chrome
  • Android
  • Firefox (Gecko)
  • Firefox Mobile (Gecko)
  • Internet Explorer (IE)
  • Edge Mobile
  • Opera
  • Opera Mobile
  • Safari (WebKit)
  • Safari Mobile

Example

We will discuss the <code> tag below, exploring examples of how to use the <code> tag in HTML5, HTML 4.01 Transitional, XHTML 1.0 Transitional, XHTML 1.0 Strict, and XHTML 1.1.