The HTML <code> element represents a fragment of computer code. By default, it is displayed in the browser's default monospace font.

Content categories Flow content, phrasing content, palpable content.
Permitted content Phrasing content.
Tag omission None, both the starting and ending tag are mandatory.
Permitted parents Any element that accepts phrasing content.
Permitted ARIA roles Any
DOM interface HTMLElement Up to Gecko 1.9.2 (Firefox 4) inclusive, Firefox implements the HTMLSpanElement interface for this element.

Attributes

This element only includes the global attributes.

Example

Regular text, followed by code.

<p>This is how we declare a Javascript variable:<br/>
<code>var i = 0;</code>
</p>

Result

This is how we declare a Javascript variable:
var i = 0;

Note

A CSS rule can be defined for the code selector to override the browser's default font face. Preferences set by the user might take precedence over the specified CSS.

Specifications

Specification Status Comment
HTML Living Standard
The definition of '<code>' in that specification.
Living Standard  
HTML5
The definition of '<code>' in that specification.
Recommendation  
HTML 4.01 Specification
The definition of '<code>' in that specification.
Recommendation  

Browser compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support1 Yes1 Yes Yes Yes
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidIE mobileOpera AndroidiOS Safari
Basic support Yes Yes Yes4 Yes Yes Yes

See also