Path: blob/main/files/en-us/web/html/element/code/index.md
6520 views
------{{HTMLSidebar}}
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 {{Glossary("user agent", "user agent's")}} default monospace font.
{{EmbedInteractiveExample("pages/tabbed/code.html", "tabbed-shorter")}}
Attributes
This element only includes the global attributes.
Example
A paragraph of text that includes <code>:
The output generated by this HTML looks like this:
{{EmbedLiveSample("Example", 640, 70)}}
Notes
To represent multiple lines of code, wrap the <code> element within a {{HTMLElement("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.
Technical summary
| Content categories | Flow content, phrasing content, palpable content. |
|---|---|
| Permitted content | Phrasing content. |
| Tag omission | {{no_tag_omission}} |
| Permitted parents | Any element that accepts phrasing content. |
| Implicit ARIA role | No corresponding role |
| Permitted ARIA roles | Any |
| DOM interface | {{domxref("HTMLElement")}} Up to Gecko 1.9.2 (Firefox 4) inclusive, Firefox implements the {{domxref("HTMLSpanElement")}} interface for this element. |
Specifications
{{Specifications}}
Browser compatibility
{{Compat}}
See also
{{HTMLElement("samp")}}
{{HTMLElement("kbd")}}
{{HTMLElement("var")}}
{{HTMLElement("pre")}}