HTML <code> Tag
Description
The <code> element in HTML is used to represent a fragment of computer code. It is intended for displaying programming or markup code inline within a paragraph or other textual content. Unlike other textual elements, <code> emphasizes that the content is to be interpreted as literal code rather than normal prose.
Visually, browsers typically render <code> text in a monospace (fixed-width) font to distinguish it from surrounding content, which helps improve readability for developers and users referencing code snippets. It is important to note that <code> does not automatically format the text as a block or preserve whitespace; it is primarily an inline element. For multi-line code blocks, <pre> is often used in combination with <code> to preserve indentation and line breaks.
The <code> tag is semantically meaningful and aids accessibility. Screen readers and other assistive technologies may announce it as code, helping users understand the context of the content. It is commonly used in documentation, tutorials, technical articles, and anywhere specific code needs to be highlighted within descriptive text.
Example usage (inline):
<p>To display text in bold, use the <code>strong</code> tag.</p>
Example usage (with <pre> for blocks):
<pre><code>
function greet(name) {
console.log("Hello, " + name + "!");
}
</code></pre>
Properties
- Permitted Parents
- Any element that accepts phrasing content
- Content
- Inline and text
- Start/End Tags
- Start tag: required, End tag: required
Example
Attributes
None
Global Attributes
The <code> tag also supports the Global Attributes in HTML5
Event Attributes
The <code> tag also supports the Event Attributes in HTML5
Browser Support
The following information will show you the current browser support for the HTML <code> tag. Hover over a browser icon to see the version that first introduced support for this HTML tag.
This tag is supported by all modern browsers.
Desktop
Tablets & Mobile
Last updated by CSSPortal on: 26th December 2025
