The HTML <code>
element displays its contents styled in a fashion intended to indicate that the text is a short fragment of computer code. By default, the content text is displayed using the user agent'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>The function <code>selectAll()</code> highlights all the text in the input field so the user can, for example, copy or delete the text.</p>
The output generated by this HTML looks like this:
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
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Feature | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | 1 | Yes | 1 | Yes | Yes | Yes |
Feature | Android webview | Chrome for Android | Edge mobile | Firefox for Android | IE mobile | Opera Android | iOS Safari |
---|---|---|---|---|---|---|---|
Basic support | Yes | Yes | Yes | 4 | Yes | Yes | Yes |
See also
Document Tags and Contributors
Tags:
Contributors to this page:
Sheppy,
teoli,
Sebastianz,
CarloMartini,
sideshowbarker,
rudijuri,
erikadoyle,
MadeByMike,
Volker-E,
Jeremie,
kscarfone,
justleroy,
tregagnon,
medicdude,
ethertank,
lmorchard,
grendel,
cers,
McGurk,
hobophobe,
xaky,
jswisher,
Ptak82,
Qk9Ka7,
Jscher2000,
PablO,
alecananian
Last updated by:
Sheppy,