| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/code | [Back] [Original] |
Get to know MDN better
<code> HTML inline code elementThis feature is well established and works across many devices and browser versions. Its been available across browsers since July 2015.
The <code> HTML 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.
<p>
The <code>push()</code> method adds one or more elements to the end of an
array and returns the new length of the array.
</p>
code {
background-color: #eeeeee;
border-radius: 3px;
font-family: "Courier New", monospace;
padding: 0 3px;
}
This element only includes the global attributes.
A paragraph of text that includes <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>
To represent multiple lines of code, wrap the <code> element within a <pre> element. The <code> element by itself only represents a single phrase of code or line of code.
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.
| 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. |
| Implicit ARIA role |
code
|
| Permitted ARIA roles | Any |
| DOM interface |
HTMLElement Up to Gecko 1.9.2 (Firefox 4)
inclusive, Firefox implements the
HTMLSpanElement interface for this element.
|
| Specification |
|---|
| HTML # the-code-element |
This page was last modified on Apr 24, 2026 by MDN contributors.
<a><abbr><acronym><address><area><article><aside><audio><b><base><bdi><bdo><big><blockquote><body><br><button><canvas><caption><center><cite><code><col><colgroup><data><datalist><dd><del><details><dfn><dialog><dir><div><dl><dt><em><embed><fencedframe><fieldset><figcaption><figure><font><footer><form><frame><frameset><geolocation><h1><h6><head><header><hgroup><hr><html><i><iframe><img><input><ins><kbd><label><legend><li><link><main><map><mark><marquee><menu><meta><meter><nav><nobr><noembed><noframes><noscript><object><ol><optgroup><option><output><p><param><picture><plaintext><pre><progress><q><rb><rp><rt><rtc><ruby><s><samp><script><search><section><select><selectedcontent><slot><small><source><span><strike><strong><style><sub><summary><sup><table><tbody><td><template><textarea><tfoot><th><thead><time><title><tr><track><tt><u><ul><var><video><wbr><xmp><input type><input type="button"><input type="checkbox"><input type="color"><input type="date"><input type="datetime-local"><input type="email"><input type="file"><input type="hidden"><input type="image"><input type="month"><input type="number"><input type="password"><input type="radio"><input type="range"><input type="reset"><input type="search"><input type="submit"><input type="tel"><input type="text"><input type="time"><input type="url"><input type="week"><script type>Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |